Show "column" in Error messages

This commit is contained in:
Andres Suarez 2019-07-28 17:40:49 +00:00
parent 8820659431
commit 8c1b49f66f
6 changed files with 184 additions and 133 deletions

View file

@ -1845,7 +1845,7 @@ impl fmt::Display for Error {
} }
if let Some(line) = self.inner.line { if let Some(line) = self.inner.line {
write!(f, " at line {}", line + 1)?; write!(f, " at line {} column {}", line + 1, self.inner.col + 1)?;
} }
Ok(()) Ok(())

View file

@ -18,7 +18,10 @@ fn newlines_after_tables() {
[a] foo = 1 [a] foo = 1
[[b]] foo = 1 [[b]] foo = 1
"; ";
bad!(s, "expected newline, found an identifier at line 2"); bad!(
s,
"expected newline, found an identifier at line 2 column 13"
);
let mut d = toml::de::Deserializer::new(s); let mut d = toml::de::Deserializer::new(s);
d.set_require_newline_after_table(false); d.set_require_newline_after_table(false);
@ -41,7 +44,7 @@ fn allow_duplicate_after_longer() {
"; ";
bad!( bad!(
s, s,
"redefinition of table `dependencies` for key `dependencies` at line 8" "redefinition of table `dependencies` for key `dependencies` at line 8 column 9"
); );
let mut d = toml::de::Deserializer::new(s); let mut d = toml::de::Deserializer::new(s);

View file

@ -50,11 +50,20 @@ fn bad_times() {
"foo = 1997-09-0909:09:09", "foo = 1997-09-0909:09:09",
"failed to parse datetime for key `foo`" "failed to parse datetime for key `foo`"
); );
bad!("foo = 1997-09-09T09:09:09.", "invalid date at line 1"); bad!(
"foo = 1997-09-09T09:09:09.",
"invalid date at line 1 column 7"
);
bad!("foo = T", "failed to parse datetime for key `foo`"); bad!("foo = T", "failed to parse datetime for key `foo`");
bad!("foo = T.", "expected newline, found a period at line 1"); bad!(
"foo = T.",
"expected newline, found a period at line 1 column 8"
);
bad!("foo = TZ", "failed to parse datetime for key `foo`"); bad!("foo = TZ", "failed to parse datetime for key `foo`");
bad!("foo = 1997-09-09T09:09:09.09+", "invalid date at line 1"); bad!(
"foo = 1997-09-09T09:09:09.09+",
"invalid date at line 1 column 7"
);
bad!( bad!(
"foo = 1997-09-09T09:09:09.09+09", "foo = 1997-09-09T09:09:09.09+09",
"failed to parse datetime for key `foo`" "failed to parse datetime for key `foo`"

View file

@ -11,22 +11,22 @@ macro_rules! bad {
#[test] #[test]
fn bad() { fn bad() {
bad!("a = 01", "invalid number at line 1"); bad!("a = 01", "invalid number at line 1 column 6");
bad!("a = 1__1", "invalid number at line 1"); bad!("a = 1__1", "invalid number at line 1 column 5");
bad!("a = 1_", "invalid number at line 1"); bad!("a = 1_", "invalid number at line 1 column 5");
bad!("''", "empty table key found at line 1"); bad!("''", "empty table key found at line 1 column 1");
bad!("a = 9e99999", "invalid number at line 1"); bad!("a = 9e99999", "invalid number at line 1 column 5");
bad!( bad!(
"a = \"\u{7f}\"", "a = \"\u{7f}\"",
"invalid character in string: `\\u{7f}` at line 1" "invalid character in string: `\\u{7f}` at line 1 column 6"
); );
bad!( bad!(
"a = '\u{7f}'", "a = '\u{7f}'",
"invalid character in string: `\\u{7f}` at line 1" "invalid character in string: `\\u{7f}` at line 1 column 6"
); );
bad!("a = -0x1", "invalid number at line 1"); bad!("a = -0x1", "invalid number at line 1 column 5");
bad!("a = 0x-1", "failed to parse datetime for key `a`"); bad!("a = 0x-1", "failed to parse datetime for key `a`");
// Dotted keys. // Dotted keys.
@ -39,10 +39,10 @@ fn bad() {
bad!( bad!(
"a = 1 "a = 1
a.b = 2", a.b = 2",
"dotted key attempted to extend non-table type at line 1" "dotted key attempted to extend non-table type at line 1 column 5"
); );
bad!( bad!(
"a = {k1 = 1, k1.name = \"joe\"}", "a = {k1 = 1, k1.name = \"joe\"}",
"dotted key attempted to extend non-table type at line 1" "dotted key attempted to extend non-table type at line 1 column 11"
); );
} }

View file

@ -17,17 +17,17 @@ macro_rules! test( ($name:ident, $s:expr, $msg:expr) => (
test!( test!(
array_mixed_types_arrays_and_ints, array_mixed_types_arrays_and_ints,
include_str!("invalid/array-mixed-types-arrays-and-ints.toml"), include_str!("invalid/array-mixed-types-arrays-and-ints.toml"),
"mixed types in an array at line 1" "mixed types in an array at line 1 column 24"
); );
test!( test!(
array_mixed_types_ints_and_floats, array_mixed_types_ints_and_floats,
include_str!("invalid/array-mixed-types-ints-and-floats.toml"), include_str!("invalid/array-mixed-types-ints-and-floats.toml"),
"mixed types in an array at line 1" "mixed types in an array at line 1 column 23"
); );
test!( test!(
array_mixed_types_strings_and_ints, array_mixed_types_strings_and_ints,
include_str!("invalid/array-mixed-types-strings-and-ints.toml"), include_str!("invalid/array-mixed-types-strings-and-ints.toml"),
"mixed types in an array at line 1" "mixed types in an array at line 1 column 27"
); );
test!( test!(
datetime_malformed_no_leads, datetime_malformed_no_leads,
@ -37,7 +37,7 @@ test!(
test!( test!(
datetime_malformed_no_secs, datetime_malformed_no_secs,
include_str!("invalid/datetime-malformed-no-secs.toml"), include_str!("invalid/datetime-malformed-no-secs.toml"),
"expected a colon, found a newline at line 1" "expected a colon, found a newline at line 1 column 28"
); );
test!( test!(
datetime_malformed_no_t, datetime_malformed_no_t,
@ -62,180 +62,180 @@ test!(
test!( test!(
duplicate_table, duplicate_table,
include_str!("invalid/duplicate-table.toml"), include_str!("invalid/duplicate-table.toml"),
"redefinition of table `dependencies` for key `dependencies` at line 7" "redefinition of table `dependencies` for key `dependencies` at line 7 column 1"
); );
test!( test!(
duplicate_tables, duplicate_tables,
include_str!("invalid/duplicate-tables.toml"), include_str!("invalid/duplicate-tables.toml"),
"redefinition of table `a` for key `a` at line 2" "redefinition of table `a` for key `a` at line 2 column 1"
); );
test!( test!(
empty_implicit_table, empty_implicit_table,
include_str!("invalid/empty-implicit-table.toml"), include_str!("invalid/empty-implicit-table.toml"),
"expected a table key, found a period at line 1" "expected a table key, found a period at line 1 column 10"
); );
test!( test!(
empty_table, empty_table,
include_str!("invalid/empty-table.toml"), include_str!("invalid/empty-table.toml"),
"expected a table key, found a right bracket at line 1" "expected a table key, found a right bracket at line 1 column 2"
); );
test!( test!(
float_no_leading_zero, float_no_leading_zero,
include_str!("invalid/float-no-leading-zero.toml"), include_str!("invalid/float-no-leading-zero.toml"),
"expected a value, found a period at line 1" "expected a value, found a period at line 1 column 10"
); );
test!( test!(
float_no_suffix, float_no_suffix,
include_str!("invalid/float-no-suffix.toml"), include_str!("invalid/float-no-suffix.toml"),
"invalid number at line 1" "invalid number at line 1 column 5"
); );
test!( test!(
float_no_trailing_digits, float_no_trailing_digits,
include_str!("invalid/float-no-trailing-digits.toml"), include_str!("invalid/float-no-trailing-digits.toml"),
"invalid number at line 1" "invalid number at line 1 column 12"
); );
test!( test!(
key_after_array, key_after_array,
include_str!("invalid/key-after-array.toml"), include_str!("invalid/key-after-array.toml"),
"expected newline, found an identifier at line 1" "expected newline, found an identifier at line 1 column 14"
); );
test!( test!(
key_after_table, key_after_table,
include_str!("invalid/key-after-table.toml"), include_str!("invalid/key-after-table.toml"),
"expected newline, found an identifier at line 1" "expected newline, found an identifier at line 1 column 11"
); );
test!( test!(
key_empty, key_empty,
include_str!("invalid/key-empty.toml"), include_str!("invalid/key-empty.toml"),
"expected a table key, found an equals at line 1" "expected a table key, found an equals at line 1 column 2"
); );
test!( test!(
key_hash, key_hash,
include_str!("invalid/key-hash.toml"), include_str!("invalid/key-hash.toml"),
"expected an equals, found a comment at line 1" "expected an equals, found a comment at line 1 column 2"
); );
test!( test!(
key_newline, key_newline,
include_str!("invalid/key-newline.toml"), include_str!("invalid/key-newline.toml"),
"expected an equals, found a newline at line 1" "expected an equals, found a newline at line 1 column 2"
); );
test!( test!(
key_open_bracket, key_open_bracket,
include_str!("invalid/key-open-bracket.toml"), include_str!("invalid/key-open-bracket.toml"),
"expected a right bracket, found an equals at line 1" "expected a right bracket, found an equals at line 1 column 6"
); );
test!( test!(
key_single_open_bracket, key_single_open_bracket,
include_str!("invalid/key-single-open-bracket.toml"), include_str!("invalid/key-single-open-bracket.toml"),
"expected a table key, found eof at line 1" "expected a table key, found eof at line 1 column 2"
); );
test!( test!(
key_space, key_space,
include_str!("invalid/key-space.toml"), include_str!("invalid/key-space.toml"),
"expected an equals, found an identifier at line 1" "expected an equals, found an identifier at line 1 column 3"
); );
test!( test!(
key_start_bracket, key_start_bracket,
include_str!("invalid/key-start-bracket.toml"), include_str!("invalid/key-start-bracket.toml"),
"expected a right bracket, found an equals at line 2" "expected a right bracket, found an equals at line 2 column 6"
); );
test!( test!(
key_two_equals, key_two_equals,
include_str!("invalid/key-two-equals.toml"), include_str!("invalid/key-two-equals.toml"),
"expected a value, found an equals at line 1" "expected a value, found an equals at line 1 column 6"
); );
test!( test!(
string_bad_byte_escape, string_bad_byte_escape,
include_str!("invalid/string-bad-byte-escape.toml"), include_str!("invalid/string-bad-byte-escape.toml"),
"invalid escape character in string: `x` at line 1" "invalid escape character in string: `x` at line 1 column 13"
); );
test!( test!(
string_bad_escape, string_bad_escape,
include_str!("invalid/string-bad-escape.toml"), include_str!("invalid/string-bad-escape.toml"),
"invalid escape character in string: `a` at line 1" "invalid escape character in string: `a` at line 1 column 42"
); );
test!( test!(
string_bad_line_ending_escape, string_bad_line_ending_escape,
include_str!("invalid/string-bad-line-ending-escape.toml"), include_str!("invalid/string-bad-line-ending-escape.toml"),
"invalid escape character in string: ` ` at line 2" "invalid escape character in string: ` ` at line 2 column 79"
); );
test!( test!(
string_byte_escapes, string_byte_escapes,
include_str!("invalid/string-byte-escapes.toml"), include_str!("invalid/string-byte-escapes.toml"),
"invalid escape character in string: `x` at line 1" "invalid escape character in string: `x` at line 1 column 12"
); );
test!( test!(
string_no_close, string_no_close,
include_str!("invalid/string-no-close.toml"), include_str!("invalid/string-no-close.toml"),
"newline in string found at line 1" "newline in string found at line 1 column 42"
); );
test!( test!(
table_array_implicit, table_array_implicit,
include_str!("invalid/table-array-implicit.toml"), include_str!("invalid/table-array-implicit.toml"),
"table redefined as array for key `albums` at line 13" "table redefined as array for key `albums` at line 13 column 1"
); );
test!( test!(
table_array_malformed_bracket, table_array_malformed_bracket,
include_str!("invalid/table-array-malformed-bracket.toml"), include_str!("invalid/table-array-malformed-bracket.toml"),
"expected a right bracket, found a newline at line 1" "expected a right bracket, found a newline at line 1 column 10"
); );
test!( test!(
table_array_malformed_empty, table_array_malformed_empty,
include_str!("invalid/table-array-malformed-empty.toml"), include_str!("invalid/table-array-malformed-empty.toml"),
"expected a table key, found a right bracket at line 1" "expected a table key, found a right bracket at line 1 column 3"
); );
test!( test!(
table_empty, table_empty,
include_str!("invalid/table-empty.toml"), include_str!("invalid/table-empty.toml"),
"expected a table key, found a right bracket at line 1" "expected a table key, found a right bracket at line 1 column 2"
); );
test!( test!(
table_nested_brackets_close, table_nested_brackets_close,
include_str!("invalid/table-nested-brackets-close.toml"), include_str!("invalid/table-nested-brackets-close.toml"),
"expected newline, found an identifier at line 1" "expected newline, found an identifier at line 1 column 4"
); );
test!( test!(
table_nested_brackets_open, table_nested_brackets_open,
include_str!("invalid/table-nested-brackets-open.toml"), include_str!("invalid/table-nested-brackets-open.toml"),
"expected a right bracket, found a left bracket at line 1" "expected a right bracket, found a left bracket at line 1 column 3"
); );
test!( test!(
table_whitespace, table_whitespace,
include_str!("invalid/table-whitespace.toml"), include_str!("invalid/table-whitespace.toml"),
"expected a right bracket, found an identifier at line 1" "expected a right bracket, found an identifier at line 1 column 10"
); );
test!( test!(
table_with_pound, table_with_pound,
include_str!("invalid/table-with-pound.toml"), include_str!("invalid/table-with-pound.toml"),
"expected a right bracket, found a comment at line 1" "expected a right bracket, found a comment at line 1 column 5"
); );
test!( test!(
text_after_array_entries, text_after_array_entries,
include_str!("invalid/text-after-array-entries.toml"), include_str!("invalid/text-after-array-entries.toml"),
"invalid number at line 2" "invalid number at line 2 column 46"
); );
test!( test!(
text_after_integer, text_after_integer,
include_str!("invalid/text-after-integer.toml"), include_str!("invalid/text-after-integer.toml"),
"expected newline, found an identifier at line 1" "expected newline, found an identifier at line 1 column 13"
); );
test!( test!(
text_after_string, text_after_string,
include_str!("invalid/text-after-string.toml"), include_str!("invalid/text-after-string.toml"),
"expected newline, found an identifier at line 1" "expected newline, found an identifier at line 1 column 41"
); );
test!( test!(
text_after_table, text_after_table,
include_str!("invalid/text-after-table.toml"), include_str!("invalid/text-after-table.toml"),
"expected newline, found an identifier at line 1" "expected newline, found an identifier at line 1 column 9"
); );
test!( test!(
text_before_array_separator, text_before_array_separator,
include_str!("invalid/text-before-array-separator.toml"), include_str!("invalid/text-before-array-separator.toml"),
"expected a right bracket, found an identifier at line 2" "expected a right bracket, found an identifier at line 2 column 46"
); );
test!( test!(
text_in_array, text_in_array,
include_str!("invalid/text-in-array.toml"), include_str!("invalid/text-in-array.toml"),
"invalid number at line 3" "invalid number at line 3 column 3"
); );

View file

@ -186,22 +186,31 @@ name = "plantain"
#[test] #[test]
fn stray_cr() { fn stray_cr() {
bad!("\r", "unexpected character found: `\\r` at line 1"); bad!("\r", "unexpected character found: `\\r` at line 1 column 1");
bad!("a = [ \r ]", "unexpected character found: `\\r` at line 1"); bad!(
"a = [ \r ]",
"unexpected character found: `\\r` at line 1 column 7"
);
bad!( bad!(
"a = \"\"\"\r\"\"\"", "a = \"\"\"\r\"\"\"",
"invalid character in string: `\\r` at line 1" "invalid character in string: `\\r` at line 1 column 8"
); );
bad!( bad!(
"a = \"\"\"\\ \r \"\"\"", "a = \"\"\"\\ \r \"\"\"",
"invalid escape character in string: ` ` at line 1" "invalid escape character in string: ` ` at line 1 column 9"
); );
bad!( bad!(
"a = '''\r'''", "a = '''\r'''",
"invalid character in string: `\\r` at line 1" "invalid character in string: `\\r` at line 1 column 8"
);
bad!(
"a = '\r'",
"invalid character in string: `\\r` at line 1 column 6"
);
bad!(
"a = \"\r\"",
"invalid character in string: `\\r` at line 1 column 6"
); );
bad!("a = '\r'", "invalid character in string: `\\r` at line 1");
bad!("a = \"\r\"", "invalid character in string: `\\r` at line 1");
} }
#[test] #[test]
@ -230,32 +239,38 @@ fn literal_eats_crlf() {
#[test] #[test]
fn string_no_newline() { fn string_no_newline() {
bad!("a = \"\n\"", "newline in string found at line 1"); bad!("a = \"\n\"", "newline in string found at line 1 column 6");
bad!("a = '\n'", "newline in string found at line 1"); bad!("a = '\n'", "newline in string found at line 1 column 6");
} }
#[test] #[test]
fn bad_leading_zeros() { fn bad_leading_zeros() {
bad!("a = 00", "invalid number at line 1"); bad!("a = 00", "invalid number at line 1 column 6");
bad!("a = -00", "invalid number at line 1"); bad!("a = -00", "invalid number at line 1 column 7");
bad!("a = +00", "invalid number at line 1"); bad!("a = +00", "invalid number at line 1 column 7");
bad!("a = 00.0", "invalid number at line 1"); bad!("a = 00.0", "invalid number at line 1 column 6");
bad!("a = -00.0", "invalid number at line 1"); bad!("a = -00.0", "invalid number at line 1 column 7");
bad!("a = +00.0", "invalid number at line 1"); bad!("a = +00.0", "invalid number at line 1 column 7");
bad!("a = 9223372036854775808", "invalid number at line 1"); bad!(
bad!("a = -9223372036854775809", "invalid number at line 1"); "a = 9223372036854775808",
"invalid number at line 1 column 5"
);
bad!(
"a = -9223372036854775809",
"invalid number at line 1 column 5"
);
} }
#[test] #[test]
fn bad_floats() { fn bad_floats() {
bad!("a = 0.", "invalid number at line 1"); bad!("a = 0.", "invalid number at line 1 column 7");
bad!("a = 0.e", "invalid number at line 1"); bad!("a = 0.e", "invalid number at line 1 column 7");
bad!("a = 0.E", "invalid number at line 1"); bad!("a = 0.E", "invalid number at line 1 column 7");
bad!("a = 0.0E", "invalid number at line 1"); bad!("a = 0.0E", "invalid number at line 1 column 5");
bad!("a = 0.0e", "invalid number at line 1"); bad!("a = 0.0e", "invalid number at line 1 column 5");
bad!("a = 0.0e-", "invalid number at line 1"); bad!("a = 0.0e-", "invalid number at line 1 column 9");
bad!("a = 0.0e+", "invalid number at line 1"); bad!("a = 0.0e+", "invalid number at line 1 column 5");
bad!("a = 0.0e+00", "invalid number at line 1"); bad!("a = 0.0e+00", "invalid number at line 1 column 11");
} }
#[test] #[test]
@ -316,29 +331,44 @@ fn bare_key_names() {
#[test] #[test]
fn bad_keys() { fn bad_keys() {
bad!("key\n=3", "expected an equals, found a newline at line 1"); bad!(
bad!("key=\n3", "expected a value, found a newline at line 1"); "key\n=3",
bad!("key|=3", "unexpected character found: `|` at line 1"); "expected an equals, found a newline at line 1 column 4"
bad!("\"\"=3", "empty table key found at line 1"); );
bad!("=3", "expected a table key, found an equals at line 1"); bad!(
bad!("\"\"|=3", "empty table key found at line 1"); "key=\n3",
bad!("\"\n\"|=3", "newline in string found at line 1"); "expected a value, found a newline at line 1 column 5"
bad!("\"\r\"|=3", "invalid character in string: `\\r` at line 1"); );
bad!(
"key|=3",
"unexpected character found: `|` at line 1 column 4"
);
bad!("\"\"=3", "empty table key found at line 1 column 1");
bad!(
"=3",
"expected a table key, found an equals at line 1 column 1"
);
bad!("\"\"|=3", "empty table key found at line 1 column 1");
bad!("\"\n\"|=3", "newline in string found at line 1 column 2");
bad!(
"\"\r\"|=3",
"invalid character in string: `\\r` at line 1 column 2"
);
bad!( bad!(
"''''''=3", "''''''=3",
"multiline strings are not allowed for key at line 1" "multiline strings are not allowed for key at line 1 column 1"
); );
bad!( bad!(
"\"\"\"\"\"\"=3", "\"\"\"\"\"\"=3",
"multiline strings are not allowed for key at line 1" "multiline strings are not allowed for key at line 1 column 1"
); );
bad!( bad!(
"'''key'''=3", "'''key'''=3",
"multiline strings are not allowed for key at line 1" "multiline strings are not allowed for key at line 1 column 1"
); );
bad!( bad!(
"\"\"\"key\"\"\"=3", "\"\"\"key\"\"\"=3",
"multiline strings are not allowed for key at line 1" "multiline strings are not allowed for key at line 1 column 1"
); );
} }
@ -346,37 +376,40 @@ fn bad_keys() {
fn bad_table_names() { fn bad_table_names() {
bad!( bad!(
"[]", "[]",
"expected a table key, found a right bracket at line 1" "expected a table key, found a right bracket at line 1 column 2"
); );
bad!("[.]", "expected a table key, found a period at line 1"); bad!(
bad!("[\"\".\"\"]", "empty table key found at line 1"); "[.]",
"expected a table key, found a period at line 1 column 2"
);
bad!("[\"\".\"\"]", "empty table key found at line 1 column 2");
bad!( bad!(
"[a.]", "[a.]",
"expected a table key, found a right bracket at line 1" "expected a table key, found a right bracket at line 1 column 4"
); );
bad!("[\"\"]", "empty table key found at line 1"); bad!("[\"\"]", "empty table key found at line 1 column 2");
bad!("[!]", "unexpected character found: `!` at line 1"); bad!("[!]", "unexpected character found: `!` at line 1 column 2");
bad!("[\"\n\"]", "newline in string found at line 1"); bad!("[\"\n\"]", "newline in string found at line 1 column 3");
bad!( bad!(
"[a.b]\n[a.\"b\"]", "[a.b]\n[a.\"b\"]",
"redefinition of table `a.b` for key `a.b` at line 2" "redefinition of table `a.b` for key `a.b` at line 2 column 1"
); );
bad!("[']", "unterminated string at line 1"); bad!("[']", "unterminated string at line 1 column 2");
bad!("[''']", "unterminated string at line 1"); bad!("[''']", "unterminated string at line 1 column 2");
bad!( bad!(
"['''''']", "['''''']",
"multiline strings are not allowed for key at line 1" "multiline strings are not allowed for key at line 1 column 2"
); );
bad!( bad!(
"['''foo''']", "['''foo''']",
"multiline strings are not allowed for key at line 1" "multiline strings are not allowed for key at line 1 column 2"
); );
bad!( bad!(
"[\"\"\"bar\"\"\"]", "[\"\"\"bar\"\"\"]",
"multiline strings are not allowed for key at line 1" "multiline strings are not allowed for key at line 1 column 2"
); );
bad!("['\n']", "newline in string found at line 1"); bad!("['\n']", "newline in string found at line 1 column 3");
bad!("['\r\n']", "newline in string found at line 1"); bad!("['\r\n']", "newline in string found at line 1 column 3");
} }
#[test] #[test]
@ -401,7 +434,7 @@ fn table_names() {
#[test] #[test]
fn invalid_bare_numeral() { fn invalid_bare_numeral() {
bad!("4", "expected an equals, found eof at line 1"); bad!("4", "expected an equals, found eof at line 1 column 2");
} }
#[test] #[test]
@ -414,15 +447,21 @@ fn inline_tables() {
bad!( bad!(
"a = {a=1,}", "a = {a=1,}",
"expected a table key, found a right brace at line 1" "expected a table key, found a right brace at line 1 column 10"
);
bad!(
"a = {,}",
"expected a table key, found a comma at line 1 column 6"
); );
bad!("a = {,}", "expected a table key, found a comma at line 1");
bad!("a = {a=1,a=1}", "duplicate key: `a` for key `a`"); bad!("a = {a=1,a=1}", "duplicate key: `a` for key `a`");
bad!( bad!(
"a = {\n}", "a = {\n}",
"expected a table key, found a newline at line 1" "expected a table key, found a newline at line 1 column 6"
);
bad!(
"a = {",
"expected a table key, found eof at line 1 column 6"
); );
bad!("a = {", "expected a table key, found eof at line 1");
"a = {a=[\n]}".parse::<Value>().unwrap(); "a = {a=[\n]}".parse::<Value>().unwrap();
"a = {\"a\"=[\n]}".parse::<Value>().unwrap(); "a = {\"a\"=[\n]}".parse::<Value>().unwrap();
@ -448,17 +487,17 @@ fn number_underscores() {
#[test] #[test]
fn bad_underscores() { fn bad_underscores() {
bad!("foo = 0_", "invalid number at line 1"); bad!("foo = 0_", "invalid number at line 1 column 7");
bad!("foo = 0__0", "invalid number at line 1"); bad!("foo = 0__0", "invalid number at line 1 column 7");
bad!("foo = __0", "invalid number at line 1"); bad!("foo = __0", "invalid number at line 1 column 7");
bad!("foo = 1_0_", "invalid number at line 1"); bad!("foo = 1_0_", "invalid number at line 1 column 7");
} }
#[test] #[test]
fn bad_unicode_codepoint() { fn bad_unicode_codepoint() {
bad!( bad!(
"foo = \"\\uD800\"", "foo = \"\\uD800\"",
"invalid escape value: `55296` at line 1" "invalid escape value: `55296` at line 1 column 9"
); );
} }
@ -466,14 +505,14 @@ fn bad_unicode_codepoint() {
fn bad_strings() { fn bad_strings() {
bad!( bad!(
"foo = \"\\uxx\"", "foo = \"\\uxx\"",
"invalid hex escape character in string: `x` at line 1" "invalid hex escape character in string: `x` at line 1 column 10"
); );
bad!( bad!(
"foo = \"\\u\"", "foo = \"\\u\"",
"invalid hex escape character in string: `\\\"` at line 1" "invalid hex escape character in string: `\\\"` at line 1 column 10"
); );
bad!("foo = \"\\", "unterminated string at line 1"); bad!("foo = \"\\", "unterminated string at line 1 column 7");
bad!("foo = '", "unterminated string at line 1"); bad!("foo = '", "unterminated string at line 1 column 7");
} }
#[test] #[test]
@ -495,9 +534,9 @@ fn booleans() {
assert_eq!(table["foo"].as_bool(), Some(false)); assert_eq!(table["foo"].as_bool(), Some(false));
bad!("foo = true2", "failed to parse datetime for key `foo`"); bad!("foo = true2", "failed to parse datetime for key `foo`");
bad!("foo = false2", "invalid number at line 1"); bad!("foo = false2", "invalid number at line 1 column 7");
bad!("foo = t1", "failed to parse datetime for key `foo`"); bad!("foo = t1", "failed to parse datetime for key `foo`");
bad!("foo = f2", "invalid number at line 1"); bad!("foo = f2", "invalid number at line 1 column 7");
} }
#[test] #[test]
@ -552,7 +591,7 @@ fn bad_table_redefine() {
foo=\"bar\" foo=\"bar\"
[a] [a]
", ",
"redefinition of table `a` for key `a` at line 6" "redefinition of table `a` for key `a` at line 6 column 9"
); );
bad!( bad!(
" "
@ -561,7 +600,7 @@ fn bad_table_redefine() {
b = { foo = \"bar\" } b = { foo = \"bar\" }
[a] [a]
", ",
"redefinition of table `a` for key `a` at line 5" "redefinition of table `a` for key `a` at line 5 column 9"
); );
bad!( bad!(
" "
@ -578,7 +617,7 @@ fn bad_table_redefine() {
b = {} b = {}
[a] [a]
", ",
"redefinition of table `a` for key `a` at line 4" "redefinition of table `a` for key `a` at line 4 column 9"
); );
} }
@ -620,12 +659,12 @@ fn datetimes() {
#[test] #[test]
fn require_newline_after_value() { fn require_newline_after_value() {
bad!("0=0r=false", "invalid number at line 1"); bad!("0=0r=false", "invalid number at line 1 column 3");
bad!( bad!(
r#" r#"
0=""o=""m=""r=""00="0"q="""0"""e="""0""" 0=""o=""m=""r=""00="0"q="""0"""e="""0"""
"#, "#,
"expected newline, found an identifier at line 2" "expected newline, found an identifier at line 2 column 5"
); );
bad!( bad!(
r#" r#"
@ -634,24 +673,24 @@ fn require_newline_after_value() {
0="0"[[0000l0]] 0="0"[[0000l0]]
0="0"l="0" 0="0"l="0"
"#, "#,
"expected newline, found a left bracket at line 3" "expected newline, found a left bracket at line 3 column 6"
); );
bad!( bad!(
r#" r#"
0=[0]00=[0,0,0]t=["0","0","0"]s=[1000-00-00T00:00:00Z,2000-00-00T00:00:00Z] 0=[0]00=[0,0,0]t=["0","0","0"]s=[1000-00-00T00:00:00Z,2000-00-00T00:00:00Z]
"#, "#,
"expected newline, found an identifier at line 2" "expected newline, found an identifier at line 2 column 6"
); );
bad!( bad!(
r#" r#"
0=0r0=0r=false 0=0r0=0r=false
"#, "#,
"invalid number at line 2" "invalid number at line 2 column 3"
); );
bad!( bad!(
r#" r#"
0=0r0=0r=falsefal=false 0=0r0=0r=falsefal=false
"#, "#,
"invalid number at line 2" "invalid number at line 2 column 3"
); );
} }