Skip to content

Commit db0c401

Browse files
committed
chore: add more test cases to pin behaviour around string and path handling.
This is important to know how to consistently handle empty strings - should they not be present? Or should they be flagged as error? The answer here is that the caller has to deal with it, as we report these values if they are present which only requires an equals sign.
1 parent 1f2ffb6 commit db0c401

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

gix-config/tests/file/access/read_only.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ fn get_value_for_all_provided_values() -> crate::Result {
2626
other-quoted = "hello world"
2727
location = ~/tmp
2828
location-quoted = "~/quoted"
29+
empty-implicit
30+
empty-equals =
31+
empty-explicit = ""
2932
"#;
3033
for lossy in [false, true] {
3134
let config = File::from_bytes_no_includes(
@@ -54,6 +57,34 @@ fn get_value_for_all_provided_values() -> crate::Result {
5457
None,
5558
"unset values are not present"
5659
);
60+
assert_eq!(
61+
config.string("core", None, "empty-implicit"),
62+
None,
63+
"mere presence is at most a boolean"
64+
);
65+
assert_eq!(
66+
config.path("core", None, "empty-implicit"),
67+
None,
68+
"mere presence is at most a boolean"
69+
);
70+
assert_eq!(
71+
config.string("core", None, "empty-equals"),
72+
Some(cow_str("")),
73+
"mere presence with equal sign is always the empty implicit string"
74+
);
75+
assert!(
76+
config.path("core", None, "empty-equals").is_some(),
77+
"this is an empty path…"
78+
);
79+
assert_eq!(
80+
config.string("core", None, "empty-explicit"),
81+
Some(cow_str("")),
82+
"and so is an explicit empty string"
83+
);
84+
assert!(
85+
config.path("core", None, "empty-explicit").is_some(),
86+
"and so is an explicit empty path"
87+
);
5788
assert_eq!(
5889
config.strings("core", None, "bool-implicit").expect("present"),
5990
&[cow_str("")],

0 commit comments

Comments
 (0)