diff --git a/crates/toml/tests/testsuite/de_errors.rs b/crates/toml/tests/testsuite/de_errors.rs index 4864a75f..8c3bf71f 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,13 @@ fn custom_errors() { # ^ ", Parent, - "\ -TOML parse error at line 2, column 19 - | -2 | p_a = '' - | ^^ -invalid length 0, expected a non-empty string -" + 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 +103,13 @@ invalid length 0, expected a non-empty string # ^ ", Parent, - "\ -TOML parse error at line 1, column 1 - | -1 | - | ^ -missing field `p_b` -" + str![[r#" + TOML parse error at line 1, column 1 + | + 1 | + | ^ + missing field `p_b` + "#]] ); // Invalid type in p_b. @@ -116,13 +120,13 @@ missing field `p_b` # ^ ", Parent, - "\ -TOML parse error at line 3, column 19 - | -3 | p_b = 1 - | ^ -invalid type: integer `1`, expected a sequence -" + 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 +139,13 @@ invalid type: integer `1`, expected a sequence ] ", Parent, - "\ -TOML parse error at line 4, column 17 - | -4 | {c_a = 'a'} - | ^^^^^^^^^^^ -missing field `c_b` -" + 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 +158,13 @@ missing field `c_b` ] ", Parent, - "\ -TOML parse error at line 4, column 35 - | -4 | {c_a = 'a', c_b = '*'} - | ^^^ -invalid value: string \"*\", expected all lowercase or all uppercase -" + 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 + "#]] ); // Sub-table in Vec is missing a field. @@ -174,13 +178,13 @@ invalid value: string \"*\", expected all lowercase or all uppercase ] ", Parent, - "\ -TOML parse error at line 5, column 17 - | -5 | {c_a = 'aa'} - | ^^^^^^^^^^^^ -missing field `c_b` -" + 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 +199,13 @@ missing field `c_b` ] ", Parent, - "\ -TOML parse error at line 5, column 17 - | -5 | {c_a = 'aa'}, - | ^^^^^^^^^^^^ -missing field `c_b` -" + 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 +220,13 @@ missing field `c_b` ] ", Parent, - "\ -TOML parse error at line 5, column 36 - | -5 | {c_a = 'aa', c_b = 1}, - | ^ -invalid type: integer `1`, expected a string -" + 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 +242,13 @@ invalid type: integer `1`, expected a string ] ", Parent, - "\ -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` -" + 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 +271,13 @@ unknown field `c_d`, expected `c_a` or `c_b` c_b = 'bbbb' ", Parent, - "\ -TOML parse error at line 6, column 13 - | -6 | [[p_b]] - | ^^^^^^^ -missing field `c_b` -" + 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 +296,13 @@ missing field `c_b` c_b = 'bbb' ", Parent, - "\ -TOML parse error at line 8, column 19 - | -8 | c_b = '*' - | ^^^ -invalid value: string \"*\", expected all lowercase or all uppercase -" + str![[r#" + 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. @@ -320,13 +324,13 @@ invalid value: string \"*\", expected all lowercase or all uppercase c_b = 'bbbb' ", Parent, - "\ -TOML parse error at line 8, column 13 - | -8 | c_d = 'dd' # unknown field - | ^^^ -unknown field `c_d`, expected `c_a` or `c_b` -" + 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 +342,13 @@ fn serde_derive_deserialize_errors() { # ^ ", Parent, - "\ -TOML parse error at line 1, column 1 - | -1 | - | ^ -missing field `p_b` -" + str![[r#" + TOML parse error at line 1, column 1 + | + 1 | + | ^ + missing field `p_b` + "#]] ); bad!( @@ -356,13 +360,13 @@ missing field `p_b` ] ", Parent, - "\ -TOML parse error at line 4, column 17 - | -4 | {c_a = ''} - | ^^^^^^^^^^ -missing field `c_b` -" + str![[r#" + TOML parse error at line 4, column 17 + | + 4 | {c_a = ''} + | ^^^^^^^^^^ + missing field `c_b` + "#]] ); bad!( @@ -374,13 +378,13 @@ missing field `c_b` ] ", Parent, - "\ -TOML parse error at line 4, column 34 - | -4 | {c_a = '', c_b = 1} - | ^ -invalid type: integer `1`, expected a string -" + 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 +397,13 @@ invalid type: integer `1`, expected a string ] ", Parent, - "\ -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` -" + 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 +415,13 @@ unknown field `c_d`, expected `c_a` or `c_b` ] ", Parent, - "\ -TOML parse error at line 4, column 34 - | -4 | {c_a = '', c_b = 1, c_d = ''}, - | ^ -invalid type: integer `1`, expected a string -" + 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 +435,13 @@ fn error_handles_crlf() { a = 2\r\n\ ", toml::Value, - "\ -TOML parse error at line 5, column 1 - | -5 | a = 2 - | ^ -duplicate key `a` in table `t2` -" + 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 +453,12 @@ duplicate key `a` in table `t2` a = 2\n\ ", toml::Value, - "\ -TOML parse error at line 5, column 1 - | -5 | a = 2 - | ^ -duplicate key `a` in table `t2` -" + 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..67d45bbb 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,90 +36,72 @@ 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` -"#, - error.to_string(), - ); + 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 - | -1 | val = "NonExistent" - | ^^^^^^^^^^^^^ -unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` -"#, - error.to_string(), - ); + 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(); - snapbox::assert_eq( - r#"unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` -"#, - error.to_string(), - ); + 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 - | -1 | val = { NonExistent = {} } - | ^^^^^^^^^^^ -unknown variant `NonExistent`, expected one of `Plain`, `Tuple`, `NewType`, `Struct` -"#, - error.to_string(), - ); + 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(); - snapbox::assert_eq( - r#"expected empty table -"#, - error.to_string(), - ); + 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 - | -1 | val = { Plain = { extra_field = 404 } } - | ^^^^^^^^^^^^^^^^^^^^^ -expected empty table -"#, - error.to_string(), - ); + 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(); - - snapbox::assert_eq( - r#"unexpected keys in table: extra_0, extra_1, available keys: value -"#, - error.to_string(), - ); + 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 - | -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(), - ); + 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/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..0af6aff4 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,17 @@ fn type_errors() { map! { bar: Value::String("a".to_owned()) }, - 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#" + 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` + "#]] } error! { @@ -299,13 +309,17 @@ invalid type: string "a", expected isize bar: Value::String("a".to_owned()) } }, - 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#" + 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` + "#]] } } @@ -319,13 +333,16 @@ fn missing_errors() { error! { Foo, map! { }, - r#"TOML parse error at line 1, column 1 - | -1 | - | ^ -missing field `bar` -"#, - "missing field `bar`\n" + str![[r#" + TOML parse error at line 1, column 1 + | + 1 | + | ^ + missing field `bar` + "#]], + str![[r#" + missing field `bar` + "#]] } } @@ -402,14 +419,14 @@ fn parse_tuple_variant() { Enum::String("2".to_owned(), "2".to_owned()), ], }; - let expected = "[[inner]] -Int = [1, 1] - -[[inner]] -String = [\"2\", \"2\"] -"; let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); + assert_data_eq!(raw, str![[r#" + [[inner]] + Int = [1, 1] + + [[inner]] + String = ["2", "2"] + "#]].raw()); equivalent! { Document { @@ -452,20 +469,20 @@ 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 -second = 1 + [inner.Int] + first = 1 + second = 1 -[[inner]] + [[inner]] -[inner.String] -first = \"2\" -second = \"2\" -"; - let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); + [inner.String] + first = "2" + second = "2" + "#]].raw()); equivalent! { Document { @@ -783,7 +800,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,15 +918,13 @@ debug = 'a' "#, ); let err = res.unwrap_err(); - snapbox::assert_eq( - r#"TOML parse error at line 8, column 9 - | -8 | debug = 'a' - | ^^^ -expected a boolean or an integer -"#, - err.to_string(), - ); + 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#" @@ -923,15 +938,13 @@ dev = { debug = 'a' } "#, ); let err = res.unwrap_err(); - snapbox::assert_eq( - r#"TOML parse error at line 8, column 17 - | -8 | dev = { debug = 'a' } - | ^^^ -expected a boolean or an integer -"#, - err.to_string(), - ); + 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] @@ -945,11 +958,9 @@ fn newline_key_value() { name: "foo".to_owned(), }; let raw = toml::to_string_pretty(&package).unwrap(); - snapbox::assert_eq( - r#"name = "foo" -"#, - raw, - ); + assert_data_eq!(raw, str![[r#" + name = "foo" + "#]]); } #[test] @@ -970,12 +981,10 @@ fn newline_table() { }, }; let raw = toml::to_string_pretty(&package).unwrap(); - snapbox::assert_eq( - r#"[package] -name = "foo" -"#, - raw, - ); + assert_data_eq!(raw, str![[r#" + [package] + name = "foo" + "#]]); } #[test] @@ -1010,12 +1019,10 @@ fn newline_dotted_table() { }, }; let raw = toml::to_string_pretty(&package).unwrap(); - snapbox::assert_eq( - r#"[profile.dev] -debug = true -"#, - raw, - ); + assert_data_eq!(raw, str![[r#" + [profile.dev] + debug = true + "#]]); } #[test] @@ -1065,19 +1072,17 @@ 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" -version = "1.0.0" -authors = [] + [package] + name = "foo" + version = "1.0.0" + authors = [] -[profile.dev] -debug = true -"#, - raw, - ); + [profile.dev] + debug = true + "#]]); } #[test] @@ -1102,9 +1107,9 @@ 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 +1155,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 +1167,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 +1224,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 +1237,16 @@ 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,21 +1269,20 @@ fn serialize_array_with_optional_struct_field() { OptionalField { x: 3, y: Some(7) }, ], }; - let expected = "\ -[[values]] -x = 0 -y = 4 - -[[values]] -x = 2 -y = 5 - -[[values]] -x = 3 -y = 7 -"; let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); + assert_data_eq!(raw, str![[r#" + [[values]] + x = 0 + y = 4 + + [[values]] + x = 2 + y = 5 + + [[values]] + x = 3 + y = 7 + "#]].raw()); let input = Document { values: vec![ @@ -1286,20 +1291,19 @@ y = 7 OptionalField { x: 3, y: Some(7) }, ], }; - let expected = "\ -[[values]] -x = 0 -y = 4 - -[[values]] -x = 2 - -[[values]] -x = 3 -y = 7 -"; let raw = toml::to_string(&input).unwrap(); - snapbox::assert_eq(expected, raw); + assert_data_eq!(raw, str![[r#" + [[values]] + x = 0 + y = 4 + + [[values]] + x = 2 + + [[values]] + x = 3 + y = 7 + "#]].raw()); } #[test] @@ -1329,10 +1333,10 @@ 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 +1346,10 @@ 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..1e04790b 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,11 @@ fn deny_unknown_fields() { fake = 1"#, ) .unwrap_err(); - snapbox::assert_eq( - "\ -TOML parse error at line 3, column 1 - | -3 | fake = 1 - | ^^^^ -unknown field `fake`, expected `real` -", - error.to_string(), - ); + 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/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..20c8c8a2 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,9 @@ 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 +41,13 @@ fn inline_table_to_table() { doc.insert("table", Item::Table(t)); let actual = doc.to_string(); - 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] @@ -73,7 +75,7 @@ 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..2f7f9462 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()), } }; } @@ -41,216 +45,166 @@ fn times() { #[test] fn bad_times() { - bad!( - "foo = 199-09-09", - "\ -TOML parse error at line 1, column 10 - | -1 | foo = 199-09-09 - | ^ -expected newline, `#` -" - ); - bad!( - "foo = 199709-09", - "\ -TOML parse error at line 1, column 13 - | -1 | foo = 199709-09 - | ^ -expected newline, `#` -" - ); - bad!( - "foo = 1997-9-09", - "\ -TOML parse error at line 1, column 12 - | -1 | foo = 1997-9-09 - | ^ -invalid date-time -" - ); - bad!( - "foo = 1997-09-9", - "\ -TOML parse error at line 1, column 15 - | -1 | foo = 1997-09-9 - | ^ -invalid date-time -" - ); - bad!( - "foo = 1997-09-0909:09:09", - "\ -TOML parse error at line 1, column 17 - | -1 | foo = 1997-09-0909:09:09 - | ^ -expected newline, `#` -" - ); - bad!( - "foo = 1997-09-09T09:09:09.", - "\ -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 - | -1 | foo = T - | ^ -invalid string -expected `"`, `'` -"# - ); - bad!( - "foo = T.", - 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 - | -1 | foo = TZ - | ^ -invalid string -expected `"`, `'` -"# - ); - bad!( - "foo = 1997-09-09T09:09:09.09+", - 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 - | -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 - | -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 - | -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 - | -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 - | -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 - | -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 - | -1 | foo = 1997-09-09T09:09:09.09-0909 - | ^ -invalid time offset -"# - ); + 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", - 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 - | -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 - | -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 - | -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 - | -1 | foo = 1997-09-09T12:09:69.09Z - | ^ -invalid date-time -value is out of range -"# - ); + 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 a5df5ed2..109b660f 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.indent(false).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,7 @@ ip = "10.0.0.2" dc = "eqdc10" [other.table] -"#, - ); +"#]]); } #[test] @@ -94,8 +95,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 +104,7 @@ fn test_inserted_leaf_table_goes_after_last_sibling() { [dependencies.newthing] [dev-dependencies] -"#, - ); +"#]]); } #[test] @@ -114,7 +114,10 @@ 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 +131,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 +140,7 @@ fn test_insert_nonleaf_table() { [servers.alpha] ip = "10.0.0.1" dc = "eqdc10" -"#, - ); +"#]]); } #[test] @@ -159,8 +161,8 @@ fn test_insert_array() { } array.push(Table::new()); }) - .produces_display( - r#" + .produces_display(str![[r#" + [package] title = "withoutarray" @@ -168,8 +170,7 @@ fn test_insert_array() { hello = "world" [[bin]] -"#, - ); +"#]]); } #[test] @@ -183,15 +184,14 @@ 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 +216,14 @@ 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 +266,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 +277,7 @@ fn test_remove_nonleaf_table() { [some.other.table] - "#, - ); + "#]]); } #[test] @@ -309,8 +307,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 +319,7 @@ fn test_remove_array_entry() { [dependencies] nom = "4.0" # future is here -"#, - ); +"#]]); } #[test] @@ -347,16 +344,15 @@ 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 +372,13 @@ 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 +400,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 +424,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 +435,7 @@ fn test_sort_values() { c = 3 [a.y] -"#, - ); +"#]]); } #[test] @@ -465,8 +459,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 +470,7 @@ fn test_sort_values_by() { b = 2 # as well as this [a.y] -"#, - ); +"#]]); } #[test] @@ -499,14 +492,13 @@ fn test_set_position() { } } }) - .produces_display( - r#" [dependencies] + .produces_display(str![[r#" + [dependencies] [package] [dev-dependencies] [dependencies.opencl] -"#, - ); +"#]]); } #[test] @@ -524,15 +516,14 @@ 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 +541,14 @@ 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 +599,13 @@ 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 +629,11 @@ 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 +654,10 @@ fn test_format_array() { } } }) - .produces_display( - r#" + .produces_display(str![[r#" + a = [1, "2", 3.0] - "#, - ); + "#]]); } macro_rules! as_inline_table { @@ -706,12 +693,11 @@ 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 +721,11 @@ 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 +799,10 @@ 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 +817,10 @@ 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..2e41532f 100644 --- a/crates/toml_edit/tests/testsuite/invalid.rs +++ b/crates/toml_edit/tests/testsuite/invalid.rs @@ -1,46 +1,44 @@ +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 - | -1 | native = { - | ^ -invalid inline table -expected `}` -"#, - err.to_string(), - ); + 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(); - snapbox::assert_eq( - r#"TOML parse error at line 1, column 7 - | -1 | value=zzz - | ^ -invalid string -expected `"`, `'` -"#, - err.to_string(), - ); + 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(); - snapbox::assert_eq( - r#"TOML parse error at line 1, column 8 - | -1 | value=[zzz] - | ^ -invalid array -expected `]` -"#, - err.to_string(), - ); + assert_data_eq!(err.to_string(), str![[r#" + TOML parse error at line 1, column 8 + | + 1 | value=[zzz] + | ^ + invalid array + expected `]` + "#]].raw()); } #[test] @@ -57,157 +55,143 @@ rand = \"0.3.14\" " .parse::() .unwrap_err(); - snapbox::assert_eq( - r#"TOML parse error at line 8, column 1 - | -8 | [dependencies] - | ^ -invalid table header -duplicate key `dependencies` in document root -"#, - err.to_string(), - ); + 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 expected_err = "\ -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()); + 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 expected_err = "\ -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()); + 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 expected_err = "\ -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()); + 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 expected_err = "\ -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()); + 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 expected_err = "\ -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()); + 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 expected_err = "\ -TOML parse error at line 1, column 6 - | -1 | a = \"\u{7f}\" - | ^ -invalid basic string -"; let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + 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 expected_err = "\ -TOML parse error at line 1, column 6 - | -1 | a = '\u{7f}' - | ^ -invalid literal string -"; let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + 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 expected_err = "\ -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()); + 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 expected_err = "\ -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()); + 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 expected_err = "\ -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()); + 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 expected_err = "\ -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()); + 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 expected_err = "\ -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) -"; let err = toml_input.parse::().unwrap_err(); - snapbox::assert_eq(expected_err, err.to_string()); + 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 a37bbb4b..0c9e39cf 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,25 @@ fn test_key_unification() { [a."b".c.e] [a.b.c.d] "#; - let expected = r#" -[a] -[a.'b'.c] -[a.'b'.c.e] -[a.'b'.c.d] -"#; + 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 +244,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] @@ -291,84 +294,63 @@ name = "plantain" #[test] fn stray_cr() { - bad!( - "\r", - "\ -TOML parse error at line 1, column 1 - | -1 | \r - | ^ - -" - ); - bad!( - "a = [ \r ]", - "\ -TOML parse error at line 1, column 7 - | -1 | a = [ \r - ] - | ^ -invalid array -expected `]` -" - ); - bad!( - "a = \"\"\"\r\"\"\"", - "\ -TOML parse error at line 1, column 8 - | -1 | a = \"\"\"\r -\"\"\" - | ^ -invalid multiline basic string -" - ); - bad!( - "a = \"\"\"\\ \r \"\"\"", - "\ -TOML parse error at line 1, column 10 - | -1 | a = \"\"\"\\ \r - \"\"\" - | ^ -invalid escape sequence -expected `b`, `f`, `n`, `r`, `t`, `u`, `U`, `\\`, `\"` -" - ); - bad!( - "a = '''\r'''", - "\ -TOML parse error at line 1, column 8 - | -1 | a = '''\r -''' - | ^ -invalid multiline literal string -" - ); - bad!( - "a = '\r'", - "\ -TOML parse error at line 1, column 6 - | -1 | a = '\r -' - | ^ -invalid literal string -" - ); - bad!( - "a = \"\r\"", - "\ -TOML parse error at line 1, column 6 - | -1 | a = \"\r -\" - | ^ -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] @@ -397,187 +379,136 @@ fn literal_eats_crlf() { #[test] fn string_no_newline() { - bad!( - "a = \"\n\"", - "\ -TOML parse error at line 1, column 6 - | -1 | a = \" - | ^ -invalid basic string -" - ); - bad!( - "a = '\n'", - "\ -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", - "\ -TOML parse error at line 1, column 6 - | -1 | a = 00 - | ^ -expected newline, `#` -" - ); - bad!( - "a = -00", - "\ -TOML parse error at line 1, column 7 - | -1 | a = -00 - | ^ -expected newline, `#` -" - ); - bad!( - "a = +00", - "\ -TOML parse error at line 1, column 7 - | -1 | a = +00 - | ^ -expected newline, `#` -" - ); - bad!( - "a = 00.0", - "\ -TOML parse error at line 1, column 6 - | -1 | a = 00.0 - | ^ -expected newline, `#` -" - ); - bad!( - "a = -00.0", - "\ -TOML parse error at line 1, column 7 - | -1 | a = -00.0 - | ^ -expected newline, `#` -" - ); - bad!( - "a = +00.0", - "\ -TOML parse error at line 1, column 7 - | -1 | a = +00.0 - | ^ -expected newline, `#` -" - ); - bad!( - "a = 9223372036854775808", - "\ -TOML parse error at line 1, column 5 - | -1 | a = 9223372036854775808 - | ^ -number too large to fit in target type -" - ); - bad!( - "a = -9223372036854775809", - "\ -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.", - "\ -TOML parse error at line 1, column 7 - | -1 | a = 0. - | ^ -invalid floating-point number -expected digit -" - ); - bad!( - "a = 0.e", - "\ -TOML parse error at line 1, column 7 - | -1 | a = 0.e - | ^ -invalid floating-point number -expected digit -" - ); - bad!( - "a = 0.E", - "\ -TOML parse error at line 1, column 7 - | -1 | a = 0.E - | ^ -invalid floating-point number -expected digit -" - ); - bad!( - "a = 0.0E", - "\ -TOML parse error at line 1, column 9 - | -1 | a = 0.0E - | ^ -invalid floating-point number -" - ); - bad!( - "a = 0.0e", - "\ -TOML parse error at line 1, column 9 - | -1 | a = 0.0e - | ^ -invalid floating-point number -" - ); - bad!( - "a = 0.0e-", - "\ -TOML parse error at line 1, column 10 - | -1 | a = 0.0e- - | ^ -invalid floating-point number -" - ); - bad!( - "a = 0.0e+", - "\ -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] @@ -638,257 +569,186 @@ fn bare_key_names() { #[test] fn bad_keys() { - bad!( - "key\n=3", - "\ -TOML parse error at line 1, column 4 - | -1 | key - | ^ -expected `.`, `=` -" - ); - bad!( - "key=\n3", - "\ -TOML parse error at line 1, column 5 - | -1 | key= - | ^ -invalid string -expected `\"`, `'` -" - ); - bad!( - "key|=3", - "\ -TOML parse error at line 1, column 4 - | -1 | key|=3 - | ^ -expected `.`, `=` -" - ); - bad!( - "=3", - "\ -TOML parse error at line 1, column 1 - | -1 | =3 - | ^ -invalid key -" - ); - bad!( - "\"\"|=3", - "\ -TOML parse error at line 1, column 3 - | -1 | \"\"|=3 - | ^ -expected `.`, `=` -" - ); - bad!( - "\"\n\"|=3", - "\ -TOML parse error at line 1, column 2 - | -1 | \" - | ^ -invalid basic string -" - ); - bad!( - "\"\r\"|=3", - "\ -TOML parse error at line 1, column 2 - | -1 | \"\r\"|=3 - | ^ -invalid basic string -" - ); - bad!( - "''''''=3", - "\ -TOML parse error at line 1, column 3 - | -1 | ''''''=3 - | ^ -expected `.`, `=` -" - ); - bad!( - "\"\"\"\"\"\"=3", - "\ -TOML parse error at line 1, column 3 - | -1 | \"\"\"\"\"\"=3 - | ^ -expected `.`, `=` -" - ); - bad!( - "'''key'''=3", - "\ -TOML parse error at line 1, column 3 - | -1 | '''key'''=3 - | ^ -expected `.`, `=` -" - ); - bad!( - "\"\"\"key\"\"\"=3", - "\ -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!( - "[]", - "\ -TOML parse error at line 1, column 2 - | -1 | [] - | ^ -invalid key -" - ); - bad!( - "[.]", - "\ -TOML parse error at line 1, column 2 - | -1 | [.] - | ^ -invalid key -" - ); - bad!( - "[a.]", - "\ -TOML parse error at line 1, column 3 - | -1 | [a.] - | ^ -invalid table header -expected `.`, `]` -" - ); - bad!( - "[!]", - "\ -TOML parse error at line 1, column 2 - | -1 | [!] - | ^ -invalid key -" - ); - bad!( - "[\"\n\"]", - "\ -TOML parse error at line 1, column 3 - | -1 | [\" - | ^ -invalid basic string -" - ); - bad!( - "[a.b]\n[a.\"b\"]", - "\ -TOML parse error at line 2, column 1 - | -2 | [a.\"b\"] - | ^ -invalid table header -duplicate key `b` in table `a` -" - ); - bad!( - "[']", - "\ -TOML parse error at line 1, column 4 - | -1 | ['] - | ^ -invalid literal string -" - ); - bad!( - "[''']", - "\ -TOML parse error at line 1, column 4 - | -1 | ['''] - | ^ -invalid table header -expected `.`, `]` -" - ); - bad!( - "['''''']", - "\ -TOML parse error at line 1, column 4 - | -1 | [''''''] - | ^ -invalid table header -expected `.`, `]` -" - ); - bad!( - "['''foo''']", - "\ -TOML parse error at line 1, column 4 - | -1 | ['''foo'''] - | ^ -invalid table header -expected `.`, `]` -" - ); - bad!( - "[\"\"\"bar\"\"\"]", - "\ -TOML parse error at line 1, column 4 - | -1 | [\"\"\"bar\"\"\"] - | ^ -invalid table header -expected `.`, `]` -" - ); - bad!( - "['\n']", - "\ -TOML parse error at line 1, column 3 - | -1 | [' - | ^ -invalid literal string -" - ); - bad!( - "['\r\n']", - "\ -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] @@ -913,16 +773,13 @@ fn table_names() { #[test] fn invalid_bare_numeral() { - bad!( - "4", - "\ -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] @@ -933,60 +790,45 @@ fn inline_tables() { "a = {a=1,b=2}".parse::().unwrap(); "a = {a=1,b=2,c={}}".parse::().unwrap(); - bad!( - "a = {a=1,}", - "\ -TOML parse error at line 1, column 9 - | -1 | a = {a=1,} - | ^ -invalid inline table -expected `}` -" - ); - bad!( - "a = {,}", - "\ -TOML parse error at line 1, column 6 - | -1 | a = {,} - | ^ -invalid inline table -expected `}` -" - ); - bad!( - "a = {a=1,a=1}", - "\ -TOML parse error at line 1, column 6 - | -1 | a = {a=1,a=1} - | ^ -duplicate key `a` -" - ); - bad!( - "a = {\n}", - "\ -TOML parse error at line 1, column 6 - | -1 | a = { - | ^ -invalid inline table -expected `}` -" - ); - bad!( - "a = {", - "\ -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(); @@ -1012,107 +854,80 @@ fn number_underscores() { #[test] fn bad_underscores() { - bad!( - "foo = 0_", - "\ -TOML parse error at line 1, column 8 - | -1 | foo = 0_ - | ^ -expected newline, `#` -" - ); - bad!( - "foo = 0__0", - "\ -TOML parse error at line 1, column 8 - | -1 | foo = 0__0 - | ^ -expected newline, `#` -" - ); - bad!( - "foo = __0", - "\ -TOML parse error at line 1, column 7 - | -1 | foo = __0 - | ^ -invalid integer -expected leading digit -" - ); - bad!( - "foo = 1_0_", - "\ -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\"", - "\ -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\"", - "\ -TOML parse error at line 1, column 10 - | -1 | foo = \"\\uxx\" - | ^ -invalid unicode 4-digit hex code -" - ); - bad!( - "foo = \"\\u\"", - "\ -TOML parse error at line 1, column 10 - | -1 | foo = \"\\u\" - | ^ -invalid unicode 4-digit hex code -" - ); - bad!( - "foo = \"\\", - "\ -TOML parse error at line 1, column 8 - | -1 | foo = \"\\ - | ^ -invalid basic string -" - ); - bad!( - "foo = '", - "\ -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] @@ -1133,48 +948,36 @@ fn booleans() { let table = "foo = false".parse::().unwrap(); assert_eq!(table["foo"].as_bool(), Some(false)); - bad!( - "foo = true2", - "\ -TOML parse error at line 1, column 11 - | -1 | foo = true2 - | ^ -expected newline, `#` -" - ); - bad!( - "foo = false2", - "\ -TOML parse error at line 1, column 12 - | -1 | foo = false2 - | ^ -expected newline, `#` -" - ); - bad!( - "foo = t1", - "\ -TOML parse error at line 1, column 7 - | -1 | foo = t1 - | ^ -invalid string -expected `\"`, `'` -" - ); - bad!( - "foo = f2", - "\ -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] @@ -1185,56 +988,56 @@ fn bad_nesting() { [[a]] b = 5 ", - "\ -TOML parse error at line 3, column 9 - | -3 | [[a]] - | ^ -invalid table header -duplicate key `a` in document root -" + 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] ", - "\ -TOML parse error at line 3, column 9 - | -3 | [a.b] - | ^ -invalid table header -dotted key `a` attempted to extend non-table type (integer) -" + 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] ", - "\ -TOML parse error at line 3, column 9 - | -3 | [a.b] - | ^ -invalid table header -dotted key `a` attempted to extend non-table type (array) -" + 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]] ", - "\ -TOML parse error at line 3, column 9 - | -3 | [[a.b]] - | ^ -invalid table header -dotted key `a` attempted to extend non-table type (array) -" + 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 +1046,14 @@ dotted key `a` attempted to extend non-table type (array) [a.b] c = 2 ", - "\ -TOML parse error at line 4, column 9 - | -4 | [a.b] - | ^ -invalid table header -duplicate key `b` in table `a` -" + str![[r#" + TOML parse error at line 4, column 9 + | + 4 | [a.b] + | ^ + invalid table header + duplicate key `b` in table `a` + "#]] ); } @@ -1264,14 +1067,14 @@ fn bad_table_redefine() { foo=\"bar\" [a] ", - "\ -TOML parse error at line 6, column 9 - | -6 | [a] - | ^ -invalid table header -duplicate key `a` in document root -" + str![[r#" + TOML parse error at line 6, column 9 + | + 6 | [a] + | ^ + invalid table header + duplicate key `a` in document root + "#]] ); bad!( " @@ -1280,14 +1083,14 @@ duplicate key `a` in document root b = { foo = \"bar\" } [a] ", - "\ -TOML parse error at line 5, column 9 - | -5 | [a] - | ^ -invalid table header -duplicate key `a` in document root -" + str![[r#" + TOML parse error at line 5, column 9 + | + 5 | [a] + | ^ + invalid table header + duplicate key `a` in document root + "#]] ); bad!( " @@ -1295,14 +1098,14 @@ duplicate key `a` in document root b = {} [a.b] ", - "\ -TOML parse error at line 4, column 9 - | -4 | [a.b] - | ^ -invalid table header -duplicate key `b` in table `a` -" + 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 +1114,14 @@ duplicate key `b` in table `a` b = {} [a] ", - "\ -TOML parse error at line 4, column 9 - | -4 | [a] - | ^ -invalid table header -duplicate key `a` in document root -" + str![[r#" + TOML parse error at line 4, column 9 + | + 4 | [a] + | ^ + invalid table header + duplicate key `a` in document root + "#]] ); } @@ -1336,80 +1139,63 @@ 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", - "\ -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", - "\ -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", - "\ -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", - "\ -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", - "\ -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", - "\ -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""" "#, - r#"TOML parse error at line 2, column 5 - | -2 | 0=""o=""m=""r=""00="0"q="""0"""e="""0""" - | ^ -expected newline, `#` -"# + 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 +1204,49 @@ expected newline, `#` 0="0"[[0000l0]] 0="0"l="0" "#, - r#"TOML parse error at line 3, column 6 - | -3 | 0="0"[[0000l0]] - | ^ -expected newline, `#` -"# + 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 - | -2 | 0=[0]00=[0,0,0]t=["0","0","0"]s=[1000-00-00T00:00:00Z,2000-00-00T00:00:00Z] - | ^ -expected newline, `#` -"# + 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 - | -2 | 0=0r0=0r=false - | ^ -expected newline, `#` -"# + 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 - | -2 | 0=0r0=0r=falsefal=false - | ^ -expected newline, `#` -"# + str![[r#" + TOML parse error at line 2, column 4 + | + 2 | 0=0r0=0r=falsefal=false + | ^ + expected newline, `#` + "#]] ); } @@ -1473,7 +1263,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 +1296,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()); }