2017-01-29 18:53:20 -06:00
|
|
|
extern crate toml;
|
|
|
|
|
2019-07-28 11:56:22 -05:00
|
|
|
macro_rules! bad {
|
|
|
|
($toml:expr, $msg:expr) => {
|
|
|
|
match $toml.parse::<toml::Value>() {
|
|
|
|
Ok(s) => panic!("parsed to: {:#?}", s),
|
|
|
|
Err(e) => assert_eq!(e.to_string(), $msg),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-29 18:53:20 -06:00
|
|
|
#[test]
|
|
|
|
fn bad() {
|
2019-07-28 12:40:49 -05:00
|
|
|
bad!("a = 01", "invalid number at line 1 column 6");
|
|
|
|
bad!("a = 1__1", "invalid number at line 1 column 5");
|
|
|
|
bad!("a = 1_", "invalid number at line 1 column 5");
|
|
|
|
bad!("''", "empty table key found at line 1 column 1");
|
|
|
|
bad!("a = 9e99999", "invalid number at line 1 column 5");
|
2018-07-10 20:00:12 -05:00
|
|
|
|
2019-07-28 11:56:22 -05:00
|
|
|
bad!(
|
|
|
|
"a = \"\u{7f}\"",
|
2019-07-28 12:40:49 -05:00
|
|
|
"invalid character in string: `\\u{7f}` at line 1 column 6"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
bad!(
|
|
|
|
"a = '\u{7f}'",
|
2019-07-28 12:40:49 -05:00
|
|
|
"invalid character in string: `\\u{7f}` at line 1 column 6"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
2018-07-10 20:00:12 -05:00
|
|
|
|
2019-07-28 12:40:49 -05:00
|
|
|
bad!("a = -0x1", "invalid number at line 1 column 5");
|
2019-07-30 12:20:18 -05:00
|
|
|
bad!(
|
|
|
|
"a = 0x-1",
|
|
|
|
"failed to parse datetime for key `a` at line 1 column 5"
|
|
|
|
);
|
2018-07-11 01:29:47 -05:00
|
|
|
|
|
|
|
// Dotted keys.
|
2019-07-28 11:56:22 -05:00
|
|
|
bad!(
|
|
|
|
"a.b.c = 1
|
2018-07-11 01:29:47 -05:00
|
|
|
a.b = 2
|
2019-07-28 11:56:22 -05:00
|
|
|
",
|
2019-07-30 12:20:18 -05:00
|
|
|
"duplicate key: `b` for key `a` at line 1 column 9"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
bad!(
|
|
|
|
"a = 1
|
|
|
|
a.b = 2",
|
2019-07-28 12:40:49 -05:00
|
|
|
"dotted key attempted to extend non-table type at line 1 column 5"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
bad!(
|
|
|
|
"a = {k1 = 1, k1.name = \"joe\"}",
|
2019-07-28 12:40:49 -05:00
|
|
|
"dotted key attempted to extend non-table type at line 1 column 11"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
2017-01-29 18:53:20 -06:00
|
|
|
}
|