Fixes the config format to require values to be strings, so to avoid problems with toml Value not being able to accommodate certain types, but then adds parsing according to the declared type to ensure the values are valid before being formatted into constants.
.tangled/workflows/test.yml
.tangled/workflows/test.yml
This file has not been changed.
+14
-1
sachy-config/src/lib.rs
+14
-1
sachy-config/src/lib.rs
···
91
"i128" => validate_kind_to_string::<i128>(name, kind, value)?,
92
"f32" => validate_kind_to_string::<f32>(name, kind, value)?,
93
"f64" => validate_kind_to_string::<f64>(name, kind, value)?,
94
-
"&str" => bail!("{} is a string, use [statics] for these", kind),
95
_ => bail!("Unsupported type: {}", kind),
96
};
97
···
155
assert!(error_chain.next().is_none());
156
157
Ok(())
158
}
159
160
#[test]
···
91
"i128" => validate_kind_to_string::<i128>(name, kind, value)?,
92
"f32" => validate_kind_to_string::<f32>(name, kind, value)?,
93
"f64" => validate_kind_to_string::<f64>(name, kind, value)?,
94
+
"&str" => bail!("{} is a {}, use [statics] for these", name, kind),
95
_ => bail!("Unsupported type: {}", kind),
96
};
97
···
155
assert!(error_chain.next().is_none());
156
157
Ok(())
158
+
}
159
+
160
+
#[test]
161
+
fn it_disallows_string_constants() {
162
+
let input = r#"[constants]
163
+
FIRST = { type = "&str", value = "42" }
164
+
"#;
165
+
166
+
let expected = "FIRST is a &str, use [statics] for these";
167
+
168
+
let output = parse_config(input).expect_err("Output somehow successfully parsed");
169
+
170
+
assert_eq!(output.to_string(), expected);
171
}
172
173
#[test]
History
2 rounds
0 comments
1 commit
expand
collapse
feat: Config format tweak with stronger type validation
Fixes the config format to require values to be strings, so to avoid problems with toml Value not being able to accommodate
certain types, but then adds parsing according to the declared type to ensure the values are valid before being
formatted into constants.
2/2 success
expand
collapse
expand 0 comments
pull request successfully merged
1 commit
expand
collapse
feat: Config format tweak with stronger type validation
Fixes the config format to require values to be strings, so to avoid problems with toml Value not being able to accommodate
certain types, but then adds parsing according to the declared type to ensure the values are valid before being
formatted into constants.