toml-rs/test-suite/tests/invalid-misc.rs

52 lines
1.3 KiB
Rust
Raw Normal View History

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),
}
};
}
#[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");
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
);
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
);
}