2015-01-15 14:44:05 -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),
|
|
|
|
}
|
|
|
|
};
|
2014-06-20 19:01:38 -05:00
|
|
|
}
|
|
|
|
|
2019-07-28 11:56:22 -05:00
|
|
|
macro_rules! test( ($name:ident, $s:expr, $msg:expr) => (
|
2014-06-20 19:01:38 -05:00
|
|
|
#[test]
|
2019-07-28 11:56:22 -05:00
|
|
|
fn $name() { bad!($s, $msg); }
|
2014-12-18 15:48:34 -06:00
|
|
|
) );
|
2014-06-20 19:01:38 -05:00
|
|
|
|
2019-05-08 19:45:39 -05:00
|
|
|
test!(
|
|
|
|
datetime_malformed_no_leads,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/datetime-malformed-no-leads.toml"),
|
2019-07-30 12:20:18 -05:00
|
|
|
"failed to parse datetime for key `no-leads` at line 1 column 12"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
datetime_malformed_no_secs,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/datetime-malformed-no-secs.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a colon, found a newline at line 1 column 28"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
datetime_malformed_no_t,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/datetime-malformed-no-t.toml"),
|
2019-07-30 12:20:18 -05:00
|
|
|
"failed to parse datetime for key `no-t` at line 1 column 8"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
datetime_malformed_with_milli,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/datetime-malformed-with-milli.toml"),
|
2019-07-30 12:20:18 -05:00
|
|
|
"failed to parse datetime for key `with-milli` at line 1 column 14"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
duplicate_key_table,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/duplicate-key-table.toml"),
|
2019-07-30 12:20:18 -05:00
|
|
|
"duplicate key: `type` for key `fruit` at line 4 column 1"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
duplicate_keys,
|
|
|
|
include_str!("invalid/duplicate-keys.toml"),
|
2019-07-30 12:20:18 -05:00
|
|
|
"duplicate key: `dupe` at line 1 column 1"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
duplicate_table,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/duplicate-table.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"redefinition of table `dependencies` for key `dependencies` at line 7 column 1"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
duplicate_tables,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/duplicate-tables.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"redefinition of table `a` for key `a` at line 2 column 1"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
empty_implicit_table,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/empty-implicit-table.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a table key, found a period at line 1 column 10"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
empty_table,
|
|
|
|
include_str!("invalid/empty-table.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a table key, found a right bracket at line 1 column 2"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
float_no_leading_zero,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/float-no-leading-zero.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a value, found a period at line 1 column 10"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
float_no_suffix,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/float-no-suffix.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"invalid number at line 1 column 5"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
float_no_trailing_digits,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/float-no-trailing-digits.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"invalid number at line 1 column 12"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
key_after_array,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/key-after-array.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected newline, found an identifier at line 1 column 14"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
key_after_table,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/key-after-table.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected newline, found an identifier at line 1 column 11"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
key_empty,
|
|
|
|
include_str!("invalid/key-empty.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a table key, found an equals at line 1 column 2"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
key_hash,
|
|
|
|
include_str!("invalid/key-hash.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected an equals, found a comment at line 1 column 2"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
key_newline,
|
|
|
|
include_str!("invalid/key-newline.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected an equals, found a newline at line 1 column 2"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
key_open_bracket,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/key-open-bracket.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a right bracket, found an equals at line 1 column 6"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
key_single_open_bracket,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/key-single-open-bracket.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a table key, found eof at line 1 column 2"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
key_space,
|
|
|
|
include_str!("invalid/key-space.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected an equals, found an identifier at line 1 column 3"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
key_start_bracket,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/key-start-bracket.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a right bracket, found an equals at line 2 column 6"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
key_two_equals,
|
|
|
|
include_str!("invalid/key-two-equals.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a value, found an equals at line 1 column 6"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
string_bad_byte_escape,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/string-bad-byte-escape.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"invalid escape character in string: `x` at line 1 column 13"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
string_bad_escape,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/string-bad-escape.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"invalid escape character in string: `a` at line 1 column 42"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
string_bad_line_ending_escape,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/string-bad-line-ending-escape.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"invalid escape character in string: ` ` at line 2 column 79"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
string_byte_escapes,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/string-byte-escapes.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"invalid escape character in string: `x` at line 1 column 12"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
string_no_close,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/string-no-close.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"newline in string found at line 1 column 42"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
table_array_implicit,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/table-array-implicit.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"table redefined as array for key `albums` at line 13 column 1"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
table_array_malformed_bracket,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/table-array-malformed-bracket.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a right bracket, found a newline at line 1 column 10"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
table_array_malformed_empty,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/table-array-malformed-empty.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a table key, found a right bracket at line 1 column 3"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
table_empty,
|
|
|
|
include_str!("invalid/table-empty.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a table key, found a right bracket at line 1 column 2"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
table_nested_brackets_close,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/table-nested-brackets-close.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected newline, found an identifier at line 1 column 4"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
table_nested_brackets_open,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/table-nested-brackets-open.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a right bracket, found a left bracket at line 1 column 3"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
table_whitespace,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/table-whitespace.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a right bracket, found an identifier at line 1 column 10"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
table_with_pound,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/table-with-pound.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a right bracket, found a comment at line 1 column 5"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
text_after_array_entries,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/text-after-array-entries.toml"),
|
2020-10-11 12:30:55 -05:00
|
|
|
"invalid TOML value, did you mean to use a quoted string? at line 2 column 46"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
text_after_integer,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/text-after-integer.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected newline, found an identifier at line 1 column 13"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
text_after_string,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/text-after-string.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected newline, found an identifier at line 1 column 41"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
text_after_table,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/text-after-table.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected newline, found an identifier at line 1 column 9"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
text_before_array_separator,
|
2019-07-28 11:56:22 -05:00
|
|
|
include_str!("invalid/text-before-array-separator.toml"),
|
2019-07-28 12:40:49 -05:00
|
|
|
"expected a right bracket, found an identifier at line 2 column 46"
|
2019-07-28 11:56:22 -05:00
|
|
|
);
|
|
|
|
test!(
|
|
|
|
text_in_array,
|
|
|
|
include_str!("invalid/text-in-array.toml"),
|
2020-10-11 12:30:55 -05:00
|
|
|
"invalid TOML value, did you mean to use a quoted string? at line 3 column 3"
|
2019-05-08 19:45:39 -05:00
|
|
|
);
|