diff --git a/Cargo.lock b/Cargo.lock index 3dc35f5b..411c9084 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -611,9 +611,9 @@ checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" [[package]] name = "snapbox" -version = "0.5.14" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f37d101fcafc8e73748fd8a1b7048f5979f93d372fd17027d7724c1643bc379b" +checksum = "9ad8c7be18cc9ec7f4d7948ad6b9df0e04fc649663e3c0ed59f304ed17ca69e9" dependencies = [ "anstream 0.6.14", "anstyle", diff --git a/crates/toml/Cargo.toml b/crates/toml/Cargo.toml index 5d93bcd8..ea0969fd 100644 --- a/crates/toml/Cargo.toml +++ b/crates/toml/Cargo.toml @@ -51,7 +51,7 @@ serde = { version = "1.0.199", features = ["derive"] } serde_json = "1.0.116" toml-test-harness = "0.4.8" toml-test-data = "1.11.0" -snapbox = "0.5.14" +snapbox = "0.6.0" [[test]] name = "decoder_compliance" diff --git a/crates/toml/tests/testsuite/de_errors.rs b/crates/toml/tests/testsuite/de_errors.rs index 8c3bf71f..3600f98c 100644 --- a/crates/toml/tests/testsuite/de_errors.rs +++ b/crates/toml/tests/testsuite/de_errors.rs @@ -88,12 +88,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 2, column 19 - | - 2 | p_a = '' - | ^^ - invalid length 0, expected a non-empty string - "#]] +TOML parse error at line 2, column 19 + | +2 | p_a = '' + | ^^ +invalid length 0, expected a non-empty string + +"#]] ); // Missing field in table. @@ -104,12 +105,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 1, column 1 - | - 1 | - | ^ - missing field `p_b` - "#]] +TOML parse error at line 1, column 1 + | +1 | + | ^ +missing field `p_b` + +"#]] ); // Invalid type in p_b. @@ -121,12 +123,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 3, column 19 - | - 3 | p_b = 1 - | ^ - invalid type: integer `1`, expected a sequence - "#]] +TOML parse error at line 3, column 19 + | +3 | p_b = 1 + | ^ +invalid type: integer `1`, expected a sequence + +"#]] ); // Sub-table in Vec is missing a field. @@ -140,12 +143,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 4, column 17 - | - 4 | {c_a = 'a'} - | ^^^^^^^^^^^ - missing field `c_b` - "#]] +TOML parse error at line 4, column 17 + | +4 | {c_a = 'a'} + | ^^^^^^^^^^^ +missing field `c_b` + +"#]] ); // Sub-table in Vec has a field with a bad value. @@ -159,12 +163,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 4, column 35 - | - 4 | {c_a = 'a', c_b = '*'} - | ^^^ - invalid value: string "*", expected all lowercase or all uppercase - "#]] +TOML parse error at line 4, column 35 + | +4 | {c_a = 'a', c_b = '*'} + | ^^^ +invalid value: string "*", expected all lowercase or all uppercase + +"#]] ); // Sub-table in Vec is missing a field. @@ -179,12 +184,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 5, column 17 - | - 5 | {c_a = 'aa'} - | ^^^^^^^^^^^^ - missing field `c_b` - "#]] +TOML parse error at line 5, column 17 + | +5 | {c_a = 'aa'} + | ^^^^^^^^^^^^ +missing field `c_b` + +"#]] ); // Sub-table in the middle of a Vec is missing a field. @@ -200,12 +206,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 5, column 17 - | - 5 | {c_a = 'aa'}, - | ^^^^^^^^^^^^ - missing field `c_b` - "#]] +TOML parse error at line 5, column 17 + | +5 | {c_a = 'aa'}, + | ^^^^^^^^^^^^ +missing field `c_b` + +"#]] ); // Sub-table in the middle of a Vec has a field with a bad value. @@ -221,12 +228,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 5, column 36 - | - 5 | {c_a = 'aa', c_b = 1}, - | ^ - invalid type: integer `1`, expected a string - "#]] +TOML parse error at line 5, column 36 + | +5 | {c_a = 'aa', c_b = 1}, + | ^ +invalid type: integer `1`, expected a string + +"#]] ); // Sub-table in the middle of a Vec has an extra field. @@ -243,12 +251,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 5, column 42 - | - 5 | {c_a = 'aa', c_b = 'bb', c_d = 'd'}, - | ^^^ - unknown field `c_d`, expected `c_a` or `c_b` - "#]] +TOML parse error at line 5, column 42 + | +5 | {c_a = 'aa', c_b = 'bb', c_d = 'd'}, + | ^^^ +unknown field `c_d`, expected `c_a` or `c_b` + +"#]] ); // Sub-table in the middle of a Vec is missing a field. @@ -272,12 +281,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 6, column 13 - | - 6 | [[p_b]] - | ^^^^^^^ - missing field `c_b` - "#]] +TOML parse error at line 6, column 13 + | +6 | [[p_b]] + | ^^^^^^^ +missing field `c_b` + +"#]] ); // Sub-table in the middle of a Vec has a field with a bad value. @@ -297,12 +307,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 8, column 19 - | - 8 | c_b = '*' - | ^^^ - invalid value: string "*", expected all lowercase or all uppercase - "#]] +TOML parse error at line 8, column 19 + | +8 | c_b = '*' + | ^^^ +invalid value: string "*", expected all lowercase or all uppercase + +"#]] ); // Sub-table in the middle of a Vec has an extra field. @@ -325,12 +336,13 @@ fn custom_errors() { ", Parent, str![[r#" - TOML parse error at line 8, column 13 - | - 8 | c_d = 'dd' # unknown field - | ^^^ - unknown field `c_d`, expected `c_a` or `c_b` - "#]] +TOML parse error at line 8, column 13 + | +8 | c_d = 'dd' # unknown field + | ^^^ +unknown field `c_d`, expected `c_a` or `c_b` + +"#]] ); } @@ -343,12 +355,13 @@ fn serde_derive_deserialize_errors() { ", Parent, str![[r#" - TOML parse error at line 1, column 1 - | - 1 | - | ^ - missing field `p_b` - "#]] +TOML parse error at line 1, column 1 + | +1 | + | ^ +missing field `p_b` + +"#]] ); bad!( @@ -361,12 +374,13 @@ fn serde_derive_deserialize_errors() { ", Parent, str![[r#" - TOML parse error at line 4, column 17 - | - 4 | {c_a = ''} - | ^^^^^^^^^^ - missing field `c_b` - "#]] +TOML parse error at line 4, column 17 + | +4 | {c_a = ''} + | ^^^^^^^^^^ +missing field `c_b` + +"#]] ); bad!( @@ -379,12 +393,13 @@ fn serde_derive_deserialize_errors() { ", Parent, str![[r#" - TOML parse error at line 4, column 34 - | - 4 | {c_a = '', c_b = 1} - | ^ - invalid type: integer `1`, expected a string - "#]] +TOML parse error at line 4, column 34 + | +4 | {c_a = '', c_b = 1} + | ^ +invalid type: integer `1`, expected a string + +"#]] ); // FIXME: This location could be better. @@ -398,12 +413,13 @@ fn serde_derive_deserialize_errors() { ", Parent, str![[r#" - TOML parse error at line 4, column 38 - | - 4 | {c_a = '', c_b = '', c_d = ''}, - | ^^^ - unknown field `c_d`, expected `c_a` or `c_b` - "#]] +TOML parse error at line 4, column 38 + | +4 | {c_a = '', c_b = '', c_d = ''}, + | ^^^ +unknown field `c_d`, expected `c_a` or `c_b` + +"#]] ); bad!( @@ -416,12 +432,13 @@ fn serde_derive_deserialize_errors() { ", Parent, str![[r#" - TOML parse error at line 4, column 34 - | - 4 | {c_a = '', c_b = 1, c_d = ''}, - | ^ - invalid type: integer `1`, expected a string - "#]] +TOML parse error at line 4, column 34 + | +4 | {c_a = '', c_b = 1, c_d = ''}, + | ^ +invalid type: integer `1`, expected a string + +"#]] ); } @@ -436,12 +453,13 @@ fn error_handles_crlf() { ", toml::Value, str![[r#" - TOML parse error at line 5, column 1 - | - 5 | a = 2 - | ^ - duplicate key `a` in table `t2` - "#]] +TOML parse error at line 5, column 1 + | +5 | a = 2 + | ^ +duplicate key `a` in table `t2` + +"#]] ); // Should be the same as above. @@ -454,11 +472,12 @@ fn error_handles_crlf() { ", toml::Value, str![[r#" - TOML parse error at line 5, column 1 - | - 5 | a = 2 - | ^ - duplicate key `a` in table `t2` - "#]] +TOML parse error at line 5, column 1 + | +5 | a = 2 + | ^ +duplicate key `a` in table `t2` + +"#]] ); } diff --git a/crates/toml/tests/testsuite/enum_external_deserialize.rs b/crates/toml/tests/testsuite/enum_external_deserialize.rs index 67d45bbb..247a2c9e 100644 --- a/crates/toml/tests/testsuite/enum_external_deserialize.rs +++ b/crates/toml/tests/testsuite/enum_external_deserialize.rs @@ -36,72 +36,112 @@ where #[test] fn invalid_variant_returns_error_with_good_message_string() { let error = value_from_str::("\"NonExistent\"").unwrap_err(); - assert_data_eq!(error.to_string(), str![[r#" - unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` - "#]].raw()); + assert_data_eq!( + error.to_string(), + str![[r#" +unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` + +"#]] + .raw() + ); let error = toml::from_str::("val = \"NonExistent\"").unwrap_err(); - assert_data_eq!(error.to_string(), str![[r#" - TOML parse error at line 1, column 7 - | - 1 | val = "NonExistent" - | ^^^^^^^^^^^^^ - unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` - "#]].raw()); + assert_data_eq!( + error.to_string(), + str![[r#" +TOML parse error at line 1, column 7 + | +1 | val = "NonExistent" + | ^^^^^^^^^^^^^ +unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` + +"#]] + .raw() + ); } #[test] fn invalid_variant_returns_error_with_good_message_inline_table() { let error = value_from_str::("{ NonExistent = {} }").unwrap_err(); - assert_data_eq!(error.to_string(), str![[r#" - unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` - "#]].raw()); + assert_data_eq!( + error.to_string(), + str![[r#" +unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` + +"#]] + .raw() + ); let error = toml::from_str::("val = { NonExistent = {} }").unwrap_err(); - assert_data_eq!(error.to_string(), str![[r#" - TOML parse error at line 1, column 9 - | - 1 | val = { NonExistent = {} } - | ^^^^^^^^^^^ - unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` - "#]].raw()); + assert_data_eq!( + error.to_string(), + str![[r#" +TOML parse error at line 1, column 9 + | +1 | val = { NonExistent = {} } + | ^^^^^^^^^^^ +unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` + +"#]] + .raw() + ); } #[test] fn extra_field_returns_expected_empty_table_error() { let error = value_from_str::("{ Plain = { extra_field = 404 } }").unwrap_err(); - assert_data_eq!(error.to_string(), str![[r#" - expected empty table - "#]].raw()); + assert_data_eq!( + error.to_string(), + str![[r#" +expected empty table + +"#]] + .raw() + ); let error = toml::from_str::("val = { Plain = { extra_field = 404 } }").unwrap_err(); - assert_data_eq!(error.to_string(), str![[r#" - TOML parse error at line 1, column 17 - | - 1 | val = { Plain = { extra_field = 404 } } - | ^^^^^^^^^^^^^^^^^^^^^ - expected empty table - "#]].raw()); + assert_data_eq!( + error.to_string(), + str![[r#" +TOML parse error at line 1, column 17 + | +1 | val = { Plain = { extra_field = 404 } } + | ^^^^^^^^^^^^^^^^^^^^^ +expected empty table + +"#]] + .raw() + ); } #[test] fn extra_field_returns_expected_empty_table_error_struct_variant() { let error = value_from_str::("{ Struct = { value = 123, extra_0 = 0, extra_1 = 1 } }") .unwrap_err(); - assert_data_eq!(error.to_string(), str![[r#" - unexpected keys in table: extra_0, extra_1, available keys: value - "#]].raw()); + assert_data_eq!( + error.to_string(), + str![[r#" +unexpected keys in table: extra_0, extra_1, available keys: value + +"#]] + .raw() + ); let error = toml::from_str::("val = { Struct = { value = 123, extra_0 = 0, extra_1 = 1 } }") .unwrap_err(); - assert_data_eq!(error.to_string(), str![[r#" - TOML parse error at line 1, column 33 - | - 1 | val = { Struct = { value = 123, extra_0 = 0, extra_1 = 1 } } - | ^^^^^^^ - unexpected keys in table: extra_0, extra_1, available keys: value - "#]].raw()); + assert_data_eq!( + error.to_string(), + str![[r#" +TOML parse error at line 1, column 33 + | +1 | val = { Struct = { value = 123, extra_0 = 0, extra_1 = 1 } } + | ^^^^^^^ +unexpected keys in table: extra_0, extra_1, available keys: value + +"#]] + .raw() + ); } mod enum_unit { diff --git a/crates/toml/tests/testsuite/serde.rs b/crates/toml/tests/testsuite/serde.rs index 0af6aff4..c3a10eb7 100644 --- a/crates/toml/tests/testsuite/serde.rs +++ b/crates/toml/tests/testsuite/serde.rs @@ -290,16 +290,18 @@ fn type_errors() { bar: Value::String("a".to_owned()) }, str![[r#" - TOML parse error at line 1, column 7 - | - 1 | bar = "a" - | ^^^ - invalid type: string "a", expected isize - "#]], +TOML parse error at line 1, column 7 + | +1 | bar = "a" + | ^^^ +invalid type: string "a", expected isize + +"#]], str![[r#" - invalid type: string "a", expected isize - in `bar` - "#]] +invalid type: string "a", expected isize +in `bar` + +"#]] } error! { @@ -310,16 +312,18 @@ fn type_errors() { } }, str![[r#" - TOML parse error at line 2, column 7 - | - 2 | bar = "a" - | ^^^ - invalid type: string "a", expected isize - "#]], +TOML parse error at line 2, column 7 + | +2 | bar = "a" + | ^^^ +invalid type: string "a", expected isize + +"#]], str![[r#" - invalid type: string "a", expected isize - in `foo.bar` - "#]] +invalid type: string "a", expected isize +in `foo.bar` + +"#]] } } @@ -334,15 +338,17 @@ fn missing_errors() { Foo, map! { }, str![[r#" - TOML parse error at line 1, column 1 - | - 1 | - | ^ - missing field `bar` - "#]], +TOML parse error at line 1, column 1 + | +1 | + | ^ +missing field `bar` + +"#]], str![[r#" - missing field `bar` - "#]] +missing field `bar` + +"#]] } } @@ -420,13 +426,18 @@ fn parse_tuple_variant() { ], }; let raw = toml::to_string(&input).unwrap(); - assert_data_eq!(raw, str![[r#" - [[inner]] - Int = [1, 1] + assert_data_eq!( + raw, + str![[r#" +[[inner]] +Int = [1, 1] - [[inner]] - String = ["2", "2"] - "#]].raw()); +[[inner]] +String = ["2", "2"] + +"#]] + .raw() + ); equivalent! { Document { @@ -470,19 +481,24 @@ fn parse_struct_variant() { ], }; let raw = toml::to_string(&input).unwrap(); - assert_data_eq!(raw, str![[r#" - [[inner]] + assert_data_eq!( + raw, + str![[r#" +[[inner]] - [inner.Int] - first = 1 - second = 1 +[inner.Int] +first = 1 +second = 1 - [[inner]] +[[inner]] - [inner.String] - first = "2" - second = "2" - "#]].raw()); +[inner.String] +first = "2" +second = "2" + +"#]] + .raw() + ); equivalent! { Document { @@ -918,13 +934,17 @@ debug = 'a' "#, ); let err = res.unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 8, column 9 - | - 8 | debug = 'a' - | ^^^ - expected a boolean or an integer - "#]]); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 8, column 9 + | +8 | debug = 'a' + | ^^^ +expected a boolean or an integer + +"#]] + ); let res: Result = toml::from_str( r#" @@ -938,13 +958,17 @@ dev = { debug = 'a' } "#, ); let err = res.unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 8, column 17 - | - 8 | dev = { debug = 'a' } - | ^^^ - expected a boolean or an integer - "#]]); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 8, column 17 + | +8 | dev = { debug = 'a' } + | ^^^ +expected a boolean or an integer + +"#]] + ); } #[test] @@ -958,9 +982,13 @@ fn newline_key_value() { name: "foo".to_owned(), }; let raw = toml::to_string_pretty(&package).unwrap(); - assert_data_eq!(raw, str![[r#" - name = "foo" - "#]]); + assert_data_eq!( + raw, + str![[r#" +name = "foo" + +"#]] + ); } #[test] @@ -981,10 +1009,14 @@ fn newline_table() { }, }; let raw = toml::to_string_pretty(&package).unwrap(); - assert_data_eq!(raw, str![[r#" - [package] - name = "foo" - "#]]); + assert_data_eq!( + raw, + str![[r#" +[package] +name = "foo" + +"#]] + ); } #[test] @@ -1019,10 +1051,14 @@ fn newline_dotted_table() { }, }; let raw = toml::to_string_pretty(&package).unwrap(); - assert_data_eq!(raw, str![[r#" - [profile.dev] - debug = true - "#]]); + assert_data_eq!( + raw, + str![[r#" +[profile.dev] +debug = true + +"#]] + ); } #[test] @@ -1072,17 +1108,21 @@ fn newline_mixed_tables() { }, }; let raw = toml::to_string_pretty(&package).unwrap(); - assert_data_eq!(raw, str![[r#" - cargo_features = [] + assert_data_eq!( + raw, + str![[r#" +cargo_features = [] - [package] - name = "foo" - version = "1.0.0" - authors = [] +[package] +name = "foo" +version = "1.0.0" +authors = [] - [profile.dev] - debug = true - "#]]); +[profile.dev] +debug = true + +"#]] + ); } #[test] @@ -1109,7 +1149,10 @@ fn integer_too_big() { let err = Table::try_from(native.clone()).unwrap_err(); assert_data_eq!(err.to_string(), str!["u64 value was too large"].raw()); let err = toml::to_string(&native).unwrap_err(); - assert_data_eq!(err.to_string(), str!["out-of-range value for u64 type"].raw()); + assert_data_eq!( + err.to_string(), + str!["out-of-range value for u64 type"].raw() + ); } #[test] @@ -1238,9 +1281,14 @@ fn serialize_array_with_none_value() { values: vec![Some(1), Some(2), Some(3)], }; let raw = toml::to_string(&input).unwrap(); - assert_data_eq!(raw, str![[r#" - values = [1, 2, 3] - "#]].raw()); + assert_data_eq!( + raw, + str![[r#" +values = [1, 2, 3] + +"#]] + .raw() + ); let input = Document { values: vec![Some(1), None, Some(3)], @@ -1270,19 +1318,24 @@ fn serialize_array_with_optional_struct_field() { ], }; let raw = toml::to_string(&input).unwrap(); - assert_data_eq!(raw, str![[r#" - [[values]] - x = 0 - y = 4 + assert_data_eq!( + raw, + str![[r#" +[[values]] +x = 0 +y = 4 + +[[values]] +x = 2 +y = 5 - [[values]] - x = 2 - y = 5 +[[values]] +x = 3 +y = 7 - [[values]] - x = 3 - y = 7 - "#]].raw()); +"#]] + .raw() + ); let input = Document { values: vec![ @@ -1292,18 +1345,23 @@ fn serialize_array_with_optional_struct_field() { ], }; let raw = toml::to_string(&input).unwrap(); - assert_data_eq!(raw, str![[r#" - [[values]] - x = 0 - y = 4 + assert_data_eq!( + raw, + str![[r#" +[[values]] +x = 0 +y = 4 + +[[values]] +x = 2 - [[values]] - x = 2 +[[values]] +x = 3 +y = 7 - [[values]] - x = 3 - y = 7 - "#]].raw()); +"#]] + .raw() + ); } #[test] @@ -1335,8 +1393,9 @@ fn serialize_array_with_enum_of_optional_struct_field() { }; let raw = toml::to_string(&input).unwrap(); assert_data_eq!(raw, str![[r#" - values = [{ Optional = { x = 0, y = 4 } }, "Empty", { Optional = { x = 2, y = 5 } }, { Optional = { x = 3, y = 7 } }] - "#]].raw()); +values = [{ Optional = { x = 0, y = 4 } }, "Empty", { Optional = { x = 2, y = 5 } }, { Optional = { x = 3, y = 7 } }] + +"#]].raw()); let input = Document { values: vec![ @@ -1348,8 +1407,9 @@ fn serialize_array_with_enum_of_optional_struct_field() { }; let raw = toml::to_string(&input).unwrap(); assert_data_eq!(raw, str![[r#" - values = [{ Optional = { x = 0, y = 4 } }, "Empty", { Optional = { x = 2 } }, { Optional = { x = 3, y = 7 } }] - "#]].raw()); +values = [{ Optional = { x = 0, y = 4 } }, "Empty", { Optional = { x = 2 } }, { Optional = { x = 3, y = 7 } }] + +"#]].raw()); } #[test] diff --git a/crates/toml/tests/testsuite/spanned.rs b/crates/toml/tests/testsuite/spanned.rs index 1e04790b..daf7601b 100644 --- a/crates/toml/tests/testsuite/spanned.rs +++ b/crates/toml/tests/testsuite/spanned.rs @@ -251,11 +251,16 @@ fn deny_unknown_fields() { fake = 1"#, ) .unwrap_err(); - assert_data_eq!(error.to_string(), str![[r#" - TOML parse error at line 3, column 1 - | - 3 | fake = 1 - | ^^^^ - unknown field `fake`, expected `real` - "#]].raw()); + assert_data_eq!( + error.to_string(), + str![[r#" +TOML parse error at line 3, column 1 + | +3 | fake = 1 + | ^^^^ +unknown field `fake`, expected `real` + +"#]] + .raw() + ); } diff --git a/crates/toml_edit/Cargo.toml b/crates/toml_edit/Cargo.toml index 404d5fb8..34f60d51 100644 --- a/crates/toml_edit/Cargo.toml +++ b/crates/toml_edit/Cargo.toml @@ -52,7 +52,7 @@ serde_json = "1.0.116" toml-test-harness = "0.4.8" toml-test-data = "1.11.0" libtest-mimic = "0.7.2" -snapbox = "0.5.14" +snapbox = "0.6.0" [[test]] name = "testsuite" diff --git a/crates/toml_edit/tests/testsuite/convert.rs b/crates/toml_edit/tests/testsuite/convert.rs index 20c8c8a2..4e542a21 100644 --- a/crates/toml_edit/tests/testsuite/convert.rs +++ b/crates/toml_edit/tests/testsuite/convert.rs @@ -22,8 +22,9 @@ other = "world" let actual = doc.to_string(); // `table=` is because we didn't re-format the table key, only the value assert_data_eq!(actual, str![[r#" - table= { string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } } - "#]].raw()); +table= { string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } } + +"#]].raw()); } #[test] @@ -41,13 +42,18 @@ fn inline_table_to_table() { doc.insert("table", Item::Table(t)); let actual = doc.to_string(); - assert_data_eq!(actual, str![[r#" - [table] - string = "value" - array = [1, 2, 3] - inline = { "1" = 1, "2" = 2 } - child = { other = "world" } - "#]].raw()); + assert_data_eq!( + actual, + str![[r#" +[table] +string = "value" +array = [1, 2, 3] +inline = { "1" = 1, "2" = 2 } +child = { other = "world" } + +"#]] + .raw() + ); } #[test] @@ -76,6 +82,7 @@ other = "world" let actual = doc.to_string(); // `table=` is because we didn't re-format the table key, only the value assert_data_eq!(actual, str![[r#" - table= [{ string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } }, { string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } }] - "#]].raw()); +table= [{ string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } }, { string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } }] + +"#]].raw()); } diff --git a/crates/toml_edit/tests/testsuite/datetime.rs b/crates/toml_edit/tests/testsuite/datetime.rs index 2f7f9462..dba89ec5 100644 --- a/crates/toml_edit/tests/testsuite/datetime.rs +++ b/crates/toml_edit/tests/testsuite/datetime.rs @@ -45,166 +45,254 @@ fn times() { #[test] fn bad_times() { - bad!("foo = 199-09-09", str![[r#" - TOML parse error at line 1, column 10 - | - 1 | foo = 199-09-09 - | ^ - expected newline, `#` - "#]]); - bad!("foo = 199709-09", str![[r#" - TOML parse error at line 1, column 13 - | - 1 | foo = 199709-09 - | ^ - expected newline, `#` - "#]]); - bad!("foo = 1997-9-09", str![[r#" - TOML parse error at line 1, column 12 - | - 1 | foo = 1997-9-09 - | ^ - invalid date-time - "#]]); - bad!("foo = 1997-09-9", str![[r#" - TOML parse error at line 1, column 15 - | - 1 | foo = 1997-09-9 - | ^ - invalid date-time - "#]]); - bad!("foo = 1997-09-0909:09:09", str![[r#" - TOML parse error at line 1, column 17 - | - 1 | foo = 1997-09-0909:09:09 - | ^ - expected newline, `#` - "#]]); - bad!("foo = 1997-09-09T09:09:09.", str![[r#" - TOML parse error at line 1, column 26 - | - 1 | foo = 1997-09-09T09:09:09. - | ^ - expected newline, `#` - "#]]); - bad!("foo = T", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | foo = T - | ^ - invalid string - expected `"`, `'` - "#]]); - bad!("foo = T.", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | foo = T. - | ^ - invalid string - expected `"`, `'` - "#]]); - bad!("foo = TZ", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | foo = TZ - | ^ - invalid string - expected `"`, `'` - "#]]); - bad!("foo = 1997-09-09T09:09:09.09+", str![[r#" - TOML parse error at line 1, column 30 - | - 1 | foo = 1997-09-09T09:09:09.09+ - | ^ - invalid time offset - "#]]); - bad!("foo = 1997-09-09T09:09:09.09+09", str![[r#" - TOML parse error at line 1, column 32 - | - 1 | foo = 1997-09-09T09:09:09.09+09 - | ^ - invalid time offset - "#]]); - bad!("foo = 1997-09-09T09:09:09.09+09:9", str![[r#" - TOML parse error at line 1, column 33 - | - 1 | foo = 1997-09-09T09:09:09.09+09:9 - | ^ - invalid time offset - "#]]); - bad!("foo = 1997-09-09T09:09:09.09+0909", str![[r#" - TOML parse error at line 1, column 32 - | - 1 | foo = 1997-09-09T09:09:09.09+0909 - | ^ - invalid time offset - "#]]); - bad!("foo = 1997-09-09T09:09:09.09-", str![[r#" - TOML parse error at line 1, column 30 - | - 1 | foo = 1997-09-09T09:09:09.09- - | ^ - invalid time offset - "#]]); - bad!("foo = 1997-09-09T09:09:09.09-09", str![[r#" - TOML parse error at line 1, column 32 - | - 1 | foo = 1997-09-09T09:09:09.09-09 - | ^ - invalid time offset - "#]]); - bad!("foo = 1997-09-09T09:09:09.09-09:9", str![[r#" - TOML parse error at line 1, column 33 - | - 1 | foo = 1997-09-09T09:09:09.09-09:9 - | ^ - invalid time offset - "#]]); - bad!("foo = 1997-09-09T09:09:09.09-0909", str![[r#" - TOML parse error at line 1, column 32 - | - 1 | foo = 1997-09-09T09:09:09.09-0909 - | ^ - invalid time offset - "#]]); - - bad!("foo = 1997-00-09T09:09:09.09Z", str![[r#" - TOML parse error at line 1, column 12 - | - 1 | foo = 1997-00-09T09:09:09.09Z - | ^ - invalid date-time - value is out of range - "#]]); - bad!("foo = 1997-09-00T09:09:09.09Z", str![[r#" - TOML parse error at line 1, column 15 - | - 1 | foo = 1997-09-00T09:09:09.09Z - | ^ - invalid date-time - value is out of range - "#]]); - bad!("foo = 1997-09-09T30:09:09.09Z", str![[r#" - TOML parse error at line 1, column 17 - | - 1 | foo = 1997-09-09T30:09:09.09Z - | ^ - expected newline, `#` - "#]]); - bad!("foo = 1997-09-09T12:69:09.09Z", str![[r#" - TOML parse error at line 1, column 21 - | - 1 | foo = 1997-09-09T12:69:09.09Z - | ^ - invalid date-time - value is out of range - "#]]); - bad!("foo = 1997-09-09T12:09:69.09Z", str![[r#" - TOML parse error at line 1, column 24 - | - 1 | foo = 1997-09-09T12:09:69.09Z - | ^ - invalid date-time - value is out of range - "#]]); + bad!( + "foo = 199-09-09", + str![[r#" +TOML parse error at line 1, column 10 + | +1 | foo = 199-09-09 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "foo = 199709-09", + str![[r#" +TOML parse error at line 1, column 13 + | +1 | foo = 199709-09 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "foo = 1997-9-09", + str![[r#" +TOML parse error at line 1, column 12 + | +1 | foo = 1997-9-09 + | ^ +invalid date-time + +"#]] + ); + bad!( + "foo = 1997-09-9", + str![[r#" +TOML parse error at line 1, column 15 + | +1 | foo = 1997-09-9 + | ^ +invalid date-time + +"#]] + ); + bad!( + "foo = 1997-09-0909:09:09", + str![[r#" +TOML parse error at line 1, column 17 + | +1 | foo = 1997-09-0909:09:09 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "foo = 1997-09-09T09:09:09.", + str![[r#" +TOML parse error at line 1, column 26 + | +1 | foo = 1997-09-09T09:09:09. + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "foo = T", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | foo = T + | ^ +invalid string +expected `"`, `'` + +"#]] + ); + bad!( + "foo = T.", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | foo = T. + | ^ +invalid string +expected `"`, `'` + +"#]] + ); + bad!( + "foo = TZ", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | foo = TZ + | ^ +invalid string +expected `"`, `'` + +"#]] + ); + bad!( + "foo = 1997-09-09T09:09:09.09+", + str![[r#" +TOML parse error at line 1, column 30 + | +1 | foo = 1997-09-09T09:09:09.09+ + | ^ +invalid time offset + +"#]] + ); + bad!( + "foo = 1997-09-09T09:09:09.09+09", + str![[r#" +TOML parse error at line 1, column 32 + | +1 | foo = 1997-09-09T09:09:09.09+09 + | ^ +invalid time offset + +"#]] + ); + bad!( + "foo = 1997-09-09T09:09:09.09+09:9", + str![[r#" +TOML parse error at line 1, column 33 + | +1 | foo = 1997-09-09T09:09:09.09+09:9 + | ^ +invalid time offset + +"#]] + ); + bad!( + "foo = 1997-09-09T09:09:09.09+0909", + str![[r#" +TOML parse error at line 1, column 32 + | +1 | foo = 1997-09-09T09:09:09.09+0909 + | ^ +invalid time offset + +"#]] + ); + bad!( + "foo = 1997-09-09T09:09:09.09-", + str![[r#" +TOML parse error at line 1, column 30 + | +1 | foo = 1997-09-09T09:09:09.09- + | ^ +invalid time offset + +"#]] + ); + bad!( + "foo = 1997-09-09T09:09:09.09-09", + str![[r#" +TOML parse error at line 1, column 32 + | +1 | foo = 1997-09-09T09:09:09.09-09 + | ^ +invalid time offset + +"#]] + ); + bad!( + "foo = 1997-09-09T09:09:09.09-09:9", + str![[r#" +TOML parse error at line 1, column 33 + | +1 | foo = 1997-09-09T09:09:09.09-09:9 + | ^ +invalid time offset + +"#]] + ); + bad!( + "foo = 1997-09-09T09:09:09.09-0909", + str![[r#" +TOML parse error at line 1, column 32 + | +1 | foo = 1997-09-09T09:09:09.09-0909 + | ^ +invalid time offset + +"#]] + ); + + bad!( + "foo = 1997-00-09T09:09:09.09Z", + str![[r#" +TOML parse error at line 1, column 12 + | +1 | foo = 1997-00-09T09:09:09.09Z + | ^ +invalid date-time +value is out of range + +"#]] + ); + bad!( + "foo = 1997-09-00T09:09:09.09Z", + str![[r#" +TOML parse error at line 1, column 15 + | +1 | foo = 1997-09-00T09:09:09.09Z + | ^ +invalid date-time +value is out of range + +"#]] + ); + bad!( + "foo = 1997-09-09T30:09:09.09Z", + str![[r#" +TOML parse error at line 1, column 17 + | +1 | foo = 1997-09-09T30:09:09.09Z + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "foo = 1997-09-09T12:69:09.09Z", + str![[r#" +TOML parse error at line 1, column 21 + | +1 | foo = 1997-09-09T12:69:09.09Z + | ^ +invalid date-time +value is out of range + +"#]] + ); + bad!( + "foo = 1997-09-09T12:09:69.09Z", + str![[r#" +TOML parse error at line 1, column 24 + | +1 | foo = 1997-09-09T12:09:69.09Z + | ^ +invalid date-time +value is out of range + +"#]] + ); } diff --git a/crates/toml_edit/tests/testsuite/edit.rs b/crates/toml_edit/tests/testsuite/edit.rs index 109b660f..f31119af 100644 --- a/crates/toml_edit/tests/testsuite/edit.rs +++ b/crates/toml_edit/tests/testsuite/edit.rs @@ -44,7 +44,7 @@ impl Test { #[track_caller] fn produces_display(&self, expected: snapbox::data::Inline) -> &Self { - assert_data_eq!(self.doc.to_string(), expected.indent(false).raw()); + assert_data_eq!(self.doc.to_string(), expected.raw()); self } } @@ -79,6 +79,7 @@ ip = "10.0.0.2" dc = "eqdc10" [other.table] + "#]]); } @@ -104,6 +105,7 @@ fn test_inserted_leaf_table_goes_after_last_sibling() { [dependencies.newthing] [dev-dependencies] + "#]]); } @@ -117,6 +119,7 @@ fn test_inserting_tables_from_different_parsed_docs() { .produces_display(str![[r#" [a] [b] + "#]]); } #[test] @@ -140,6 +143,7 @@ fn test_insert_nonleaf_table() { [servers.alpha] ip = "10.0.0.1" dc = "eqdc10" + "#]]); } @@ -170,6 +174,7 @@ fn test_insert_array() { hello = "world" [[bin]] + "#]]); } @@ -191,6 +196,7 @@ key2 = 42 key3 = 8.1415926 [tbl.son] + "#]]); } @@ -223,6 +229,7 @@ fn test_remove_leaf_table() { [servers.beta] ip = "10.0.0.2" dc = "eqdc10" + "#]]); } @@ -319,6 +326,7 @@ fn test_remove_array_entry() { [dependencies] nom = "4.0" # future is here + "#]]); } @@ -352,6 +360,7 @@ fn test_remove_array() { [dependencies] nom = "4.0" # future is here + "#]]); } @@ -378,6 +387,7 @@ fn test_remove_value() { name = "hello" documentation = "https://docs.rs/hello" + "#]]); } @@ -435,6 +445,7 @@ fn test_sort_values() { c = 3 [a.y] + "#]]); } @@ -470,6 +481,7 @@ fn test_sort_values_by() { b = 2 # as well as this [a.y] + "#]]); } @@ -498,6 +510,7 @@ fn test_set_position() { [package] [dev-dependencies] [dependencies.opencl] + "#]]); } @@ -523,6 +536,7 @@ fn test_multiple_zero_positions() { [dev-dependencies] [dependencies.opencl] a="" + "#]]); } @@ -548,6 +562,7 @@ fn test_multiple_max_usize_positions() { [package] [dependencies] [dev-dependencies] + "#]]); } @@ -605,6 +620,7 @@ fn test_insert_replace_into_array() { b = ["hello", "beep", "zoink" , "world" , "yikes"] + "#]]); } @@ -633,6 +649,7 @@ fn test_remove_from_array() { a = [1, 2, 3] b = [] + "#]]); } @@ -697,6 +714,7 @@ fn test_insert_into_inline_table() { a = { a = 2, c = 3, b = 42 } b = { hello = "world" } + "#]]); } @@ -725,6 +743,7 @@ fn test_remove_from_inline_table() { a = {a=2, b = 42} b = {} + "#]]); } @@ -802,6 +821,7 @@ fn test_insert_dotted_into_std_table() { .produces_display(str![[r#" [nixpkgs] src.git = "https://github.com/nixos/nixpkgs" + "#]]); } @@ -820,6 +840,7 @@ fn test_insert_dotted_into_implicit_table() { .produces_display(str![[r#" [nixpkgs] src.git = "https://github.com/nixos/nixpkgs" + "#]]); } diff --git a/crates/toml_edit/tests/testsuite/invalid.rs b/crates/toml_edit/tests/testsuite/invalid.rs index 2e41532f..b685ff9a 100644 --- a/crates/toml_edit/tests/testsuite/invalid.rs +++ b/crates/toml_edit/tests/testsuite/invalid.rs @@ -5,40 +5,55 @@ use snapbox::str; #[test] fn incomplete_inline_table_issue_296() { let err = "native = {".parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 11 - | - 1 | native = { - | ^ - invalid inline table - expected `}` - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 11 + | +1 | native = { + | ^ +invalid inline table +expected `}` + +"#]] + .raw() + ); } #[test] fn bare_value_disallowed_issue_293() { let err = "value=zzz".parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 7 - | - 1 | value=zzz - | ^ - invalid string - expected `"`, `'` - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 7 + | +1 | value=zzz + | ^ +invalid string +expected `"`, `'` + +"#]] + .raw() + ); } #[test] fn bare_value_in_array_disallowed_issue_293() { let err = "value=[zzz]".parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 8 - | - 1 | value=[zzz] - | ^ - invalid array - expected `]` - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 8 + | +1 | value=[zzz] + | ^ +invalid array +expected `]` + +"#]] + .raw() + ); } #[test] @@ -55,143 +70,208 @@ rand = \"0.3.14\" " .parse::() .unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 8, column 1 - | - 8 | [dependencies] - | ^ - invalid table header - duplicate key `dependencies` in document root - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 8, column 1 + | +8 | [dependencies] + | ^ +invalid table header +duplicate key `dependencies` in document root + +"#]] + .raw() + ); } #[test] fn bad() { let toml_input = "a = 01"; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = 01 - | ^ - expected newline, `#` - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = 01 + | ^ +expected newline, `#` + +"#]] + .raw() + ); let toml_input = "a = 1__1"; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = 1__1 - | ^ - invalid integer - expected digit - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = 1__1 + | ^ +invalid integer +expected digit + +"#]] + .raw() + ); let toml_input = "a = 1_"; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = 1_ - | ^ - invalid integer - expected digit - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = 1_ + | ^ +invalid integer +expected digit + +"#]] + .raw() + ); let toml_input = "''"; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 3 - | - 1 | '' - | ^ - expected `.`, `=` - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 3 + | +1 | '' + | ^ +expected `.`, `=` + +"#]] + .raw() + ); let toml_input = "a = 9e99999"; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 5 - | - 1 | a = 9e99999 - | ^ - invalid floating-point number - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 5 + | +1 | a = 9e99999 + | ^ +invalid floating-point number + +"#]] + .raw() + ); let toml_input = "a = \"\u{7f}\""; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = "" - | ^ - invalid basic string - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = "" + | ^ +invalid basic string + +"#]] + .raw() + ); let toml_input = "a = '\u{7f}'"; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = '' - | ^ - invalid literal string - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = '' + | ^ +invalid literal string + +"#]] + .raw() + ); let toml_input = "a = -0x1"; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = -0x1 - | ^ - expected newline, `#` - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = -0x1 + | ^ +expected newline, `#` + +"#]] + .raw() + ); let toml_input = "a = 0x-1"; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = 0x-1 - | ^ - invalid hexadecimal integer - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = 0x-1 + | ^ +invalid hexadecimal integer + +"#]] + .raw() + ); // Dotted keys. let toml_input = "a.b.c = 1 a.b = 2 "; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 2, column 10 - | - 2 | a.b = 2 - | ^ - duplicate key `b` in document root - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 2, column 10 + | +2 | a.b = 2 + | ^ +duplicate key `b` in document root + +"#]] + .raw() + ); let toml_input = "a = 1 a.b = 2"; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 2, column 10 - | - 2 | a.b = 2 - | ^ - dotted key `a` attempted to extend non-table type (integer) - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 2, column 10 + | +2 | a.b = 2 + | ^ +dotted key `a` attempted to extend non-table type (integer) + +"#]] + .raw() + ); let toml_input = "a = {k1 = 1, k1.name = \"joe\"}"; let err = toml_input.parse::().unwrap_err(); - assert_data_eq!(err.to_string(), str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = {k1 = 1, k1.name = "joe"} - | ^ - dotted key `k1` attempted to extend non-table type (integer) - "#]].raw()); + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = {k1 = 1, k1.name = "joe"} + | ^ +dotted key `k1` attempted to extend non-table type (integer) + +"#]] + .raw() + ); } #[test] diff --git a/crates/toml_edit/tests/testsuite/parse.rs b/crates/toml_edit/tests/testsuite/parse.rs index 0c9e39cf..3cee2e22 100644 --- a/crates/toml_edit/tests/testsuite/parse.rs +++ b/crates/toml_edit/tests/testsuite/parse.rs @@ -85,11 +85,12 @@ fn test_key_unification() { "#; let expected = str![[r#" - [a] - [a.'b'.c] - [a.'b'.c.e] - [a.'b'.c.d] - "#]]; +[a] +[a.'b'.c] +[a.'b'.c.e] +[a.'b'.c.d] + +"#]]; let doc = toml.parse::(); assert!(doc.is_ok()); let doc = doc.unwrap(); @@ -294,63 +295,91 @@ name = "plantain" #[test] fn stray_cr() { - bad!("\r", str![[r#" - TOML parse error at line 1, column 1 - | - 1 | - | ^ - - "#]]); - bad!("a = [ \r ]", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = [ - ] - | ^ - invalid array - expected `]` - "#]]); - bad!("a = \"\"\"\r\"\"\"", str![[r#" - TOML parse error at line 1, column 8 - | - 1 | a = """ - """ - | ^ - invalid multiline basic string - "#]]); - bad!("a = \"\"\"\\ \r \"\"\"", str![[r#" - TOML parse error at line 1, column 10 - | - 1 | a = """\ - """ - | ^ - invalid escape sequence - expected `b`, `f`, `n`, `r`, `t`, `u`, `U`, `\`, `"` - "#]]); - bad!("a = '''\r'''", str![[r#" - TOML parse error at line 1, column 8 - | - 1 | a = ''' - ''' - | ^ - invalid multiline literal string - "#]]); - bad!("a = '\r'", str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = ' - ' - | ^ - invalid literal string - "#]]); - bad!("a = \"\r\"", str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = " - " - | ^ - invalid basic string - "#]]); + bad!( + "\r", + str![[r#" +TOML parse error at line 1, column 1 + | +1 | + | ^ + + +"#]] + ); + bad!( + "a = [ \r ]", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = [ + ] + | ^ +invalid array +expected `]` + +"#]] + ); + bad!( + "a = \"\"\"\r\"\"\"", + str![[r#" +TOML parse error at line 1, column 8 + | +1 | a = """ +""" + | ^ +invalid multiline basic string + +"#]] + ); + bad!( + "a = \"\"\"\\ \r \"\"\"", + str![[r#" +TOML parse error at line 1, column 10 + | +1 | a = """\ + """ + | ^ +invalid escape sequence +expected `b`, `f`, `n`, `r`, `t`, `u`, `U`, `\`, `"` + +"#]] + ); + bad!( + "a = '''\r'''", + str![[r#" +TOML parse error at line 1, column 8 + | +1 | a = ''' +''' + | ^ +invalid multiline literal string + +"#]] + ); + bad!( + "a = '\r'", + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = ' +' + | ^ +invalid literal string + +"#]] + ); + bad!( + "a = \"\r\"", + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = " +" + | ^ +invalid basic string + +"#]] + ); } #[test] @@ -379,136 +408,204 @@ fn literal_eats_crlf() { #[test] fn string_no_newline() { - bad!("a = \"\n\"", str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = " - | ^ - invalid basic string - "#]]); - bad!("a = '\n'", str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = ' - | ^ - invalid literal string - "#]]); + bad!( + "a = \"\n\"", + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = " + | ^ +invalid basic string + +"#]] + ); + bad!( + "a = '\n'", + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = ' + | ^ +invalid literal string + +"#]] + ); } #[test] fn bad_leading_zeros() { - bad!("a = 00", str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = 00 - | ^ - expected newline, `#` - "#]]); - bad!("a = -00", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = -00 - | ^ - expected newline, `#` - "#]]); - bad!("a = +00", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = +00 - | ^ - expected newline, `#` - "#]]); - bad!("a = 00.0", str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = 00.0 - | ^ - expected newline, `#` - "#]]); - bad!("a = -00.0", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = -00.0 - | ^ - expected newline, `#` - "#]]); - bad!("a = +00.0", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = +00.0 - | ^ - expected newline, `#` - "#]]); - bad!("a = 9223372036854775808", str![[r#" - TOML parse error at line 1, column 5 - | - 1 | a = 9223372036854775808 - | ^ - number too large to fit in target type - "#]]); - bad!("a = -9223372036854775809", str![[r#" - TOML parse error at line 1, column 5 - | - 1 | a = -9223372036854775809 - | ^ - number too small to fit in target type - "#]]); + bad!( + "a = 00", + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = 00 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "a = -00", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = -00 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "a = +00", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = +00 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "a = 00.0", + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = 00.0 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "a = -00.0", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = -00.0 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "a = +00.0", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = +00.0 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "a = 9223372036854775808", + str![[r#" +TOML parse error at line 1, column 5 + | +1 | a = 9223372036854775808 + | ^ +number too large to fit in target type + +"#]] + ); + bad!( + "a = -9223372036854775809", + str![[r#" +TOML parse error at line 1, column 5 + | +1 | a = -9223372036854775809 + | ^ +number too small to fit in target type + +"#]] + ); } #[test] fn bad_floats() { - bad!("a = 0.", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = 0. - | ^ - invalid floating-point number - expected digit - "#]]); - bad!("a = 0.e", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = 0.e - | ^ - invalid floating-point number - expected digit - "#]]); - bad!("a = 0.E", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | a = 0.E - | ^ - invalid floating-point number - expected digit - "#]]); - bad!("a = 0.0E", str![[r#" - TOML parse error at line 1, column 9 - | - 1 | a = 0.0E - | ^ - invalid floating-point number - "#]]); - bad!("a = 0.0e", str![[r#" - TOML parse error at line 1, column 9 - | - 1 | a = 0.0e - | ^ - invalid floating-point number - "#]]); - bad!("a = 0.0e-", str![[r#" - TOML parse error at line 1, column 10 - | - 1 | a = 0.0e- - | ^ - invalid floating-point number - "#]]); - bad!("a = 0.0e+", str![[r#" - TOML parse error at line 1, column 10 - | - 1 | a = 0.0e+ - | ^ - invalid floating-point number - "#]]); + bad!( + "a = 0.", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = 0. + | ^ +invalid floating-point number +expected digit + +"#]] + ); + bad!( + "a = 0.e", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = 0.e + | ^ +invalid floating-point number +expected digit + +"#]] + ); + bad!( + "a = 0.E", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | a = 0.E + | ^ +invalid floating-point number +expected digit + +"#]] + ); + bad!( + "a = 0.0E", + str![[r#" +TOML parse error at line 1, column 9 + | +1 | a = 0.0E + | ^ +invalid floating-point number + +"#]] + ); + bad!( + "a = 0.0e", + str![[r#" +TOML parse error at line 1, column 9 + | +1 | a = 0.0e + | ^ +invalid floating-point number + +"#]] + ); + bad!( + "a = 0.0e-", + str![[r#" +TOML parse error at line 1, column 10 + | +1 | a = 0.0e- + | ^ +invalid floating-point number + +"#]] + ); + bad!( + "a = 0.0e+", + str![[r#" +TOML parse error at line 1, column 10 + | +1 | a = 0.0e+ + | ^ +invalid floating-point number + +"#]] + ); } #[test] @@ -569,186 +666,282 @@ fn bare_key_names() { #[test] fn bad_keys() { - bad!("key\n=3", str![[r#" - TOML parse error at line 1, column 4 - | - 1 | key - | ^ - expected `.`, `=` - "#]]); - bad!("key=\n3", str![[r#" - TOML parse error at line 1, column 5 - | - 1 | key= - | ^ - invalid string - expected `"`, `'` - "#]]); - bad!("key|=3", str![[r#" - TOML parse error at line 1, column 4 - | - 1 | key|=3 - | ^ - expected `.`, `=` - "#]]); - bad!("=3", str![[r#" - TOML parse error at line 1, column 1 - | - 1 | =3 - | ^ - invalid key - "#]]); - bad!("\"\"|=3", str![[r#" - TOML parse error at line 1, column 3 - | - 1 | ""|=3 - | ^ - expected `.`, `=` - "#]]); - bad!("\"\n\"|=3", str![[r#" - TOML parse error at line 1, column 2 - | - 1 | " - | ^ - invalid basic string - "#]]); - bad!("\"\r\"|=3", str![[r#" - TOML parse error at line 1, column 2 - | - 1 | " - "|=3 - | ^ - invalid basic string - "#]]); - bad!("''''''=3", str![[r#" - TOML parse error at line 1, column 3 - | - 1 | ''''''=3 - | ^ - expected `.`, `=` - "#]]); - bad!("\"\"\"\"\"\"=3", str![[r#" - TOML parse error at line 1, column 3 - | - 1 | """"""=3 - | ^ - expected `.`, `=` - "#]]); - bad!("'''key'''=3", str![[r#" - TOML parse error at line 1, column 3 - | - 1 | '''key'''=3 - | ^ - expected `.`, `=` - "#]]); - bad!("\"\"\"key\"\"\"=3", str![[r#" - TOML parse error at line 1, column 3 - | - 1 | """key"""=3 - | ^ - expected `.`, `=` - "#]]); + bad!( + "key\n=3", + str![[r#" +TOML parse error at line 1, column 4 + | +1 | key + | ^ +expected `.`, `=` + +"#]] + ); + bad!( + "key=\n3", + str![[r#" +TOML parse error at line 1, column 5 + | +1 | key= + | ^ +invalid string +expected `"`, `'` + +"#]] + ); + bad!( + "key|=3", + str![[r#" +TOML parse error at line 1, column 4 + | +1 | key|=3 + | ^ +expected `.`, `=` + +"#]] + ); + bad!( + "=3", + str![[r#" +TOML parse error at line 1, column 1 + | +1 | =3 + | ^ +invalid key + +"#]] + ); + bad!( + "\"\"|=3", + str![[r#" +TOML parse error at line 1, column 3 + | +1 | ""|=3 + | ^ +expected `.`, `=` + +"#]] + ); + bad!( + "\"\n\"|=3", + str![[r#" +TOML parse error at line 1, column 2 + | +1 | " + | ^ +invalid basic string + +"#]] + ); + bad!( + "\"\r\"|=3", + str![[r#" +TOML parse error at line 1, column 2 + | +1 | " +"|=3 + | ^ +invalid basic string + +"#]] + ); + bad!( + "''''''=3", + str![[r#" +TOML parse error at line 1, column 3 + | +1 | ''''''=3 + | ^ +expected `.`, `=` + +"#]] + ); + bad!( + "\"\"\"\"\"\"=3", + str![[r#" +TOML parse error at line 1, column 3 + | +1 | """"""=3 + | ^ +expected `.`, `=` + +"#]] + ); + bad!( + "'''key'''=3", + str![[r#" +TOML parse error at line 1, column 3 + | +1 | '''key'''=3 + | ^ +expected `.`, `=` + +"#]] + ); + bad!( + "\"\"\"key\"\"\"=3", + str![[r#" +TOML parse error at line 1, column 3 + | +1 | """key"""=3 + | ^ +expected `.`, `=` + +"#]] + ); } #[test] fn bad_table_names() { - bad!("[]", str![[r#" - TOML parse error at line 1, column 2 - | - 1 | [] - | ^ - invalid key - "#]]); - bad!("[.]", str![[r#" - TOML parse error at line 1, column 2 - | - 1 | [.] - | ^ - invalid key - "#]]); - bad!("[a.]", str![[r#" - TOML parse error at line 1, column 3 - | - 1 | [a.] - | ^ - invalid table header - expected `.`, `]` - "#]]); - bad!("[!]", str![[r#" - TOML parse error at line 1, column 2 - | - 1 | [!] - | ^ - invalid key - "#]]); - bad!("[\"\n\"]", str![[r#" - TOML parse error at line 1, column 3 - | - 1 | [" - | ^ - invalid basic string - "#]]); - bad!("[a.b]\n[a.\"b\"]", str![[r#" - TOML parse error at line 2, column 1 - | - 2 | [a."b"] - | ^ - invalid table header - duplicate key `b` in table `a` - "#]]); - bad!("[']", str![[r#" - TOML parse error at line 1, column 4 - | - 1 | ['] - | ^ - invalid literal string - "#]]); - bad!("[''']", str![[r#" - TOML parse error at line 1, column 4 - | - 1 | ['''] - | ^ - invalid table header - expected `.`, `]` - "#]]); - bad!("['''''']", str![[r#" - TOML parse error at line 1, column 4 - | - 1 | [''''''] - | ^ - invalid table header - expected `.`, `]` - "#]]); - bad!("['''foo''']", str![[r#" - TOML parse error at line 1, column 4 - | - 1 | ['''foo'''] - | ^ - invalid table header - expected `.`, `]` - "#]]); - bad!("[\"\"\"bar\"\"\"]", str![[r#" - TOML parse error at line 1, column 4 - | - 1 | ["""bar"""] - | ^ - invalid table header - expected `.`, `]` - "#]]); - bad!("['\n']", str![[r#" - TOML parse error at line 1, column 3 - | - 1 | [' - | ^ - invalid literal string - "#]]); - bad!("['\r\n']", str![[r#" - TOML parse error at line 1, column 3 - | - 1 | [' - | ^ - invalid literal string - "#]]); + bad!( + "[]", + str![[r#" +TOML parse error at line 1, column 2 + | +1 | [] + | ^ +invalid key + +"#]] + ); + bad!( + "[.]", + str![[r#" +TOML parse error at line 1, column 2 + | +1 | [.] + | ^ +invalid key + +"#]] + ); + bad!( + "[a.]", + str![[r#" +TOML parse error at line 1, column 3 + | +1 | [a.] + | ^ +invalid table header +expected `.`, `]` + +"#]] + ); + bad!( + "[!]", + str![[r#" +TOML parse error at line 1, column 2 + | +1 | [!] + | ^ +invalid key + +"#]] + ); + bad!( + "[\"\n\"]", + str![[r#" +TOML parse error at line 1, column 3 + | +1 | [" + | ^ +invalid basic string + +"#]] + ); + bad!( + "[a.b]\n[a.\"b\"]", + str![[r#" +TOML parse error at line 2, column 1 + | +2 | [a."b"] + | ^ +invalid table header +duplicate key `b` in table `a` + +"#]] + ); + bad!( + "[']", + str![[r#" +TOML parse error at line 1, column 4 + | +1 | ['] + | ^ +invalid literal string + +"#]] + ); + bad!( + "[''']", + str![[r#" +TOML parse error at line 1, column 4 + | +1 | ['''] + | ^ +invalid table header +expected `.`, `]` + +"#]] + ); + bad!( + "['''''']", + str![[r#" +TOML parse error at line 1, column 4 + | +1 | [''''''] + | ^ +invalid table header +expected `.`, `]` + +"#]] + ); + bad!( + "['''foo''']", + str![[r#" +TOML parse error at line 1, column 4 + | +1 | ['''foo'''] + | ^ +invalid table header +expected `.`, `]` + +"#]] + ); + bad!( + "[\"\"\"bar\"\"\"]", + str![[r#" +TOML parse error at line 1, column 4 + | +1 | ["""bar"""] + | ^ +invalid table header +expected `.`, `]` + +"#]] + ); + bad!( + "['\n']", + str![[r#" +TOML parse error at line 1, column 3 + | +1 | [' + | ^ +invalid literal string + +"#]] + ); + bad!( + "['\r\n']", + str![[r#" +TOML parse error at line 1, column 3 + | +1 | [' + | ^ +invalid literal string + +"#]] + ); } #[test] @@ -773,13 +966,17 @@ fn table_names() { #[test] fn invalid_bare_numeral() { - bad!("4", str![[r#" - TOML parse error at line 1, column 2 - | - 1 | 4 - | ^ - expected `.`, `=` - "#]]); + bad!( + "4", + str![[r#" +TOML parse error at line 1, column 2 + | +1 | 4 + | ^ +expected `.`, `=` + +"#]] + ); } #[test] @@ -790,45 +987,65 @@ fn inline_tables() { "a = {a=1,b=2}".parse::().unwrap(); "a = {a=1,b=2,c={}}".parse::().unwrap(); - bad!("a = {a=1,}", str![[r#" - TOML parse error at line 1, column 9 - | - 1 | a = {a=1,} - | ^ - invalid inline table - expected `}` - "#]]); - bad!("a = {,}", str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = {,} - | ^ - invalid inline table - expected `}` - "#]]); - bad!("a = {a=1,a=1}", str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = {a=1,a=1} - | ^ - duplicate key `a` - "#]]); - bad!("a = {\n}", str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = { - | ^ - invalid inline table - expected `}` - "#]]); - bad!("a = {", str![[r#" - TOML parse error at line 1, column 6 - | - 1 | a = { - | ^ - invalid inline table - expected `}` - "#]]); + bad!( + "a = {a=1,}", + str![[r#" +TOML parse error at line 1, column 9 + | +1 | a = {a=1,} + | ^ +invalid inline table +expected `}` + +"#]] + ); + bad!( + "a = {,}", + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = {,} + | ^ +invalid inline table +expected `}` + +"#]] + ); + bad!( + "a = {a=1,a=1}", + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = {a=1,a=1} + | ^ +duplicate key `a` + +"#]] + ); + bad!( + "a = {\n}", + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = { + | ^ +invalid inline table +expected `}` + +"#]] + ); + bad!( + "a = {", + str![[r#" +TOML parse error at line 1, column 6 + | +1 | a = { + | ^ +invalid inline table +expected `}` + +"#]] + ); "a = {a=[\n]}".parse::().unwrap(); "a = {\"a\"=[\n]}".parse::().unwrap(); @@ -854,80 +1071,116 @@ fn number_underscores() { #[test] fn bad_underscores() { - bad!("foo = 0_", str![[r#" - TOML parse error at line 1, column 8 - | - 1 | foo = 0_ - | ^ - expected newline, `#` - "#]]); - bad!("foo = 0__0", str![[r#" - TOML parse error at line 1, column 8 - | - 1 | foo = 0__0 - | ^ - expected newline, `#` - "#]]); - bad!("foo = __0", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | foo = __0 - | ^ - invalid integer - expected leading digit - "#]]); - bad!("foo = 1_0_", str![[r#" - TOML parse error at line 1, column 11 - | - 1 | foo = 1_0_ - | ^ - invalid integer - expected digit - "#]]); + bad!( + "foo = 0_", + str![[r#" +TOML parse error at line 1, column 8 + | +1 | foo = 0_ + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "foo = 0__0", + str![[r#" +TOML parse error at line 1, column 8 + | +1 | foo = 0__0 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "foo = __0", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | foo = __0 + | ^ +invalid integer +expected leading digit + +"#]] + ); + bad!( + "foo = 1_0_", + str![[r#" +TOML parse error at line 1, column 11 + | +1 | foo = 1_0_ + | ^ +invalid integer +expected digit + +"#]] + ); } #[test] fn bad_unicode_codepoint() { - bad!("foo = \"\\uD800\"", str![[r#" - TOML parse error at line 1, column 10 - | - 1 | foo = "\uD800" - | ^ - invalid unicode 4-digit hex code - value is out of range - "#]]); + bad!( + "foo = \"\\uD800\"", + str![[r#" +TOML parse error at line 1, column 10 + | +1 | foo = "\uD800" + | ^ +invalid unicode 4-digit hex code +value is out of range + +"#]] + ); } #[test] fn bad_strings() { - bad!("foo = \"\\uxx\"", str![[r#" - TOML parse error at line 1, column 10 - | - 1 | foo = "\uxx" - | ^ - invalid unicode 4-digit hex code - "#]]); - bad!("foo = \"\\u\"", str![[r#" - TOML parse error at line 1, column 10 - | - 1 | foo = "\u" - | ^ - invalid unicode 4-digit hex code - "#]]); - bad!("foo = \"\\", str![[r#" - TOML parse error at line 1, column 8 - | - 1 | foo = "\ - | ^ - invalid basic string - "#]]); - bad!("foo = '", str![[r#" - TOML parse error at line 1, column 8 - | - 1 | foo = ' - | ^ - invalid literal string - "#]]); + bad!( + "foo = \"\\uxx\"", + str![[r#" +TOML parse error at line 1, column 10 + | +1 | foo = "\uxx" + | ^ +invalid unicode 4-digit hex code + +"#]] + ); + bad!( + "foo = \"\\u\"", + str![[r#" +TOML parse error at line 1, column 10 + | +1 | foo = "\u" + | ^ +invalid unicode 4-digit hex code + +"#]] + ); + bad!( + "foo = \"\\", + str![[r#" +TOML parse error at line 1, column 8 + | +1 | foo = "\ + | ^ +invalid basic string + +"#]] + ); + bad!( + "foo = '", + str![[r#" +TOML parse error at line 1, column 8 + | +1 | foo = ' + | ^ +invalid literal string + +"#]] + ); } #[test] @@ -948,36 +1201,52 @@ fn booleans() { let table = "foo = false".parse::().unwrap(); assert_eq!(table["foo"].as_bool(), Some(false)); - bad!("foo = true2", str![[r#" - TOML parse error at line 1, column 11 - | - 1 | foo = true2 - | ^ - expected newline, `#` - "#]]); - bad!("foo = false2", str![[r#" - TOML parse error at line 1, column 12 - | - 1 | foo = false2 - | ^ - expected newline, `#` - "#]]); - bad!("foo = t1", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | foo = t1 - | ^ - invalid string - expected `"`, `'` - "#]]); - bad!("foo = f2", str![[r#" - TOML parse error at line 1, column 7 - | - 1 | foo = f2 - | ^ - invalid string - expected `"`, `'` - "#]]); + bad!( + "foo = true2", + str![[r#" +TOML parse error at line 1, column 11 + | +1 | foo = true2 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "foo = false2", + str![[r#" +TOML parse error at line 1, column 12 + | +1 | foo = false2 + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "foo = t1", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | foo = t1 + | ^ +invalid string +expected `"`, `'` + +"#]] + ); + bad!( + "foo = f2", + str![[r#" +TOML parse error at line 1, column 7 + | +1 | foo = f2 + | ^ +invalid string +expected `"`, `'` + +"#]] + ); } #[test] @@ -989,13 +1258,14 @@ fn bad_nesting() { b = 5 ", str![[r#" - TOML parse error at line 3, column 9 - | - 3 | [[a]] - | ^ - invalid table header - duplicate key `a` in document root - "#]] +TOML parse error at line 3, column 9 + | +3 | [[a]] + | ^ +invalid table header +duplicate key `a` in document root + +"#]] ); bad!( " @@ -1003,13 +1273,14 @@ fn bad_nesting() { [a.b] ", str![[r#" - TOML parse error at line 3, column 9 - | - 3 | [a.b] - | ^ - invalid table header - dotted key `a` attempted to extend non-table type (integer) - "#]] +TOML parse error at line 3, column 9 + | +3 | [a.b] + | ^ +invalid table header +dotted key `a` attempted to extend non-table type (integer) + +"#]] ); bad!( " @@ -1017,13 +1288,14 @@ fn bad_nesting() { [a.b] ", str![[r#" - TOML parse error at line 3, column 9 - | - 3 | [a.b] - | ^ - invalid table header - dotted key `a` attempted to extend non-table type (array) - "#]] +TOML parse error at line 3, column 9 + | +3 | [a.b] + | ^ +invalid table header +dotted key `a` attempted to extend non-table type (array) + +"#]] ); bad!( " @@ -1031,13 +1303,14 @@ fn bad_nesting() { [[a.b]] ", str![[r#" - TOML parse error at line 3, column 9 - | - 3 | [[a.b]] - | ^ - invalid table header - dotted key `a` attempted to extend non-table type (array) - "#]] +TOML parse error at line 3, column 9 + | +3 | [[a.b]] + | ^ +invalid table header +dotted key `a` attempted to extend non-table type (array) + +"#]] ); bad!( " @@ -1047,13 +1320,14 @@ fn bad_nesting() { c = 2 ", str![[r#" - TOML parse error at line 4, column 9 - | - 4 | [a.b] - | ^ - invalid table header - duplicate key `b` in table `a` - "#]] +TOML parse error at line 4, column 9 + | +4 | [a.b] + | ^ +invalid table header +duplicate key `b` in table `a` + +"#]] ); } @@ -1068,13 +1342,14 @@ fn bad_table_redefine() { [a] ", str![[r#" - TOML parse error at line 6, column 9 - | - 6 | [a] - | ^ - invalid table header - duplicate key `a` in document root - "#]] +TOML parse error at line 6, column 9 + | +6 | [a] + | ^ +invalid table header +duplicate key `a` in document root + +"#]] ); bad!( " @@ -1084,13 +1359,14 @@ fn bad_table_redefine() { [a] ", str![[r#" - TOML parse error at line 5, column 9 - | - 5 | [a] - | ^ - invalid table header - duplicate key `a` in document root - "#]] +TOML parse error at line 5, column 9 + | +5 | [a] + | ^ +invalid table header +duplicate key `a` in document root + +"#]] ); bad!( " @@ -1099,13 +1375,14 @@ fn bad_table_redefine() { [a.b] ", str![[r#" - TOML parse error at line 4, column 9 - | - 4 | [a.b] - | ^ - invalid table header - duplicate key `b` in table `a` - "#]] +TOML parse error at line 4, column 9 + | +4 | [a.b] + | ^ +invalid table header +duplicate key `b` in table `a` + +"#]] ); bad!( @@ -1115,13 +1392,14 @@ fn bad_table_redefine() { [a] ", str![[r#" - TOML parse error at line 4, column 9 - | - 4 | [a] - | ^ - invalid table header - duplicate key `a` in document root - "#]] +TOML parse error at line 4, column 9 + | +4 | [a] + | ^ +invalid table header +duplicate key `a` in document root + +"#]] ); } @@ -1139,63 +1417,88 @@ fn datetimes() { t!("2016-09-09T09:09:09.1Z"); t!("2016-09-09T09:09:09.2+10:00"); t!("2016-09-09T09:09:09.123456789-02:00"); - bad!("foo = 2016-09-09T09:09:09.Z", str![[r#" - TOML parse error at line 1, column 26 - | - 1 | foo = 2016-09-09T09:09:09.Z - | ^ - expected newline, `#` - "#]]); - bad!("foo = 2016-9-09T09:09:09Z", str![[r#" - TOML parse error at line 1, column 12 - | - 1 | foo = 2016-9-09T09:09:09Z - | ^ - invalid date-time - "#]]); - bad!("foo = 2016-09-09T09:09:09+2:00", str![[r#" - TOML parse error at line 1, column 27 - | - 1 | foo = 2016-09-09T09:09:09+2:00 - | ^ - invalid time offset - "#]]); - bad!("foo = 2016-09-09T09:09:09-2:00", str![[r#" - TOML parse error at line 1, column 27 - | - 1 | foo = 2016-09-09T09:09:09-2:00 - | ^ - invalid time offset - "#]]); - bad!("foo = 2016-09-09T09:09:09Z-2:00", str![[r#" - TOML parse error at line 1, column 27 - | - 1 | foo = 2016-09-09T09:09:09Z-2:00 - | ^ - expected newline, `#` - "#]]); + bad!( + "foo = 2016-09-09T09:09:09.Z", + str![[r#" +TOML parse error at line 1, column 26 + | +1 | foo = 2016-09-09T09:09:09.Z + | ^ +expected newline, `#` + +"#]] + ); + bad!( + "foo = 2016-9-09T09:09:09Z", + str![[r#" +TOML parse error at line 1, column 12 + | +1 | foo = 2016-9-09T09:09:09Z + | ^ +invalid date-time + +"#]] + ); + bad!( + "foo = 2016-09-09T09:09:09+2:00", + str![[r#" +TOML parse error at line 1, column 27 + | +1 | foo = 2016-09-09T09:09:09+2:00 + | ^ +invalid time offset + +"#]] + ); + bad!( + "foo = 2016-09-09T09:09:09-2:00", + str![[r#" +TOML parse error at line 1, column 27 + | +1 | foo = 2016-09-09T09:09:09-2:00 + | ^ +invalid time offset + +"#]] + ); + bad!( + "foo = 2016-09-09T09:09:09Z-2:00", + str![[r#" +TOML parse error at line 1, column 27 + | +1 | foo = 2016-09-09T09:09:09Z-2:00 + | ^ +expected newline, `#` + +"#]] + ); } #[test] fn require_newline_after_value() { - bad!("0=0r=false", str![[r#" - TOML parse error at line 1, column 4 - | - 1 | 0=0r=false - | ^ - expected newline, `#` - "#]]); + bad!( + "0=0r=false", + str![[r#" +TOML parse error at line 1, column 4 + | +1 | 0=0r=false + | ^ +expected newline, `#` + +"#]] + ); bad!( r#" 0=""o=""m=""r=""00="0"q="""0"""e="""0""" "#, str![[r#" - TOML parse error at line 2, column 5 - | - 2 | 0=""o=""m=""r=""00="0"q="""0"""e="""0""" - | ^ - expected newline, `#` - "#]] +TOML parse error at line 2, column 5 + | +2 | 0=""o=""m=""r=""00="0"q="""0"""e="""0""" + | ^ +expected newline, `#` + +"#]] ); bad!( r#" @@ -1205,48 +1508,52 @@ fn require_newline_after_value() { 0="0"l="0" "#, str![[r#" - TOML parse error at line 3, column 6 - | - 3 | 0="0"[[0000l0]] - | ^ - expected newline, `#` - "#]] +TOML parse error at line 3, column 6 + | +3 | 0="0"[[0000l0]] + | ^ +expected newline, `#` + +"#]] ); bad!( r#" 0=[0]00=[0,0,0]t=["0","0","0"]s=[1000-00-00T00:00:00Z,2000-00-00T00:00:00Z] "#, str![[r#" - TOML parse error at line 2, column 6 - | - 2 | 0=[0]00=[0,0,0]t=["0","0","0"]s=[1000-00-00T00:00:00Z,2000-00-00T00:00:00Z] - | ^ - expected newline, `#` - "#]] +TOML parse error at line 2, column 6 + | +2 | 0=[0]00=[0,0,0]t=["0","0","0"]s=[1000-00-00T00:00:00Z,2000-00-00T00:00:00Z] + | ^ +expected newline, `#` + +"#]] ); bad!( r#" 0=0r0=0r=false "#, str![[r#" - TOML parse error at line 2, column 4 - | - 2 | 0=0r0=0r=false - | ^ - expected newline, `#` - "#]] +TOML parse error at line 2, column 4 + | +2 | 0=0r0=0r=false + | ^ +expected newline, `#` + +"#]] ); bad!( r#" 0=0r0=0r=falsefal=false "#, str![[r#" - TOML parse error at line 2, column 4 - | - 2 | 0=0r0=0r=falsefal=false - | ^ - expected newline, `#` - "#]] +TOML parse error at line 2, column 4 + | +2 | 0=0r0=0r=falsefal=false + | ^ +expected newline, `#` + +"#]] ); }