diff --git a/Cargo.lock b/Cargo.lock index e042a1e5..411c9084 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -611,14 +611,12 @@ checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" [[package]] name = "snapbox" -version = "0.5.10" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72f1918ec224cc1fd581ff833603f7d203b2cbe36f725e030255f1143a48ba5d" +checksum = "9ad8c7be18cc9ec7f4d7948ad6b9df0e04fc649663e3c0ed59f304ed17ca69e9" dependencies = [ "anstream 0.6.14", "anstyle", - "ignore", - "libtest-mimic", "normalize-line-endings", "similar", "snapbox-macros", diff --git a/crates/toml/Cargo.toml b/crates/toml/Cargo.toml index 7cee5258..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.10" +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 4864a75f..3600f98c 100644 --- a/crates/toml/tests/testsuite/de_errors.rs +++ b/crates/toml/tests/testsuite/de_errors.rs @@ -1,11 +1,15 @@ -use serde::{de, Deserialize}; use std::fmt; +use serde::{de, Deserialize}; +use snapbox::assert_data_eq; +use snapbox::prelude::*; +use snapbox::str; + macro_rules! bad { ($toml:expr, $ty:ty, $msg:expr) => { match toml::from_str::<$ty>($toml) { Ok(s) => panic!("parsed to: {:#?}", s), - Err(e) => snapbox::assert_eq($msg, e.to_string()), + Err(e) => assert_data_eq!(e.to_string(), $msg.raw()), } }; } @@ -83,13 +87,14 @@ 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 -" + +"#]] ); // Missing field in table. @@ -99,13 +104,14 @@ invalid length 0, expected a non-empty string # ^ ", Parent, - "\ + str![[r#" TOML parse error at line 1, column 1 | 1 | | ^ missing field `p_b` -" + +"#]] ); // Invalid type in p_b. @@ -116,13 +122,14 @@ missing field `p_b` # ^ ", Parent, - "\ + str![[r#" 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. @@ -135,13 +142,14 @@ invalid type: integer `1`, expected a sequence ] ", Parent, - "\ + str![[r#" 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. @@ -154,13 +162,14 @@ missing field `c_b` ] ", 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 -" +invalid value: string "*", expected all lowercase or all uppercase + +"#]] ); // Sub-table in Vec is missing a field. @@ -174,13 +183,14 @@ invalid value: string \"*\", expected all lowercase or all uppercase ] ", Parent, - "\ + str![[r#" 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. @@ -195,13 +205,14 @@ missing field `c_b` ] ", Parent, - "\ + str![[r#" 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. @@ -216,13 +227,14 @@ missing field `c_b` ] ", 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 -" + +"#]] ); // Sub-table in the middle of a Vec has an extra field. @@ -238,13 +250,14 @@ invalid type: integer `1`, expected a string ] ", 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` -" + +"#]] ); // Sub-table in the middle of a Vec is missing a field. @@ -267,13 +280,14 @@ unknown field `c_d`, expected `c_a` or `c_b` c_b = 'bbbb' ", Parent, - "\ + str![[r#" 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. @@ -292,13 +306,14 @@ missing field `c_b` c_b = 'bbb' ", Parent, - "\ + str![[r#" TOML parse error at line 8, column 19 | 8 | c_b = '*' | ^^^ -invalid value: string \"*\", expected all lowercase or all uppercase -" +invalid value: string "*", expected all lowercase or all uppercase + +"#]] ); // Sub-table in the middle of a Vec has an extra field. @@ -320,13 +335,14 @@ invalid value: string \"*\", expected all lowercase or all uppercase c_b = 'bbbb' ", 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` -" + +"#]] ); } @@ -338,13 +354,14 @@ fn serde_derive_deserialize_errors() { # ^ ", Parent, - "\ + str![[r#" TOML parse error at line 1, column 1 | 1 | | ^ missing field `p_b` -" + +"#]] ); bad!( @@ -356,13 +373,14 @@ missing field `p_b` ] ", Parent, - "\ + str![[r#" TOML parse error at line 4, column 17 | 4 | {c_a = ''} | ^^^^^^^^^^ missing field `c_b` -" + +"#]] ); bad!( @@ -374,13 +392,14 @@ missing field `c_b` ] ", Parent, - "\ + str![[r#" 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. @@ -393,13 +412,14 @@ invalid type: integer `1`, expected a string ] ", 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` -" + +"#]] ); bad!( @@ -411,13 +431,14 @@ unknown field `c_d`, expected `c_a` or `c_b` ] ", 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 -" + +"#]] ); } @@ -431,13 +452,14 @@ fn error_handles_crlf() { a = 2\r\n\ ", toml::Value, - "\ + str![[r#" TOML parse error at line 5, column 1 | 5 | a = 2 | ^ duplicate key `a` in table `t2` -" + +"#]] ); // Should be the same as above. @@ -449,12 +471,13 @@ duplicate key `a` in table `t2` a = 2\n\ ", toml::Value, - "\ + str![[r#" 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 0c1a33cb..247a2c9e 100644 --- a/crates/toml/tests/testsuite/enum_external_deserialize.rs +++ b/crates/toml/tests/testsuite/enum_external_deserialize.rs @@ -1,4 +1,7 @@ use serde::Deserialize; +use snapbox::assert_data_eq; +use snapbox::prelude::*; +use snapbox::str; #[derive(Debug, Deserialize, PartialEq)] struct OuterStruct { @@ -33,63 +36,81 @@ where #[test] fn invalid_variant_returns_error_with_good_message_string() { let error = value_from_str::("\"NonExistent\"").unwrap_err(); - snapbox::assert_eq( - r#"unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` -"#, + 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(); - snapbox::assert_eq( - r#"TOML parse error at line 1, column 7 + 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` -"#, - error.to_string(), + +"#]] + .raw() ); } #[test] fn invalid_variant_returns_error_with_good_message_inline_table() { let error = value_from_str::("{ NonExistent = {} }").unwrap_err(); - snapbox::assert_eq( - r#"unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` -"#, + 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(); - snapbox::assert_eq( - r#"TOML parse error at line 1, column 9 + 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` -"#, - error.to_string(), + +"#]] + .raw() ); } #[test] fn extra_field_returns_expected_empty_table_error() { let error = value_from_str::("{ Plain = { extra_field = 404 } }").unwrap_err(); - snapbox::assert_eq( - r#"expected empty table -"#, + assert_data_eq!( error.to_string(), + str![[r#" +expected empty table + +"#]] + .raw() ); let error = toml::from_str::("val = { Plain = { extra_field = 404 } }").unwrap_err(); - snapbox::assert_eq( - r#"TOML parse error at line 1, column 17 + 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 -"#, - error.to_string(), + +"#]] + .raw() ); } @@ -97,25 +118,29 @@ expected empty table 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(); - - snapbox::assert_eq( - r#"unexpected keys in table: extra_0, extra_1, available keys: value -"#, + 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(); - - snapbox::assert_eq( - r#"TOML parse error at line 1, column 33 + 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 -"#, - error.to_string(), + +"#]] + .raw() ); } diff --git a/crates/toml/tests/testsuite/pretty.rs b/crates/toml/tests/testsuite/pretty.rs index 11c44236..e8b96269 100644 --- a/crates/toml/tests/testsuite/pretty.rs +++ b/crates/toml/tests/testsuite/pretty.rs @@ -1,5 +1,6 @@ use serde::ser::Serialize; -use snapbox::assert_eq; +use snapbox::assert_data_eq; +use snapbox::prelude::*; const NO_PRETTY: &str = "\ [example] @@ -18,7 +19,7 @@ fn no_pretty() { let value: toml::Value = toml::from_str(toml).unwrap(); let mut result = String::with_capacity(128); value.serialize(toml::Serializer::new(&mut result)).unwrap(); - assert_eq(toml, &result); + assert_data_eq!(&result, toml.raw()); } const PRETTY_STD: &str = "\ @@ -44,7 +45,7 @@ fn pretty_std() { value .serialize(toml::Serializer::pretty(&mut result)) .unwrap(); - assert_eq(toml, &result); + assert_data_eq!(&result, toml.raw()); } const PRETTY_TRICKY: &str = r#"[example] @@ -82,7 +83,7 @@ fn pretty_tricky() { value .serialize(toml::Serializer::pretty(&mut result)) .unwrap(); - assert_eq(toml, &result); + assert_data_eq!(&result, toml.raw()); } const PRETTY_TABLE_ARRAY: &str = r#"[[array]] @@ -106,7 +107,7 @@ fn pretty_table_array() { value .serialize(toml::Serializer::pretty(&mut result)) .unwrap(); - assert_eq(toml, &result); + assert_data_eq!(&result, toml.raw()); } const TABLE_ARRAY: &str = r#"[[array]] @@ -128,7 +129,7 @@ fn table_array() { let value: toml::Value = toml::from_str(toml).unwrap(); let mut result = String::with_capacity(128); value.serialize(toml::Serializer::new(&mut result)).unwrap(); - assert_eq(toml, &result); + assert_data_eq!(&result, toml.raw()); } const PRETTY_EMPTY_TABLE: &str = r#"[example] @@ -140,7 +141,7 @@ fn pretty_empty_table() { let value: toml::Value = toml::from_str(toml).unwrap(); let mut result = String::with_capacity(128); value.serialize(toml::Serializer::new(&mut result)).unwrap(); - assert_eq(toml, &result); + assert_data_eq!(&result, toml.raw()); } #[test] @@ -180,5 +181,5 @@ debug = true let pkg: Package = toml::from_str(raw).unwrap(); let pretty = toml::to_string_pretty(&pkg).unwrap(); - assert_eq(raw, pretty); + assert_data_eq!(pretty, raw.raw()); } diff --git a/crates/toml/tests/testsuite/serde.rs b/crates/toml/tests/testsuite/serde.rs index 52d0113e..c3a10eb7 100644 --- a/crates/toml/tests/testsuite/serde.rs +++ b/crates/toml/tests/testsuite/serde.rs @@ -1,8 +1,11 @@ +use std::collections::BTreeMap; + use serde::Deserialize; use serde::Deserializer; use serde::Serialize; -use std::collections::BTreeMap; - +use snapbox::assert_data_eq; +use snapbox::prelude::*; +use snapbox::str; use toml::map::Map; use toml::Table; use toml::Value; @@ -23,7 +26,10 @@ macro_rules! equivalent { // Through a string equivalent println!("to_string"); - snapbox::assert_eq(t!(toml::to_string(&literal)), t!(toml::to_string(&toml))); + assert_data_eq!( + t!(toml::to_string(&toml)), + t!(toml::to_string(&literal)).raw() + ); println!("literal, from_str(toml)"); assert_eq!(literal, t!(toml::from_str(&t!(toml::to_string(&toml))))); println!("toml, from_str(literal)"); @@ -49,13 +55,13 @@ macro_rules! error { println!("attempting parsing"); match toml::from_str::<$ty>(&$toml.to_string()) { Ok(_) => panic!("successful"), - Err(e) => snapbox::assert_eq($msg_parse, e.to_string()), + Err(e) => assert_data_eq!(e.to_string(), $msg_parse.raw()), } println!("attempting toml decoding"); match $toml.try_into::<$ty>() { Ok(_) => panic!("successful"), - Err(e) => snapbox::assert_eq($msg_decode, e.to_string()), + Err(e) => assert_data_eq!(e.to_string(), $msg_decode.raw()), } }}; } @@ -283,13 +289,19 @@ fn type_errors() { map! { bar: Value::String("a".to_owned()) }, - r#"TOML parse error at line 1, column 7 + str![[r#" +TOML parse error at line 1, column 7 | 1 | bar = "a" | ^^^ invalid type: string "a", expected isize -"#, - "invalid type: string \"a\", expected isize\nin `bar`\n" + +"#]], + str![[r#" +invalid type: string "a", expected isize +in `bar` + +"#]] } error! { @@ -299,13 +311,19 @@ invalid type: string "a", expected isize bar: Value::String("a".to_owned()) } }, - r#"TOML parse error at line 2, column 7 + str![[r#" +TOML parse error at line 2, column 7 | 2 | bar = "a" | ^^^ invalid type: string "a", expected isize -"#, - "invalid type: string \"a\", expected isize\nin `foo.bar`\n" + +"#]], + str![[r#" +invalid type: string "a", expected isize +in `foo.bar` + +"#]] } } @@ -319,13 +337,18 @@ fn missing_errors() { error! { Foo, map! { }, - r#"TOML parse error at line 1, column 1 + str![[r#" +TOML parse error at line 1, column 1 | 1 | | ^ missing field `bar` -"#, - "missing field `bar`\n" + +"#]], + str![[r#" +missing field `bar` + +"#]] } } @@ -402,14 +425,19 @@ fn parse_tuple_variant() { Enum::String("2".to_owned(), "2".to_owned()), ], }; - let expected = "[[inner]] + let raw = toml::to_string(&input).unwrap(); + assert_data_eq!( + raw, + str![[r#" +[[inner]] Int = [1, 1] [[inner]] -String = [\"2\", \"2\"] -"; - let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); +String = ["2", "2"] + +"#]] + .raw() + ); equivalent! { Document { @@ -452,7 +480,11 @@ fn parse_struct_variant() { }, ], }; - let expected = "[[inner]] + let raw = toml::to_string(&input).unwrap(); + assert_data_eq!( + raw, + str![[r#" +[[inner]] [inner.Int] first = 1 @@ -461,11 +493,12 @@ second = 1 [[inner]] [inner.String] -first = \"2\" -second = \"2\" -"; - let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); +first = "2" +second = "2" + +"#]] + .raw() + ); equivalent! { Document { @@ -783,7 +816,7 @@ fn table_structs_empty() { ); expected.insert("foo".to_owned(), CanBeEmpty::default()); assert_eq!(value, expected); - snapbox::assert_eq(text, toml::to_string(&value).unwrap()); + assert_data_eq!(toml::to_string(&value).unwrap(), text.raw()); } #[test] @@ -901,14 +934,16 @@ debug = 'a' "#, ); let err = res.unwrap_err(); - snapbox::assert_eq( - r#"TOML parse error at line 8, column 9 + 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 -"#, - err.to_string(), + +"#]] ); let res: Result = toml::from_str( @@ -923,14 +958,16 @@ dev = { debug = 'a' } "#, ); let err = res.unwrap_err(); - snapbox::assert_eq( - r#"TOML parse error at line 8, column 17 + 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 -"#, - err.to_string(), + +"#]] ); } @@ -945,10 +982,12 @@ fn newline_key_value() { name: "foo".to_owned(), }; let raw = toml::to_string_pretty(&package).unwrap(); - snapbox::assert_eq( - r#"name = "foo" -"#, + assert_data_eq!( raw, + str![[r#" +name = "foo" + +"#]] ); } @@ -970,11 +1009,13 @@ fn newline_table() { }, }; let raw = toml::to_string_pretty(&package).unwrap(); - snapbox::assert_eq( - r#"[package] -name = "foo" -"#, + assert_data_eq!( raw, + str![[r#" +[package] +name = "foo" + +"#]] ); } @@ -1010,11 +1051,13 @@ fn newline_dotted_table() { }, }; let raw = toml::to_string_pretty(&package).unwrap(); - snapbox::assert_eq( - r#"[profile.dev] -debug = true -"#, + assert_data_eq!( raw, + str![[r#" +[profile.dev] +debug = true + +"#]] ); } @@ -1065,8 +1108,10 @@ fn newline_mixed_tables() { }, }; let raw = toml::to_string_pretty(&package).unwrap(); - snapbox::assert_eq( - r#"cargo_features = [] + assert_data_eq!( + raw, + str![[r#" +cargo_features = [] [package] name = "foo" @@ -1075,8 +1120,8 @@ authors = [] [profile.dev] debug = true -"#, - raw, + +"#]] ); } @@ -1102,9 +1147,12 @@ fn integer_too_big() { let native = Foo { a_b: u64::MAX }; let err = Table::try_from(native.clone()).unwrap_err(); - snapbox::assert_eq("u64 value was too large", err.to_string()); + assert_data_eq!(err.to_string(), str!["u64 value was too large"].raw()); let err = toml::to_string(&native).unwrap_err(); - snapbox::assert_eq("out-of-range value for u64 type", err.to_string()); + assert_data_eq!( + err.to_string(), + str!["out-of-range value for u64 type"].raw() + ); } #[test] @@ -1150,7 +1198,7 @@ fn float_max() { fn unsupported_root_type() { let native = "value"; let err = toml::to_string_pretty(&native).unwrap_err(); - snapbox::assert_eq("unsupported rust type", err.to_string()); + assert_data_eq!(err.to_string(), str!["unsupported rust type"].raw()); } #[test] @@ -1162,7 +1210,7 @@ fn unsupported_nested_type() { let native = Foo { unused: () }; let err = toml::to_string_pretty(&native).unwrap_err(); - snapbox::assert_eq("unsupported unit type", err.to_string()); + assert_data_eq!(err.to_string(), str!["unsupported unit type"].raw()); } #[test] @@ -1219,7 +1267,7 @@ fn datetime_offset_issue_496() { let original = "value = 1911-01-01T10:11:12-00:36\n"; let toml = original.parse::().unwrap(); let output = toml.to_string(); - snapbox::assert_eq(original, output); + assert_data_eq!(output, original.raw()); } #[test] @@ -1232,15 +1280,21 @@ fn serialize_array_with_none_value() { let input = Document { values: vec![Some(1), Some(2), Some(3)], }; - let expected = "values = [1, 2, 3]\n"; let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); + assert_data_eq!( + raw, + str![[r#" +values = [1, 2, 3] + +"#]] + .raw() + ); let input = Document { values: vec![Some(1), None, Some(3)], }; let err = toml::to_string(&input).unwrap_err(); - snapbox::assert_eq("unsupported None value", err.to_string()); + assert_data_eq!(err.to_string(), str!["unsupported None value"].raw()); } #[test] @@ -1263,7 +1317,10 @@ fn serialize_array_with_optional_struct_field() { OptionalField { x: 3, y: Some(7) }, ], }; - let expected = "\ + let raw = toml::to_string(&input).unwrap(); + assert_data_eq!( + raw, + str![[r#" [[values]] x = 0 y = 4 @@ -1275,9 +1332,10 @@ y = 5 [[values]] x = 3 y = 7 -"; - let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); + +"#]] + .raw() + ); let input = Document { values: vec![ @@ -1286,7 +1344,10 @@ y = 7 OptionalField { x: 3, y: Some(7) }, ], }; - let expected = "\ + let raw = toml::to_string(&input).unwrap(); + assert_data_eq!( + raw, + str![[r#" [[values]] x = 0 y = 4 @@ -1297,9 +1358,10 @@ x = 2 [[values]] x = 3 y = 7 -"; - let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); + +"#]] + .raw() + ); } #[test] @@ -1329,10 +1391,11 @@ fn serialize_array_with_enum_of_optional_struct_field() { Choice::Optional(OptionalField { x: 3, y: Some(7) }), ], }; - let expected = "values = [{ Optional = { x = 0, y = 4 } }, \"Empty\", { Optional = { x = 2, y = 5 } }, { Optional = { x = 3, y = 7 } }] -"; let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); + assert_data_eq!(raw, str![[r#" +values = [{ Optional = { x = 0, y = 4 } }, "Empty", { Optional = { x = 2, y = 5 } }, { Optional = { x = 3, y = 7 } }] + +"#]].raw()); let input = Document { values: vec![ @@ -1342,10 +1405,11 @@ fn serialize_array_with_enum_of_optional_struct_field() { Choice::Optional(OptionalField { x: 3, y: Some(7) }), ], }; - let expected = "values = [{ Optional = { x = 0, y = 4 } }, \"Empty\", { Optional = { x = 2 } }, { Optional = { x = 3, y = 7 } }] -"; let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); + assert_data_eq!(raw, str![[r#" +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 a6dff1d5..daf7601b 100644 --- a/crates/toml/tests/testsuite/spanned.rs +++ b/crates/toml/tests/testsuite/spanned.rs @@ -5,6 +5,9 @@ use std::collections::HashMap; use std::fmt::Debug; use serde::Deserialize; +use snapbox::assert_data_eq; +use snapbox::prelude::*; +use snapbox::str; use toml::value::Datetime; use toml::Spanned; @@ -248,14 +251,16 @@ fn deny_unknown_fields() { fake = 1"#, ) .unwrap_err(); - snapbox::assert_eq( - "\ + assert_data_eq!( + error.to_string(), + str![[r#" TOML parse error at line 3, column 1 | 3 | fake = 1 | ^^^^ unknown field `fake`, expected `real` -", - error.to_string(), + +"#]] + .raw() ); } diff --git a/crates/toml_edit/Cargo.toml b/crates/toml_edit/Cargo.toml index cad0ad15..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 = { version = "0.5.10", features = ["harness"] } +snapbox = "0.6.0" [[test]] name = "testsuite" diff --git a/crates/toml_edit/src/item.rs b/crates/toml_edit/src/item.rs index cb55625b..601c2358 100644 --- a/crates/toml_edit/src/item.rs +++ b/crates/toml_edit/src/item.rs @@ -364,7 +364,6 @@ impl std::fmt::Display for Item { /// ```rust /// # #[cfg(feature = "display")] { /// # #[cfg(feature = "parse")] { -/// # use snapbox::assert_eq; /// # use toml_edit::*; /// let mut table = Table::default(); /// let mut array = Array::default(); @@ -373,7 +372,7 @@ impl std::fmt::Display for Item { /// table["key1"] = value("value1"); /// table["key2"] = value(42); /// table["key3"] = value(array); -/// assert_eq(table.to_string(), +/// assert_eq!(table.to_string(), /// r#"key1 = "value1" /// key2 = 42 /// key3 = ["hello", '\, world'] diff --git a/crates/toml_edit/src/parser/mod.rs b/crates/toml_edit/src/parser/mod.rs index 47f57532..4c64dfcd 100644 --- a/crates/toml_edit/src/parser/mod.rs +++ b/crates/toml_edit/src/parser/mod.rs @@ -152,6 +152,8 @@ pub(crate) mod prelude { #[cfg(feature = "display")] mod test { use super::*; + use snapbox::assert_data_eq; + use snapbox::prelude::*; #[test] fn documents() { @@ -226,7 +228,7 @@ key = "value" } }; - snapbox::assert_eq(input, doc.to_string()); + assert_data_eq!(doc.to_string(), input.raw()); } } diff --git a/crates/toml_edit/tests/invalid.rs b/crates/toml_edit/tests/invalid.rs index 67cbe287..9bce553d 100644 --- a/crates/toml_edit/tests/invalid.rs +++ b/crates/toml_edit/tests/invalid.rs @@ -11,7 +11,7 @@ fn main() { Ok(()) => "".to_owned(), Err(err) => err, }; - snapbox::assert_eq(snapbox::Data::read_from(&expect_path, None), err); + snapbox::assert_data_eq!(err, snapbox::Data::read_from(&expect_path, None).raw()); Ok(()) }) }) diff --git a/crates/toml_edit/tests/testsuite/convert.rs b/crates/toml_edit/tests/testsuite/convert.rs index ea09c5d7..4e542a21 100644 --- a/crates/toml_edit/tests/testsuite/convert.rs +++ b/crates/toml_edit/tests/testsuite/convert.rs @@ -1,4 +1,6 @@ -use snapbox::assert_eq; +use snapbox::assert_data_eq; +use snapbox::prelude::*; +use snapbox::str; use toml_edit::{DocumentMut, Item, Value}; @@ -19,9 +21,10 @@ other = "world" let actual = doc.to_string(); // `table=` is because we didn't re-format the table key, only the value - let expected = r#"table= { string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } } -"#; - assert_eq(expected, actual); + assert_data_eq!(actual, str![[r#" +table= { string = "value", array = [1, 2, 3], inline = { "1" = 1, "2" = 2 }, child = { other = "world" } } + +"#]].raw()); } #[test] @@ -39,13 +42,18 @@ fn inline_table_to_table() { doc.insert("table", Item::Table(t)); let actual = doc.to_string(); - let expected = r#"[table] + assert_data_eq!( + actual, + str![[r#" +[table] string = "value" array = [1, 2, 3] inline = { "1" = 1, "2" = 2 } child = { other = "world" } -"#; - assert_eq(expected, actual); + +"#]] + .raw() + ); } #[test] @@ -73,7 +81,8 @@ other = "world" let actual = doc.to_string(); // `table=` is because we didn't re-format the table key, only the value - let expected = 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" } }] -"#; - assert_eq(expected, actual); + 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()); } diff --git a/crates/toml_edit/tests/testsuite/datetime.rs b/crates/toml_edit/tests/testsuite/datetime.rs index 7974ee17..dba89ec5 100644 --- a/crates/toml_edit/tests/testsuite/datetime.rs +++ b/crates/toml_edit/tests/testsuite/datetime.rs @@ -1,8 +1,12 @@ +use snapbox::assert_data_eq; +use snapbox::prelude::*; +use snapbox::str; + macro_rules! bad { ($toml:expr, $msg:expr) => { match $toml.parse::() { Ok(s) => panic!("parsed to: {:#?}", s), - Err(e) => snapbox::assert_eq($msg, e.to_string()), + Err(e) => assert_data_eq!(e.to_string(), $msg.raw()), } }; } @@ -43,214 +47,252 @@ fn times() { 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", - r#"TOML parse error at line 1, column 7 + str![[r#" +TOML parse error at line 1, column 7 | 1 | foo = T | ^ invalid string expected `"`, `'` -"# + +"#]] ); bad!( "foo = T.", - r#"TOML parse error at line 1, column 7 + str![[r#" +TOML parse error at line 1, column 7 | 1 | foo = T. | ^ invalid string expected `"`, `'` -"# + +"#]] ); bad!( "foo = TZ", - r#"TOML parse error at line 1, column 7 + str![[r#" +TOML parse error at line 1, column 7 | 1 | foo = TZ | ^ invalid string expected `"`, `'` -"# + +"#]] ); bad!( "foo = 1997-09-09T09:09:09.09+", - r#"TOML parse error at line 1, column 30 + 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", - r#"TOML parse error at line 1, column 32 + 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", - r#"TOML parse error at line 1, column 33 + 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", - r#"TOML parse error at line 1, column 32 + 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-", - r#"TOML parse error at line 1, column 30 + 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", - r#"TOML parse error at line 1, column 32 + 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", - r#"TOML parse error at line 1, column 33 + 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", - r#"TOML parse error at line 1, column 32 + 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", - r#"TOML parse error at line 1, column 12 + 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", - r#"TOML parse error at line 1, column 15 + 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", - r#"TOML parse error at line 1, column 17 + 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", - r#"TOML parse error at line 1, column 21 + 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", - r#"TOML parse error at line 1, column 24 + 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 a5df5ed2..f31119af 100644 --- a/crates/toml_edit/tests/testsuite/edit.rs +++ b/crates/toml_edit/tests/testsuite/edit.rs @@ -1,6 +1,8 @@ use std::iter::FromIterator; -use snapbox::assert_eq; +use snapbox::assert_data_eq; +use snapbox::prelude::*; +use snapbox::str; use toml_edit::{array, table, value, DocumentMut, Item, Key, Table, Value}; macro_rules! parse_key { @@ -41,8 +43,8 @@ impl Test { } #[track_caller] - fn produces_display(&self, expected: &str) -> &Self { - assert_eq(expected, self.doc.to_string()); + fn produces_display(&self, expected: snapbox::data::Inline) -> &Self { + assert_data_eq!(self.doc.to_string(), expected.raw()); self } } @@ -65,8 +67,8 @@ fn test_insert_leaf_table() { root["servers"]["beta"]["ip"] = value("10.0.0.2"); root["servers"]["beta"]["dc"] = value("eqdc10"); }) - .produces_display( - r#"[servers] + .produces_display(str![[r#" +[servers] [servers.alpha] ip = "10.0.0.1" @@ -77,8 +79,8 @@ ip = "10.0.0.2" dc = "eqdc10" [other.table] -"#, - ); + +"#]]); } #[test] @@ -94,8 +96,8 @@ fn test_inserted_leaf_table_goes_after_last_sibling() { .running(|root| { root["dependencies"]["newthing"] = table(); }) - .produces_display( - r#" + .produces_display(str![[r#" + [package] [dependencies] [[example]] @@ -103,8 +105,8 @@ fn test_inserted_leaf_table_goes_after_last_sibling() { [dependencies.newthing] [dev-dependencies] -"#, - ); + +"#]]); } #[test] @@ -114,7 +116,11 @@ fn test_inserting_tables_from_different_parsed_docs() { let other = "[b]".parse::().unwrap(); root["b"] = other["b"].clone(); }) - .produces_display("[a]\n[b]\n"); + .produces_display(str![[r#" +[a] +[b] + +"#]]); } #[test] fn test_insert_nonleaf_table() { @@ -128,8 +134,8 @@ fn test_insert_nonleaf_table() { root["servers"]["alpha"]["ip"] = value("10.0.0.1"); root["servers"]["alpha"]["dc"] = value("eqdc10"); }) - .produces_display( - r#" + .produces_display(str![[r#" + [other.table] [servers] @@ -137,8 +143,8 @@ fn test_insert_nonleaf_table() { [servers.alpha] ip = "10.0.0.1" dc = "eqdc10" -"#, - ); + +"#]]); } #[test] @@ -159,8 +165,8 @@ fn test_insert_array() { } array.push(Table::new()); }) - .produces_display( - r#" + .produces_display(str![[r#" + [package] title = "withoutarray" @@ -168,8 +174,8 @@ fn test_insert_array() { hello = "world" [[bin]] -"#, - ); + +"#]]); } #[test] @@ -183,15 +189,15 @@ fn test_insert_values() { root["tbl"]["key2"] = value(42); root["tbl"]["key3"] = value(8.1415926); }) - .produces_display( - r#"[tbl] + .produces_display(str![[r#" +[tbl] key1 = "value1" key2 = 42 key3 = 8.1415926 [tbl.son] -"#, - ); + +"#]]); } // removal @@ -216,15 +222,15 @@ fn test_remove_leaf_table() { let servers = as_table!(servers); assert!(servers.remove("alpha").is_some()); }) - .produces_display( - r#" + .produces_display(str![[r#" + [servers] [servers.beta] ip = "10.0.0.2" dc = "eqdc10" -"#, - ); + +"#]]); } #[test] @@ -267,8 +273,8 @@ fn test_remove_nonleaf_table() { .running(|root| { assert!(root.remove("a").is_some()); }) - .produces_display( - r#" + .produces_display(str![[r#" + title = "not relevant" # comment 2 [b] # comment 2.1 @@ -278,8 +284,7 @@ fn test_remove_nonleaf_table() { [some.other.table] - "#, - ); + "#]]); } #[test] @@ -309,8 +314,8 @@ fn test_remove_array_entry() { dmp.remove(1); assert_eq!(dmp.len(), 1); }) - .produces_display( - r#" + .produces_display(str![[r#" + [package] name = "hello" version = "1.0.0" @@ -321,8 +326,8 @@ fn test_remove_array_entry() { [dependencies] nom = "4.0" # future is here -"#, - ); + +"#]]); } #[test] @@ -347,16 +352,16 @@ fn test_remove_array() { .running(|root| { assert!(root.remove("bin").is_some()); }) - .produces_display( - r#" + .produces_display(str![[r#" + [package] name = "hello" version = "1.0.0" [dependencies] nom = "4.0" # future is here -"#, - ); + +"#]]); } #[test] @@ -376,14 +381,14 @@ fn test_remove_value() { let value = value.as_value().unwrap(); assert!(value.is_str()); let value = value.as_str().unwrap(); - assert_eq(value, "1.0.0"); + assert_data_eq!(value, str!["1.0.0"].raw()); }) - .produces_display( - r#" + .produces_display(str![[r#" + name = "hello" documentation = "https://docs.rs/hello" -"#, - ); + +"#]]); } #[test] @@ -405,7 +410,7 @@ fn test_remove_last_value_from_implicit() { let value = value.as_value().unwrap(); assert_eq!(value.as_integer(), Some(1)); }) - .produces_display(r#""#); + .produces_display(str![]); } // values @@ -429,8 +434,8 @@ fn test_sort_values() { let a = as_table!(a); a.sort_values(); }) - .produces_display( - r#" + .produces_display(str![[r#" + [a.z] [a] @@ -440,8 +445,8 @@ fn test_sort_values() { c = 3 [a.y] -"#, - ); + +"#]]); } #[test] @@ -465,8 +470,8 @@ fn test_sort_values_by() { // before 'a'. a.sort_values_by(|k1, _, k2, _| k1.display_repr().cmp(&k2.display_repr())); }) - .produces_display( - r#" + .produces_display(str![[r#" + [a.z] [a] @@ -476,8 +481,8 @@ fn test_sort_values_by() { b = 2 # as well as this [a.y] -"#, - ); + +"#]]); } #[test] @@ -499,14 +504,14 @@ fn test_set_position() { } } }) - .produces_display( - r#" [dependencies] + .produces_display(str![[r#" + [dependencies] [package] [dev-dependencies] [dependencies.opencl] -"#, - ); + +"#]]); } #[test] @@ -524,15 +529,15 @@ fn test_multiple_zero_positions() { as_table!(table).set_position(0); } }) - .produces_display( - r#" + .produces_display(str![[r#" + [package] [dependencies] [dev-dependencies] [dependencies.opencl] a="" -"#, - ); + +"#]]); } #[test] @@ -550,15 +555,15 @@ fn test_multiple_max_usize_positions() { as_table!(table).set_position(usize::MAX); } }) - .produces_display( - r#" [dependencies.opencl] + .produces_display(str![[r#" + [dependencies.opencl] a="" [package] [dependencies] [dev-dependencies] -"#, - ); + +"#]]); } macro_rules! as_array { @@ -609,14 +614,14 @@ fn test_insert_replace_into_array() { ); dbg!(root); }) - .produces_display( - r#" + .produces_display(str![[r#" + a = [1, 2, 3, 4] b = ["hello", "beep", "zoink" , "world" , "yikes"] -"#, - ); + +"#]]); } #[test] @@ -640,12 +645,12 @@ fn test_remove_from_array() { assert!(b.remove(0).is_str()); assert!(b.is_empty()); }) - .produces_display( - r#" + .produces_display(str![[r#" + a = [1, 2, 3] b = [] -"#, - ); + +"#]]); } #[test] @@ -666,11 +671,10 @@ fn test_format_array() { } } }) - .produces_display( - r#" + .produces_display(str![[r#" + a = [1, "2", 3.0] - "#, - ); + "#]]); } macro_rules! as_inline_table { @@ -706,12 +710,12 @@ fn test_insert_into_inline_table() { assert_eq!(b.len(), 1); b.fmt(); }) - .produces_display( - r#" + .produces_display(str![[r#" + a = { a = 2, c = 3, b = 42 } b = { hello = "world" } -"#, - ); + +"#]]); } #[test] @@ -735,12 +739,12 @@ fn test_remove_from_inline_table() { assert!(b.remove("hello").is_some()); assert!(b.is_empty()); }) - .produces_display( - r#" + .produces_display(str![[r#" + a = {a=2, b = 42} b = {} -"#, - ); + +"#]]); } #[test] @@ -814,11 +818,11 @@ fn test_insert_dotted_into_std_table() { .set_dotted(true); root["nixpkgs"]["src"]["git"] = value("https://github.com/nixos/nixpkgs"); }) - .produces_display( - r#"[nixpkgs] + .produces_display(str![[r#" +[nixpkgs] src.git = "https://github.com/nixos/nixpkgs" -"#, - ); + +"#]]); } #[test] @@ -833,11 +837,11 @@ fn test_insert_dotted_into_implicit_table() { .unwrap() .set_dotted(true); }) - .produces_display( - r#"[nixpkgs] + .produces_display(str![[r#" +[nixpkgs] src.git = "https://github.com/nixos/nixpkgs" -"#, - ); + +"#]]); } #[test] diff --git a/crates/toml_edit/tests/testsuite/invalid.rs b/crates/toml_edit/tests/testsuite/invalid.rs index 0d963665..b685ff9a 100644 --- a/crates/toml_edit/tests/testsuite/invalid.rs +++ b/crates/toml_edit/tests/testsuite/invalid.rs @@ -1,45 +1,58 @@ +use snapbox::assert_data_eq; +use snapbox::prelude::*; +use snapbox::str; + #[test] fn incomplete_inline_table_issue_296() { let err = "native = {".parse::().unwrap_err(); - snapbox::assert_eq( - r#"TOML parse error at line 1, column 11 + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 11 | 1 | native = { | ^ invalid inline table expected `}` -"#, - err.to_string(), + +"#]] + .raw() ); } #[test] fn bare_value_disallowed_issue_293() { let err = "value=zzz".parse::().unwrap_err(); - snapbox::assert_eq( - r#"TOML parse error at line 1, column 7 + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 7 | 1 | value=zzz | ^ invalid string expected `"`, `'` -"#, - err.to_string(), + +"#]] + .raw() ); } #[test] fn bare_value_in_array_disallowed_issue_293() { let err = "value=[zzz]".parse::().unwrap_err(); - snapbox::assert_eq( - r#"TOML parse error at line 1, column 8 + assert_data_eq!( + err.to_string(), + str![[r#" +TOML parse error at line 1, column 8 | 1 | value=[zzz] | ^ invalid array expected `]` -"#, - err.to_string(), + +"#]] + .raw() ); } @@ -57,157 +70,208 @@ rand = \"0.3.14\" " .parse::() .unwrap_err(); - snapbox::assert_eq( - r#"TOML parse error at line 8, column 1 + 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 -"#, - err.to_string(), + +"#]] + .raw() ); } #[test] fn bad() { let toml_input = "a = 01"; - let expected_err = "\ + 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, `#` -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); let toml_input = "a = 1__1"; - let expected_err = "\ + 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 -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); let toml_input = "a = 1_"; - let expected_err = "\ + 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 -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); let toml_input = "''"; - let expected_err = "\ + 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 `.`, `=` -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); let toml_input = "a = 9e99999"; - let expected_err = "\ + 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 -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); let toml_input = "a = \"\u{7f}\""; - let expected_err = "\ + 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 = \"\u{7f}\" +1 | a = "" | ^ invalid basic string -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); let toml_input = "a = '\u{7f}'"; - let expected_err = "\ + 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 = '\u{7f}' +1 | a = '' | ^ invalid literal string -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); let toml_input = "a = -0x1"; - let expected_err = "\ + 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, `#` -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); let toml_input = "a = 0x-1"; - let expected_err = "\ + 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 -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); // Dotted keys. let toml_input = "a.b.c = 1 a.b = 2 "; - let expected_err = "\ + 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 -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); let toml_input = "a = 1 a.b = 2"; - let expected_err = "\ + 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) -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); let toml_input = "a = {k1 = 1, k1.name = \"joe\"}"; - let expected_err = "\ + 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\"} +1 | a = {k1 = 1, k1.name = "joe"} | ^ dotted key `k1` attempted to extend non-table type (integer) -"; - let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + +"#]] + .raw() + ); } #[test] diff --git a/crates/toml_edit/tests/testsuite/parse.rs b/crates/toml_edit/tests/testsuite/parse.rs index a37bbb4b..3cee2e22 100644 --- a/crates/toml_edit/tests/testsuite/parse.rs +++ b/crates/toml_edit/tests/testsuite/parse.rs @@ -1,4 +1,6 @@ -use snapbox::assert_eq; +use snapbox::assert_data_eq; +use snapbox::prelude::*; +use snapbox::str; use toml_edit::{DocumentMut, Key, Value}; macro_rules! parse { @@ -81,24 +83,26 @@ fn test_key_unification() { [a."b".c.e] [a.b.c.d] "#; - let expected = r#" + let expected = str![[r#" + [a] [a.'b'.c] [a.'b'.c.e] [a.'b'.c.d] -"#; + +"#]]; let doc = toml.parse::(); assert!(doc.is_ok()); let doc = doc.unwrap(); - assert_eq(expected, doc.to_string()); + assert_data_eq!(doc.to_string(), expected.raw()); } macro_rules! bad { ($toml:expr, $msg:expr) => { match $toml.parse::() { Ok(s) => panic!("parsed to: {:#?}", s), - Err(e) => assert_eq($msg, e.to_string()), + Err(e) => assert_data_eq!(e.to_string(), $msg.raw()), } }; } @@ -241,7 +245,7 @@ metadata.msrv = "1.65.0" "#; let document = input.parse::().unwrap(); let actual = document.to_string(); - assert_eq(input, actual); + assert_data_eq!(actual, input.raw()); } #[test] @@ -293,81 +297,88 @@ name = "plantain" fn stray_cr() { bad!( "\r", - "\ + str![[r#" TOML parse error at line 1, column 1 | -1 | \r +1 | | ^ -" + +"#]] ); bad!( "a = [ \r ]", - "\ + str![[r#" TOML parse error at line 1, column 7 | -1 | a = [ \r +1 | a = [ ] | ^ invalid array expected `]` -" + +"#]] ); bad!( "a = \"\"\"\r\"\"\"", - "\ + str![[r#" TOML parse error at line 1, column 8 | -1 | a = \"\"\"\r -\"\"\" +1 | a = """ +""" | ^ invalid multiline basic string -" + +"#]] ); bad!( "a = \"\"\"\\ \r \"\"\"", - "\ + str![[r#" TOML parse error at line 1, column 10 | -1 | a = \"\"\"\\ \r - \"\"\" +1 | a = """\ + """ | ^ invalid escape sequence -expected `b`, `f`, `n`, `r`, `t`, `u`, `U`, `\\`, `\"` -" +expected `b`, `f`, `n`, `r`, `t`, `u`, `U`, `\`, `"` + +"#]] ); bad!( "a = '''\r'''", - "\ + str![[r#" TOML parse error at line 1, column 8 | -1 | a = '''\r +1 | a = ''' ''' | ^ invalid multiline literal string -" + +"#]] ); bad!( "a = '\r'", - "\ + str![[r#" TOML parse error at line 1, column 6 | -1 | a = '\r +1 | a = ' ' | ^ invalid literal string -" + +"#]] ); bad!( "a = \"\r\"", - "\ + str![[r#" TOML parse error at line 1, column 6 | -1 | a = \"\r -\" +1 | a = " +" | ^ invalid basic string -" + +"#]] ); } @@ -399,23 +410,25 @@ fn literal_eats_crlf() { fn string_no_newline() { bad!( "a = \"\n\"", - "\ + str![[r#" TOML parse error at line 1, column 6 | -1 | a = \" +1 | a = " | ^ invalid basic string -" + +"#]] ); bad!( "a = '\n'", - "\ + str![[r#" TOML parse error at line 1, column 6 | 1 | a = ' | ^ invalid literal string -" + +"#]] ); } @@ -423,83 +436,91 @@ invalid literal string 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 -" + +"#]] ); } @@ -507,76 +528,83 @@ number too small to fit in target type 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 -" + +"#]] ); } @@ -640,114 +668,126 @@ fn bare_key_names() { 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 `\"`, `'` -" +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 +1 | ""|=3 | ^ expected `.`, `=` -" + +"#]] ); bad!( "\"\n\"|=3", - "\ + str![[r#" TOML parse error at line 1, column 2 | -1 | \" +1 | " | ^ invalid basic string -" + +"#]] ); bad!( "\"\r\"|=3", - "\ + str![[r#" TOML parse error at line 1, column 2 | -1 | \"\r\"|=3 +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 +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 +1 | """key"""=3 | ^ expected `.`, `=` -" + +"#]] ); } @@ -755,139 +795,152 @@ expected `.`, `=` 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 | [\" +1 | [" | ^ invalid basic string -" + +"#]] ); bad!( "[a.b]\n[a.\"b\"]", - "\ + str![[r#" TOML parse error at line 2, column 1 | -2 | [a.\"b\"] +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\"\"\"] +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 -" + +"#]] ); } @@ -915,13 +968,14 @@ fn table_names() { fn invalid_bare_numeral() { bad!( "4", - "\ + str![[r#" TOML parse error at line 1, column 2 | 1 | 4 | ^ expected `.`, `=` -" + +"#]] ); } @@ -935,57 +989,62 @@ fn inline_tables() { 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(); @@ -1014,45 +1073,49 @@ fn number_underscores() { 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 -" + +"#]] ); } @@ -1060,14 +1123,15 @@ expected digit fn bad_unicode_codepoint() { bad!( "foo = \"\\uD800\"", - "\ + str![[r#" TOML parse error at line 1, column 10 | -1 | foo = \"\\uD800\" +1 | foo = "\uD800" | ^ invalid unicode 4-digit hex code value is out of range -" + +"#]] ); } @@ -1075,43 +1139,47 @@ value is out of range fn bad_strings() { bad!( "foo = \"\\uxx\"", - "\ + str![[r#" TOML parse error at line 1, column 10 | -1 | foo = \"\\uxx\" +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\" +1 | foo = "\u" | ^ invalid unicode 4-digit hex code -" + +"#]] ); bad!( "foo = \"\\", - "\ + str![[r#" TOML parse error at line 1, column 8 | -1 | foo = \"\\ +1 | foo = "\ | ^ invalid basic string -" + +"#]] ); bad!( "foo = '", - "\ + str![[r#" TOML parse error at line 1, column 8 | 1 | foo = ' | ^ invalid literal string -" + +"#]] ); } @@ -1135,45 +1203,49 @@ fn booleans() { 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 `\"`, `'` -" +expected `"`, `'` + +"#]] ); bad!( "foo = f2", - "\ + str![[r#" TOML parse error at line 1, column 7 | 1 | foo = f2 | ^ invalid string -expected `\"`, `'` -" +expected `"`, `'` + +"#]] ); } @@ -1185,56 +1257,60 @@ fn bad_nesting() { [[a]] b = 5 ", - "\ + str![[r#" TOML parse error at line 3, column 9 | 3 | [[a]] | ^ invalid table header duplicate key `a` in document root -" + +"#]] ); bad!( " a = 1 [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) -" + +"#]] ); bad!( " a = [] [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) -" + +"#]] ); bad!( " a = [] [[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) -" + +"#]] ); bad!( " @@ -1243,14 +1319,15 @@ dotted key `a` attempted to extend non-table type (array) [a.b] c = 2 ", - "\ + str![[r#" TOML parse error at line 4, column 9 | 4 | [a.b] | ^ invalid table header duplicate key `b` in table `a` -" + +"#]] ); } @@ -1264,14 +1341,15 @@ fn bad_table_redefine() { foo=\"bar\" [a] ", - "\ + str![[r#" TOML parse error at line 6, column 9 | 6 | [a] | ^ invalid table header duplicate key `a` in document root -" + +"#]] ); bad!( " @@ -1280,14 +1358,15 @@ duplicate key `a` in document root b = { foo = \"bar\" } [a] ", - "\ + str![[r#" TOML parse error at line 5, column 9 | 5 | [a] | ^ invalid table header duplicate key `a` in document root -" + +"#]] ); bad!( " @@ -1295,14 +1374,15 @@ duplicate key `a` in document root b = {} [a.b] ", - "\ + str![[r#" TOML parse error at line 4, column 9 | 4 | [a.b] | ^ invalid table header duplicate key `b` in table `a` -" + +"#]] ); bad!( @@ -1311,14 +1391,15 @@ duplicate key `b` in table `a` b = {} [a] ", - "\ + str![[r#" TOML parse error at line 4, column 9 | 4 | [a] | ^ invalid table header duplicate key `a` in document root -" + +"#]] ); } @@ -1338,53 +1419,58 @@ fn datetimes() { 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, `#` -" + +"#]] ); } @@ -1392,24 +1478,27 @@ expected newline, `#` 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!( r#" 0=""o=""m=""r=""00="0"q="""0"""e="""0""" "#, - r#"TOML parse error at line 2, column 5 + str![[r#" +TOML parse error at line 2, column 5 | 2 | 0=""o=""m=""r=""00="0"q="""0"""e="""0""" | ^ expected newline, `#` -"# + +"#]] ); bad!( r#" @@ -1418,45 +1507,53 @@ expected newline, `#` 0="0"[[0000l0]] 0="0"l="0" "#, - r#"TOML parse error at line 3, column 6 + str![[r#" +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] "#, - r#"TOML parse error at line 2, column 6 + 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, `#` -"# + +"#]] ); bad!( r#" 0=0r0=0r=false "#, - r#"TOML parse error at line 2, column 4 + str![[r#" +TOML parse error at line 2, column 4 | 2 | 0=0r0=0r=false | ^ expected newline, `#` -"# + +"#]] ); bad!( r#" 0=0r0=0r=falsefal=false "#, - r#"TOML parse error at line 2, column 4 + str![[r#" +TOML parse error at line 2, column 4 | 2 | 0=0r0=0r=falsefal=false | ^ expected newline, `#` -"# + +"#]] ); } @@ -1473,7 +1570,7 @@ p.a=4 "#; let document = input.parse::().unwrap(); let actual = document.to_string(); - assert_eq(input, actual); + assert_data_eq!(actual, input.raw()); } #[test] @@ -1506,5 +1603,5 @@ clippy.exhaustive_enums = "warn" let manifest: DocumentMut = input.parse().unwrap(); let actual = manifest.to_string(); - assert_eq(expected, actual); + assert_data_eq!(actual, expected.raw()); }