diff --git a/src/key.rs b/src/key.rs index 0ffb37de..c9993499 100644 --- a/src/key.rs +++ b/src/key.rs @@ -158,11 +158,7 @@ impl FromStr for Key { /// if fails, tries as basic quoted key (surrounds with "") /// and then literal quoted key (surrounds with '') fn from_str(s: &str) -> Result { - let basic = format!("\"{}\"", s); - let literal = format!("'{}'", s); Key::try_parse(s) - .or_else(|_| Key::try_parse(&basic)) - .or_else(|_| Key::try_parse(&literal)) } } diff --git a/src/parser/table.rs b/src/parser/table.rs index 506ba519..b05edfb6 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -31,7 +31,7 @@ const ARRAY_TABLE_CLOSE: &[u8] = b"]]"; toml_parser!(std_table, parser, { ( between(byte(STD_TABLE_OPEN), byte(STD_TABLE_CLOSE), key()), - line_trailing().and_then(|t| std::str::from_utf8(t)), + line_trailing().and_then(std::str::from_utf8), ) .and_then(|(h, t)| parser.borrow_mut().deref_mut().on_std_header(h, t)) }); @@ -42,7 +42,7 @@ toml_parser!(std_table, parser, { toml_parser!(array_table, parser, { ( between(range(ARRAY_TABLE_OPEN), range(ARRAY_TABLE_CLOSE), key()), - line_trailing().and_then(|t| std::str::from_utf8(t)), + line_trailing().and_then(std::str::from_utf8), ) .and_then(|(h, t)| parser.borrow_mut().deref_mut().on_array_header(h, t)) }); diff --git a/tests/easy_encoder.rs b/tests/easy_encoder.rs index 47c3e170..01849072 100644 --- a/tests/easy_encoder.rs +++ b/tests/easy_encoder.rs @@ -82,5 +82,5 @@ fn from_table( fn from_array( decoded: &[toml_test_harness::Decoded], ) -> Result { - decoded.iter().map(|v| from_decoded(v)).collect() + decoded.iter().map(from_decoded).collect() } diff --git a/tests/encoder.rs b/tests/encoder.rs index 99bc0271..172d348f 100644 --- a/tests/encoder.rs +++ b/tests/encoder.rs @@ -106,5 +106,5 @@ fn from_table( fn from_array( decoded: &[toml_test_harness::Decoded], ) -> Result { - decoded.iter().map(|v| from_decoded(v)).collect() + decoded.iter().map(from_decoded).collect() } diff --git a/tests/test_parse.rs b/tests/test_parse.rs index 7d03b0e3..231d3feb 100644 --- a/tests/test_parse.rs +++ b/tests/test_parse.rs @@ -3,7 +3,7 @@ use toml_edit::{Key, Value}; macro_rules! parse { ($s:expr, $ty:ty) => {{ let v = $s.parse::<$ty>(); - assert!(v.is_ok()); + assert!(v.is_ok(), "Failed with {}", v.unwrap_err()); v.unwrap() }}; } @@ -17,7 +17,7 @@ macro_rules! parse_value { macro_rules! test_key { ($s:expr, $expected:expr) => {{ let key = parse!($s, Key); - assert_eq!(key.get(), $expected); + assert_eq!(key.get(), $expected, ""); }}; } @@ -26,7 +26,11 @@ macro_rules! parse_error { let res = $input.parse::<$ty>(); assert!(res.is_err()); let err = res.unwrap_err(); - assert!(err.to_string().find($err_msg).is_some()); + assert!( + err.to_string().find($err_msg).is_some(), + "Error was: `{:?}`", + err.to_string() + ); }}; } @@ -35,7 +39,7 @@ fn test_parse_error() { parse_error!("'hello'bla", Value, "Could not parse the line"); parse_error!(r#"{a = 2"#, Value, "Expected `}`"); - parse_error!("'\"", Key, "Could not parse the line"); + parse_error!("'\"", Key, "Expected `'`"); } #[test] @@ -46,10 +50,12 @@ fn test_key_from_str() { r#""Jos\u00E9\U000A0000\n\t\r\f\b\"""#, "Jos\u{00E9}\u{A0000}\n\t\r\u{c}\u{8}\"" ); - test_key!("", ""); - test_key!("'hello key'bla", "'hello key'bla"); - let wp = "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\cargo-edit-test.YizxPxxElXn9"; - test_key!(wp, wp); + test_key!("\"\"", ""); + test_key!("\"'hello key'bla\"", "'hello key'bla"); + test_key!( + "'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\cargo-edit-test.YizxPxxElXn9'", + "C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\cargo-edit-test.YizxPxxElXn9" + ); } #[test]