Files
max-sixty__worktrunk/tests/integration_tests/select_config.rs
Maximilian Roos 4bacab23af refactor(config): flatten section fields from Option<T> to T (#2104)
Each per-section config field on `UserConfig` and `UserProjectOverrides`
(`ListConfig`, `CommitConfig`, `MergeConfig`, `SwitchConfig`,
`StepConfig`, `aliases`) was wrapped in `Option<>` despite each section
type having all-`Option<T>` fields internally — making
`Some(MergeConfig::default())` semantically equivalent to `None`.
`ResolvedConfig::for_project` was already calling `.unwrap_or_default()`
on every accessor result.

Replace `Option<Type>` with `Type` using `#[serde(default,
skip_serializing_if = "is_default")]` (sections) or `BTreeMap::is_empty`
(aliases), where `is_default` compares against `T::default()`. This
removes redundant Option indirection across the accessor, persistence,
mutation, and resolved config layers. Net -53 lines.

Continues the config cleanup from #2093.

> _This was written by Claude Code on behalf of @max-sixty_

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-11 17:48:31 -07:00

27 lines
807 B
Rust

use worktrunk::config::UserConfig;
use worktrunk::config::migrate_content;
#[test]
fn test_select_pager_config_migrated_to_switch_picker() {
// [select] is migrated to [switch.picker] at the TOML level before parsing
let content = r#"
[select]
pager = "test-pager --custom-flag"
"#;
let migrated = migrate_content(content);
let config: UserConfig = toml::from_str(&migrated).unwrap();
let picker = config.switch_picker(None);
assert_eq!(picker.pager.as_deref(), Some("test-pager --custom-flag"));
}
#[test]
fn test_select_config_optional() {
// Config without [select] section is still valid
let content = r#"
[list]
full = true
"#;
let config: UserConfig = toml::from_str(content).unwrap();
assert_eq!(config.switch, worktrunk::config::SwitchConfig::default());
}