mirror of
https://github.com/max-sixty/worktrunk.git
synced 2026-09-14 20:00:38 +08:00
4bacab23af
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>
27 lines
807 B
Rust
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());
|
|
}
|