From 1b016589133e48d34dd5ae1b440581ded4cb4cdb Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 8 May 2019 12:12:14 -0700 Subject: Migrate to 2018 edition. --- test-suite/Cargo.toml | 1 + test-suite/tests/macros.rs | 4 ++++ test-suite/tests/serde.rs | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) (limited to 'test-suite') diff --git a/test-suite/Cargo.toml b/test-suite/Cargo.toml index 10ffbcb..fa81741 100644 --- a/test-suite/Cargo.toml +++ b/test-suite/Cargo.toml @@ -4,6 +4,7 @@ version = "0.0.0" authors = ["Alex Crichton "] build = "build.rs" publish = false +edition = "2018" [build-dependencies] rustc_version = "0.2" diff --git a/test-suite/tests/macros.rs b/test-suite/tests/macros.rs index 6b77c81..db94549 100644 --- a/test-suite/tests/macros.rs +++ b/test-suite/tests/macros.rs @@ -7,6 +7,8 @@ use std::f64; macro_rules! table { ($($key:expr => $value:expr,)*) => {{ + // https://github.com/rust-lang/rust/issues/60643 + #[allow(unused_mut)] let mut table = toml::value::Table::new(); $( table.insert($key.to_string(), $value.into()); @@ -17,6 +19,8 @@ macro_rules! table { macro_rules! array { ($($element:expr,)*) => {{ + // https://github.com/rust-lang/rust/issues/60643 + #[allow(unused_mut)] let mut array = toml::value::Array::new(); $( array.push($element.into()); diff --git a/test-suite/tests/serde.rs b/test-suite/tests/serde.rs index 9bbf7e0..c72bfc6 100644 --- a/test-suite/tests/serde.rs +++ b/test-suite/tests/serde.rs @@ -130,7 +130,7 @@ fn application_decode_error() { struct Range10(usize); impl<'de> Deserialize<'de> for Range10 { fn deserialize>(d: D) -> Result { - let x: usize = try!(Deserialize::deserialize(d)); + let x: usize = Deserialize::deserialize(d)?; if x > 10 { Err(serde::de::Error::custom("more than 10")) } else { -- cgit v1.2.3 From 0fca4dd2d30a2044af454cf55211e67cf76f333c Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 8 May 2019 17:45:39 -0700 Subject: cargo fmt --- test-suite/tests/backcompat.rs | 7 +- test-suite/tests/display-tricky.rs | 23 +- test-suite/tests/display.rs | 171 ++++++++------- test-suite/tests/float.rs | 9 +- test-suite/tests/formatting.rs | 44 ++-- test-suite/tests/invalid.rs | 243 +++++++++++++-------- test-suite/tests/parser.rs | 243 ++++++++++++++------- test-suite/tests/pretty.rs | 26 ++- test-suite/tests/serde.rs | 147 ++++++++----- test-suite/tests/spanned.rs | 21 +- test-suite/tests/tables-last.rs | 4 +- test-suite/tests/valid.rs | 429 +++++++++++++++++++++++-------------- 12 files changed, 847 insertions(+), 520 deletions(-) (limited to 'test-suite') diff --git a/test-suite/tests/backcompat.rs b/test-suite/tests/backcompat.rs index e06eefc..53cda69 100644 --- a/test-suite/tests/backcompat.rs +++ b/test-suite/tests/backcompat.rs @@ -1,5 +1,5 @@ -extern crate toml; extern crate serde; +extern crate toml; use serde::de::Deserialize; @@ -35,7 +35,10 @@ fn allow_duplicate_after_longer() { let mut d = toml::de::Deserializer::new(s); d.set_allow_duplicate_after_longer_table(true); let value = toml::Value::deserialize(&mut d).unwrap(); - assert_eq!(value["dependencies"]["openssl-sys"]["version"].as_integer(), Some(1)); + assert_eq!( + value["dependencies"]["openssl-sys"]["version"].as_integer(), + Some(1) + ); assert_eq!(value["dependencies"]["libc"].as_integer(), Some(1)); assert_eq!(value["dependencies"]["bitflags"].as_integer(), Some(1)); } diff --git a/test-suite/tests/display-tricky.rs b/test-suite/tests/display-tricky.rs index 069e0f9..0daa10e 100644 --- a/test-suite/tests/display-tricky.rs +++ b/test-suite/tests/display-tricky.rs @@ -1,5 +1,6 @@ extern crate toml; -#[macro_use] extern crate serde_derive; +#[macro_use] +extern crate serde_derive; #[derive(Debug, Serialize, Deserialize)] pub struct Recipe { @@ -8,41 +9,47 @@ pub struct Recipe { #[serde(default)] pub modules: Vec, #[serde(default)] - pub packages: Vec + pub packages: Vec, } #[derive(Debug, Serialize, Deserialize)] pub struct Modules { pub name: String, - pub version: Option + pub version: Option, } #[derive(Debug, Serialize, Deserialize)] pub struct Packages { pub name: String, - pub version: Option + pub version: Option, } #[test] fn both_ends() { - let recipe_works = toml::from_str::(r#" + let recipe_works = toml::from_str::( + r#" name = "testing" description = "example" modules = [] [[packages]] name = "base" - "#).unwrap(); + "#, + ) + .unwrap(); toml::to_string(&recipe_works).unwrap(); - let recipe_fails = toml::from_str::(r#" + let recipe_fails = toml::from_str::( + r#" name = "testing" description = "example" packages = [] [[modules]] name = "base" - "#).unwrap(); + "#, + ) + .unwrap(); let recipe_toml = toml::Value::try_from(recipe_fails).unwrap(); recipe_toml.to_string(); diff --git a/test-suite/tests/display.rs b/test-suite/tests/display.rs index 0174de1..5d9f44a 100644 --- a/test-suite/tests/display.rs +++ b/test-suite/tests/display.rs @@ -1,7 +1,7 @@ extern crate toml; -use toml::Value::{String, Integer, Float, Boolean, Array, Table}; use toml::map::Map; +use toml::Value::{Array, Boolean, Float, Integer, String, Table}; macro_rules! map( ($($k:expr => $v:expr),*) => ({ let mut _m = Map::new(); @@ -11,76 +11,86 @@ macro_rules! map( ($($k:expr => $v:expr),*) => ({ #[test] fn simple_show() { - assert_eq!(String("foo".to_string()).to_string(), - "\"foo\""); - assert_eq!(Integer(10).to_string(), - "10"); - assert_eq!(Float(10.0).to_string(), - "10.0"); - assert_eq!(Float(2.4).to_string(), - "2.4"); - assert_eq!(Boolean(true).to_string(), - "true"); - assert_eq!(Array(vec![]).to_string(), - "[]"); - assert_eq!(Array(vec![Integer(1), Integer(2)]).to_string(), - "[1, 2]"); + assert_eq!(String("foo".to_string()).to_string(), "\"foo\""); + assert_eq!(Integer(10).to_string(), "10"); + assert_eq!(Float(10.0).to_string(), "10.0"); + assert_eq!(Float(2.4).to_string(), "2.4"); + assert_eq!(Boolean(true).to_string(), "true"); + assert_eq!(Array(vec![]).to_string(), "[]"); + assert_eq!(Array(vec![Integer(1), Integer(2)]).to_string(), "[1, 2]"); } #[test] fn table() { - assert_eq!(Table(map! { }).to_string(), - ""); - assert_eq!(Table(map! { - "test" => Integer(2), - "test2" => Integer(3) }).to_string(), - "test = 2\ntest2 = 3\n"); - assert_eq!(Table(map! { - "test" => Integer(2), - "test2" => Table(map! { - "test" => String("wut".to_string()) - }) - }).to_string(), - "test = 2\n\ - \n\ - [test2]\n\ - test = \"wut\"\n"); - assert_eq!(Table(map! { - "test" => Integer(2), - "test2" => Table(map! { - "test" => String("wut".to_string()) - }) - }).to_string(), - "test = 2\n\ - \n\ - [test2]\n\ - test = \"wut\"\n"); - assert_eq!(Table(map! { - "test" => Integer(2), - "test2" => Array(vec![Table(map! { - "test" => String("wut".to_string()) - })]) - }).to_string(), - "test = 2\n\ - \n\ - [[test2]]\n\ - test = \"wut\"\n"); - assert_eq!(Table(map! { - "foo.bar" => Integer(2), - "foo\"bar" => Integer(2) - }).to_string(), - "\"foo\\\"bar\" = 2\n\ - \"foo.bar\" = 2\n"); - assert_eq!(Table(map! { - "test" => Integer(2), - "test2" => Array(vec![Table(map! { - "test" => Array(vec![Integer(2)]) - })]) - }).to_string(), - "test = 2\n\ - \n\ - [[test2]]\n\ - test = [2]\n"); + assert_eq!(Table(map! {}).to_string(), ""); + assert_eq!( + Table(map! { + "test" => Integer(2), + "test2" => Integer(3) }) + .to_string(), + "test = 2\ntest2 = 3\n" + ); + assert_eq!( + Table(map! { + "test" => Integer(2), + "test2" => Table(map! { + "test" => String("wut".to_string()) + }) + }) + .to_string(), + "test = 2\n\ + \n\ + [test2]\n\ + test = \"wut\"\n" + ); + assert_eq!( + Table(map! { + "test" => Integer(2), + "test2" => Table(map! { + "test" => String("wut".to_string()) + }) + }) + .to_string(), + "test = 2\n\ + \n\ + [test2]\n\ + test = \"wut\"\n" + ); + assert_eq!( + Table(map! { + "test" => Integer(2), + "test2" => Array(vec![Table(map! { + "test" => String("wut".to_string()) + })]) + }) + .to_string(), + "test = 2\n\ + \n\ + [[test2]]\n\ + test = \"wut\"\n" + ); + assert_eq!( + Table(map! { + "foo.bar" => Integer(2), + "foo\"bar" => Integer(2) + }) + .to_string(), + "\"foo\\\"bar\" = 2\n\ + \"foo.bar\" = 2\n" + ); + assert_eq!( + Table(map! { + "test" => Integer(2), + "test2" => Array(vec![Table(map! { + "test" => Array(vec![Integer(2)]) + })]) + }) + .to_string(), + "test = 2\n\ + \n\ + [[test2]]\n\ + test = [2]\n" + ); let table = Table(map! { "test" => Integer(2), "test2" => Array(vec![Table(map! { @@ -88,15 +98,20 @@ fn table() { Array(vec![String("foo".to_string()), String("bar".to_string())])]) })]) }); - assert_eq!(table.to_string(), - "test = 2\n\ - \n\ - [[test2]]\n\ - test = [[2, 3], [\"foo\", \"bar\"]]\n"); - assert_eq!(Table(map! { - "test" => Array(vec![Integer(2)]), - "test2" => Integer(2) - }).to_string(), - "test = [2]\n\ - test2 = 2\n"); + assert_eq!( + table.to_string(), + "test = 2\n\ + \n\ + [[test2]]\n\ + test = [[2, 3], [\"foo\", \"bar\"]]\n" + ); + assert_eq!( + Table(map! { + "test" => Array(vec![Integer(2)]), + "test2" => Integer(2) + }) + .to_string(), + "test = [2]\n\ + test2 = 2\n" + ); } diff --git a/test-suite/tests/float.rs b/test-suite/tests/float.rs index 6590fe4..5ce99c8 100644 --- a/test-suite/tests/float.rs +++ b/test-suite/tests/float.rs @@ -32,7 +32,9 @@ macro_rules! float_inf_tests { # zero sf7 = +0.0 sf8 = -0.0 - ").expect("Parse infinities."); + ", + ) + .expect("Parse infinities."); assert!(inf.sf1.is_infinite()); assert!(inf.sf1.is_sign_positive()); @@ -55,8 +57,9 @@ macro_rules! float_inf_tests { let s = toml::to_string(&inf).unwrap(); assert_eq!( - s, "\ -sf1 = inf + s, + "\ + sf1 = inf sf2 = inf sf3 = -inf sf4 = nan diff --git a/test-suite/tests/formatting.rs b/test-suite/tests/formatting.rs index 4ba1418..8e15ec2 100644 --- a/test-suite/tests/formatting.rs +++ b/test-suite/tests/formatting.rs @@ -24,31 +24,33 @@ struct TwoUsers { #[test] fn no_unnecessary_newlines_array() { assert!(!to_string(&Users { - user: vec![ - User { - name: "John".to_string(), - surname: "Doe".to_string(), - }, - User { - name: "Jane".to_string(), - surname: "Dough".to_string(), - }, - ], - }).unwrap() - .starts_with("\n")); -} - -#[test] -fn no_unnecessary_newlines_table() { - assert!(!to_string(&TwoUsers { - user0: User { + user: vec![ + User { name: "John".to_string(), surname: "Doe".to_string(), }, - user1: User { + User { name: "Jane".to_string(), surname: "Dough".to_string(), }, - }).unwrap() - .starts_with("\n")); + ], + }) + .unwrap() + .starts_with("\n")); +} + +#[test] +fn no_unnecessary_newlines_table() { + assert!(!to_string(&TwoUsers { + user0: User { + name: "John".to_string(), + surname: "Doe".to_string(), + }, + user1: User { + name: "Jane".to_string(), + surname: "Dough".to_string(), + }, + }) + .unwrap() + .starts_with("\n")); } diff --git a/test-suite/tests/invalid.rs b/test-suite/tests/invalid.rs index 7ac17d5..275e385 100644 --- a/test-suite/tests/invalid.rs +++ b/test-suite/tests/invalid.rs @@ -12,93 +12,156 @@ macro_rules! test( ($name:ident, $toml:expr) => ( fn $name() { run($toml); } ) ); -test!(array_mixed_types_arrays_and_ints, - include_str!("invalid/array-mixed-types-arrays-and-ints.toml")); -test!(array_mixed_types_ints_and_floats, - include_str!("invalid/array-mixed-types-ints-and-floats.toml")); -test!(array_mixed_types_strings_and_ints, - include_str!("invalid/array-mixed-types-strings-and-ints.toml")); -test!(datetime_malformed_no_leads, - include_str!("invalid/datetime-malformed-no-leads.toml")); -test!(datetime_malformed_no_secs, - include_str!("invalid/datetime-malformed-no-secs.toml")); -test!(datetime_malformed_no_t, - include_str!("invalid/datetime-malformed-no-t.toml")); -test!(datetime_malformed_with_milli, - include_str!("invalid/datetime-malformed-with-milli.toml")); -test!(duplicate_key_table, - include_str!("invalid/duplicate-key-table.toml")); -test!(duplicate_keys, - include_str!("invalid/duplicate-keys.toml")); -test!(duplicate_table, - include_str!("invalid/duplicate-table.toml")); -test!(duplicate_tables, - include_str!("invalid/duplicate-tables.toml")); -test!(empty_implicit_table, - include_str!("invalid/empty-implicit-table.toml")); -test!(empty_table, - include_str!("invalid/empty-table.toml")); -test!(float_no_leading_zero, - include_str!("invalid/float-no-leading-zero.toml")); -test!(float_no_suffix, - include_str!("invalid/float-no-suffix.toml")); -test!(float_no_trailing_digits, - include_str!("invalid/float-no-trailing-digits.toml")); -test!(key_after_array, - include_str!("invalid/key-after-array.toml")); -test!(key_after_table, - include_str!("invalid/key-after-table.toml")); -test!(key_empty, - include_str!("invalid/key-empty.toml")); -test!(key_hash, - include_str!("invalid/key-hash.toml")); -test!(key_newline, - include_str!("invalid/key-newline.toml")); -test!(key_open_bracket, - include_str!("invalid/key-open-bracket.toml")); -test!(key_single_open_bracket, - include_str!("invalid/key-single-open-bracket.toml")); -test!(key_space, - include_str!("invalid/key-space.toml")); -test!(key_start_bracket, - include_str!("invalid/key-start-bracket.toml")); -test!(key_two_equals, - include_str!("invalid/key-two-equals.toml")); -test!(string_bad_byte_escape, - include_str!("invalid/string-bad-byte-escape.toml")); -test!(string_bad_escape, - include_str!("invalid/string-bad-escape.toml")); -test!(string_bad_line_ending_escape, - include_str!("invalid/string-bad-line-ending-escape.toml")); -test!(string_byte_escapes, - include_str!("invalid/string-byte-escapes.toml")); -test!(string_no_close, - include_str!("invalid/string-no-close.toml")); -test!(table_array_implicit, - include_str!("invalid/table-array-implicit.toml")); -test!(table_array_malformed_bracket, - include_str!("invalid/table-array-malformed-bracket.toml")); -test!(table_array_malformed_empty, - include_str!("invalid/table-array-malformed-empty.toml")); -test!(table_empty, - include_str!("invalid/table-empty.toml")); -test!(table_nested_brackets_close, - include_str!("invalid/table-nested-brackets-close.toml")); -test!(table_nested_brackets_open, - include_str!("invalid/table-nested-brackets-open.toml")); -test!(table_whitespace, - include_str!("invalid/table-whitespace.toml")); -test!(table_with_pound, - include_str!("invalid/table-with-pound.toml")); -test!(text_after_array_entries, - include_str!("invalid/text-after-array-entries.toml")); -test!(text_after_integer, - include_str!("invalid/text-after-integer.toml")); -test!(text_after_string, - include_str!("invalid/text-after-string.toml")); -test!(text_after_table, - include_str!("invalid/text-after-table.toml")); -test!(text_before_array_separator, - include_str!("invalid/text-before-array-separator.toml")); -test!(text_in_array, - include_str!("invalid/text-in-array.toml")); +test!( + array_mixed_types_arrays_and_ints, + include_str!("invalid/array-mixed-types-arrays-and-ints.toml") +); +test!( + array_mixed_types_ints_and_floats, + include_str!("invalid/array-mixed-types-ints-and-floats.toml") +); +test!( + array_mixed_types_strings_and_ints, + include_str!("invalid/array-mixed-types-strings-and-ints.toml") +); +test!( + datetime_malformed_no_leads, + include_str!("invalid/datetime-malformed-no-leads.toml") +); +test!( + datetime_malformed_no_secs, + include_str!("invalid/datetime-malformed-no-secs.toml") +); +test!( + datetime_malformed_no_t, + include_str!("invalid/datetime-malformed-no-t.toml") +); +test!( + datetime_malformed_with_milli, + include_str!("invalid/datetime-malformed-with-milli.toml") +); +test!( + duplicate_key_table, + include_str!("invalid/duplicate-key-table.toml") +); +test!(duplicate_keys, include_str!("invalid/duplicate-keys.toml")); +test!( + duplicate_table, + include_str!("invalid/duplicate-table.toml") +); +test!( + duplicate_tables, + include_str!("invalid/duplicate-tables.toml") +); +test!( + empty_implicit_table, + include_str!("invalid/empty-implicit-table.toml") +); +test!(empty_table, include_str!("invalid/empty-table.toml")); +test!( + float_no_leading_zero, + include_str!("invalid/float-no-leading-zero.toml") +); +test!( + float_no_suffix, + include_str!("invalid/float-no-suffix.toml") +); +test!( + float_no_trailing_digits, + include_str!("invalid/float-no-trailing-digits.toml") +); +test!( + key_after_array, + include_str!("invalid/key-after-array.toml") +); +test!( + key_after_table, + include_str!("invalid/key-after-table.toml") +); +test!(key_empty, include_str!("invalid/key-empty.toml")); +test!(key_hash, include_str!("invalid/key-hash.toml")); +test!(key_newline, include_str!("invalid/key-newline.toml")); +test!( + key_open_bracket, + include_str!("invalid/key-open-bracket.toml") +); +test!( + key_single_open_bracket, + include_str!("invalid/key-single-open-bracket.toml") +); +test!(key_space, include_str!("invalid/key-space.toml")); +test!( + key_start_bracket, + include_str!("invalid/key-start-bracket.toml") +); +test!(key_two_equals, include_str!("invalid/key-two-equals.toml")); +test!( + string_bad_byte_escape, + include_str!("invalid/string-bad-byte-escape.toml") +); +test!( + string_bad_escape, + include_str!("invalid/string-bad-escape.toml") +); +test!( + string_bad_line_ending_escape, + include_str!("invalid/string-bad-line-ending-escape.toml") +); +test!( + string_byte_escapes, + include_str!("invalid/string-byte-escapes.toml") +); +test!( + string_no_close, + include_str!("invalid/string-no-close.toml") +); +test!( + table_array_implicit, + include_str!("invalid/table-array-implicit.toml") +); +test!( + table_array_malformed_bracket, + include_str!("invalid/table-array-malformed-bracket.toml") +); +test!( + table_array_malformed_empty, + include_str!("invalid/table-array-malformed-empty.toml") +); +test!(table_empty, include_str!("invalid/table-empty.toml")); +test!( + table_nested_brackets_close, + include_str!("invalid/table-nested-brackets-close.toml") +); +test!( + table_nested_brackets_open, + include_str!("invalid/table-nested-brackets-open.toml") +); +test!( + table_whitespace, + include_str!("invalid/table-whitespace.toml") +); +test!( + table_with_pound, + include_str!("invalid/table-with-pound.toml") +); +test!( + text_after_array_entries, + include_str!("invalid/text-after-array-entries.toml") +); +test!( + text_after_integer, + include_str!("invalid/text-after-integer.toml") +); +test!( + text_after_string, + include_str!("invalid/text-after-string.toml") +); +test!( + text_after_table, + include_str!("invalid/text-after-table.toml") +); +test!( + text_before_array_separator, + include_str!("invalid/text-before-array-separator.toml") +); +test!(text_in_array, include_str!("invalid/text-in-array.toml")); diff --git a/test-suite/tests/parser.rs b/test-suite/tests/parser.rs index 69b491d..56f559d 100644 --- a/test-suite/tests/parser.rs +++ b/test-suite/tests/parser.rs @@ -3,7 +3,7 @@ extern crate toml; use toml::Value; macro_rules! bad { - ($s:expr, $msg:expr) => ({ + ($s:expr, $msg:expr) => {{ match $s.parse::() { Ok(s) => panic!("successfully parsed as {}", s), Err(e) => { @@ -11,29 +11,31 @@ macro_rules! bad { assert!(e.contains($msg), "error: {}", e); } } - }) + }}; } #[test] fn crlf() { "\ -[project]\r\n\ -\r\n\ -name = \"splay\"\r\n\ -version = \"0.1.0\"\r\n\ -authors = [\"alex@crichton.co\"]\r\n\ -\r\n\ -[[lib]]\r\n\ -\r\n\ -path = \"lib.rs\"\r\n\ -name = \"splay\"\r\n\ -description = \"\"\"\ -A Rust implementation of a TAR file reader and writer. This library does not\r\n\ -currently handle compression, but it is abstract over all I/O readers and\r\n\ -writers. Additionally, great lengths are taken to ensure that the entire\r\n\ -contents are never required to be entirely resident in memory all at once.\r\n\ -\"\"\"\ -".parse::().unwrap(); + [project]\r\n\ + \r\n\ + name = \"splay\"\r\n\ + version = \"0.1.0\"\r\n\ + authors = [\"alex@crichton.co\"]\r\n\ + \r\n\ + [[lib]]\r\n\ + \r\n\ + path = \"lib.rs\"\r\n\ + name = \"splay\"\r\n\ + description = \"\"\"\ + A Rust implementation of a TAR file reader and writer. This library does not\r\n\ + currently handle compression, but it is abstract over all I/O readers and\r\n\ + writers. Additionally, great lengths are taken to ensure that the entire\r\n\ + contents are never required to be entirely resident in memory all at once.\r\n\ + \"\"\"\ + " + .parse::() + .unwrap(); } #[test] @@ -71,7 +73,9 @@ trimmed in raw strings. All other whitespace is preserved. ''' -"#.parse::().unwrap(); +"# + .parse::() + .unwrap(); assert_eq!(table["bar"].as_str(), Some("\0")); assert_eq!(table["key1"].as_str(), Some("One\nTwo")); assert_eq!(table["key2"].as_str(), Some("One\nTwo")); @@ -82,16 +86,32 @@ is preserved. assert_eq!(table["key5"].as_str(), Some(msg)); assert_eq!(table["key6"].as_str(), Some(msg)); - assert_eq!(table["winpath"].as_str(), Some(r"C:\Users\nodejs\templates")); - assert_eq!(table["winpath2"].as_str(), Some(r"\\ServerX\admin$\system32\")); - assert_eq!(table["quoted"].as_str(), Some(r#"Tom "Dubs" Preston-Werner"#)); + assert_eq!( + table["winpath"].as_str(), + Some(r"C:\Users\nodejs\templates") + ); + assert_eq!( + table["winpath2"].as_str(), + Some(r"\\ServerX\admin$\system32\") + ); + assert_eq!( + table["quoted"].as_str(), + Some(r#"Tom "Dubs" Preston-Werner"#) + ); assert_eq!(table["regex"].as_str(), Some(r"<\i\c*\s*>")); - assert_eq!(table["regex2"].as_str(), Some(r"I [dw]on't need \d{2} apples")); - assert_eq!(table["lines"].as_str(), - Some("The first newline is\n\ - trimmed in raw strings.\n\ - All other whitespace\n\ - is preserved.\n")); + assert_eq!( + table["regex2"].as_str(), + Some(r"I [dw]on't need \d{2} apples") + ); + assert_eq!( + table["lines"].as_str(), + Some( + "The first newline is\n\ + trimmed in raw strings.\n\ + All other whitespace\n\ + is preserved.\n" + ) + ); } #[test] @@ -106,7 +126,9 @@ fn tables_in_arrays() { #… [foo.bar] #... -"#.parse::().unwrap(); +"# + .parse::() + .unwrap(); table["foo"][0]["bar"].as_table().unwrap(); table["foo"][1]["bar"].as_table().unwrap(); } @@ -114,7 +136,9 @@ fn tables_in_arrays() { #[test] fn empty_table() { let table = r#" -[foo]"#.parse::().unwrap(); +[foo]"# + .parse::() + .unwrap(); table["foo"].as_table().unwrap(); } @@ -139,14 +163,28 @@ name = "banana" [[fruit.variety]] name = "plantain" -"#.parse::().unwrap(); +"# + .parse::() + .unwrap(); assert_eq!(table["fruit"][0]["name"].as_str(), Some("apple")); assert_eq!(table["fruit"][0]["physical"]["color"].as_str(), Some("red")); - assert_eq!(table["fruit"][0]["physical"]["shape"].as_str(), Some("round")); - assert_eq!(table["fruit"][0]["variety"][0]["name"].as_str(), Some("red delicious")); - assert_eq!(table["fruit"][0]["variety"][1]["name"].as_str(), Some("granny smith")); + assert_eq!( + table["fruit"][0]["physical"]["shape"].as_str(), + Some("round") + ); + assert_eq!( + table["fruit"][0]["variety"][0]["name"].as_str(), + Some("red delicious") + ); + assert_eq!( + table["fruit"][0]["variety"][1]["name"].as_str(), + Some("granny smith") + ); assert_eq!(table["fruit"][1]["name"].as_str(), Some("banana")); - assert_eq!(table["fruit"][1]["variety"][0]["name"].as_str(), Some("plantain")); + assert_eq!( + table["fruit"][1]["variety"][0]["name"].as_str(), + Some("plantain") + ); } #[test] @@ -177,7 +215,9 @@ fn literal_eats_crlf() { let table = " foo = \"\"\"\\\r\n\"\"\" bar = \"\"\"\\\r\n \r\n \r\n a\"\"\" - ".parse::().unwrap(); + " + .parse::() + .unwrap(); assert_eq!(table["foo"].as_str(), Some("")); assert_eq!(table["bar"].as_str(), Some("a")); } @@ -215,12 +255,12 @@ fn bad_floats() { #[test] fn floats() { macro_rules! t { - ($actual:expr, $expected:expr) => ({ + ($actual:expr, $expected:expr) => {{ let f = format!("foo = {}", $actual); println!("{}", f); let a = f.parse::().unwrap(); assert_eq!(a["foo"].as_float().unwrap(), $expected); - }) + }}; } t!("1.0", 1.0); @@ -252,7 +292,9 @@ fn bare_key_names() { \"\\\"\" = 3 \"character encoding\" = \"value\" 'ʎǝʞ' = \"value\" - ".parse::().unwrap(); + " + .parse::() + .unwrap(); &a["foo"]; &a["-"]; &a["_"]; @@ -310,7 +352,9 @@ fn table_names() { [\"\\\"\"] ['a.a'] ['\"\"'] - ".parse::().unwrap(); + " + .parse::() + .unwrap(); println!("{:?}", a); &a["a"]["b"]; &a["f f"]; @@ -344,11 +388,11 @@ fn inline_tables() { #[test] fn number_underscores() { macro_rules! t { - ($actual:expr, $expected:expr) => ({ + ($actual:expr, $expected:expr) => {{ let f = format!("foo = {}", $actual); let table = f.parse::().unwrap(); assert_eq!(table["foo"].as_integer().unwrap(), $expected); - }) + }}; } t!("1_0", 10); @@ -381,11 +425,12 @@ fn bad_strings() { #[test] fn empty_string() { - assert_eq!("foo = \"\"".parse::() - .unwrap()["foo"] - .as_str() - .unwrap(), - ""); + assert_eq!( + "foo = \"\"".parse::().unwrap()["foo"] + .as_str() + .unwrap(), + "" + ); } #[test] @@ -404,67 +449,94 @@ fn booleans() { #[test] fn bad_nesting() { - bad!(" + bad!( + " a = [2] [[a]] b = 5 - ", "duplicate key: `a`"); - bad!(" + ", + "duplicate key: `a`" + ); + bad!( + " a = 1 [a.b] - ", "duplicate key: `a`"); - bad!(" + ", + "duplicate key: `a`" + ); + bad!( + " a = [] [a.b] - ", "duplicate key: `a`"); - bad!(" + ", + "duplicate key: `a`" + ); + bad!( + " a = [] [[a.b]] - ", "duplicate key: `a`"); - bad!(" + ", + "duplicate key: `a`" + ); + bad!( + " [a] b = { c = 2, d = {} } [a.b] c = 2 - ", "duplicate key: `b`"); + ", + "duplicate key: `b`" + ); } #[test] fn bad_table_redefine() { - bad!(" + bad!( + " [a] foo=\"bar\" [a.b] foo=\"bar\" [a] - ", "redefinition of table `a`"); - bad!(" + ", + "redefinition of table `a`" + ); + bad!( + " [a] foo=\"bar\" b = { foo = \"bar\" } [a] - ", "redefinition of table `a`"); - bad!(" + ", + "redefinition of table `a`" + ); + bad!( + " [a] b = {} [a.b] - ", "duplicate key: `b`"); + ", + "duplicate key: `b`" + ); - bad!(" + bad!( + " [a] b = {} [a] - ", "redefinition of table `a`"); + ", + "redefinition of table `a`" + ); } #[test] fn datetimes() { macro_rules! t { - ($actual:expr) => ({ + ($actual:expr) => {{ let f = format!("foo = {}", $actual); let toml = f.parse::().expect(&format!("failed: {}", f)); assert_eq!(toml["foo"].as_datetime().unwrap().to_string(), $actual); - }) + }}; } t!("2016-09-09T09:09:09Z"); @@ -481,22 +553,37 @@ fn datetimes() { #[test] fn require_newline_after_value() { bad!("0=0r=false", "invalid number at line 1"); - bad!(r#" + bad!( + r#" 0=""o=""m=""r=""00="0"q="""0"""e="""0""" -"#, "expected newline"); - bad!(r#" +"#, + "expected newline" + ); + bad!( + r#" [[0000l0]] 0="0"[[0000l0]] 0="0"[[0000l0]] 0="0"l="0" -"#, "expected newline"); - bad!(r#" +"#, + "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] -"#, "expected newline"); - bad!(r#" +"#, + "expected newline" + ); + bad!( + r#" 0=0r0=0r=false -"#, "invalid number at line 2"); - bad!(r#" +"#, + "invalid number at line 2" + ); + bad!( + r#" 0=0r0=0r=falsefal=false -"#, "invalid number at line 2"); +"#, + "invalid number at line 2" + ); } diff --git a/test-suite/tests/pretty.rs b/test-suite/tests/pretty.rs index 19ed22d..0c65e0f 100644 --- a/test-suite/tests/pretty.rs +++ b/test-suite/tests/pretty.rs @@ -1,5 +1,5 @@ -extern crate toml; extern crate serde; +extern crate toml; use serde::ser::Serialize; @@ -16,7 +16,9 @@ fn no_pretty() { let toml = NO_PRETTY; let value: toml::Value = toml::from_str(toml).unwrap(); let mut result = String::with_capacity(128); - value.serialize(&mut toml::Serializer::new(&mut result)).unwrap(); + value + .serialize(&mut toml::Serializer::new(&mut result)) + .unwrap(); println!("EXPECTED:\n{}", toml); println!("\nRESULT:\n{}", result); assert_eq!(toml, &result); @@ -58,13 +60,14 @@ fn pretty_std() { let toml = PRETTY_STD; let value: toml::Value = toml::from_str(toml).unwrap(); let mut result = String::with_capacity(128); - value.serialize(&mut toml::Serializer::pretty(&mut result)).unwrap(); + value + .serialize(&mut toml::Serializer::pretty(&mut result)) + .unwrap(); println!("EXPECTED:\n{}", toml); println!("\nRESULT:\n{}", result); assert_eq!(toml, &result); } - const PRETTY_INDENT_2: &'static str = "\ [example] array = [ @@ -110,7 +113,6 @@ oneline = \"this has no newlines.\" text = \"\\nthis is the first line\\nthis is the second line\\n\" "; - #[test] /// Test pretty indent when gotten the other way fn pretty_indent_2_other() { @@ -125,7 +127,6 @@ fn pretty_indent_2_other() { assert_eq!(toml, &result); } - const PRETTY_ARRAY_NO_COMMA: &'static str = "\ [example] array = [ @@ -150,7 +151,6 @@ fn pretty_indent_array_no_comma() { assert_eq!(toml, &result); } - const PRETTY_NO_STRING: &'static str = "\ [example] array = [ @@ -207,7 +207,9 @@ fn pretty_tricky() { let toml = PRETTY_TRICKY; let value: toml::Value = toml::from_str(toml).unwrap(); let mut result = String::with_capacity(128); - value.serialize(&mut toml::Serializer::pretty(&mut result)).unwrap(); + value + .serialize(&mut toml::Serializer::pretty(&mut result)) + .unwrap(); println!("EXPECTED:\n{}", toml); println!("\nRESULT:\n{}", result); assert_eq!(toml, &result); @@ -231,7 +233,9 @@ fn pretty_table_array() { let toml = PRETTY_TABLE_ARRAY; let value: toml::Value = toml::from_str(toml).unwrap(); let mut result = String::with_capacity(128); - value.serialize(&mut toml::Serializer::pretty(&mut result)).unwrap(); + value + .serialize(&mut toml::Serializer::pretty(&mut result)) + .unwrap(); println!("EXPECTED:\n{}", toml); println!("\nRESULT:\n{}", result); assert_eq!(toml, &result); @@ -255,7 +259,9 @@ fn table_array() { let toml = TABLE_ARRAY; let value: toml::Value = toml::from_str(toml).unwrap(); let mut result = String::with_capacity(128); - value.serialize(&mut toml::Serializer::new(&mut result)).unwrap(); + value + .serialize(&mut toml::Serializer::new(&mut result)) + .unwrap(); println!("EXPECTED:\n{}", toml); println!("\nRESULT:\n{}", result); assert_eq!(toml, &result); diff --git a/test-suite/tests/serde.rs b/test-suite/tests/serde.rs index c72bfc6..bf019d4 100644 --- a/test-suite/tests/serde.rs +++ b/test-suite/tests/serde.rs @@ -4,22 +4,24 @@ extern crate toml; #[macro_use] extern crate serde_derive; -use std::collections::{BTreeMap, HashSet}; use serde::{Deserialize, Deserializer}; +use std::collections::{BTreeMap, HashSet}; -use toml::Value; -use toml::Value::{Table, Integer, Array, Float}; use toml::map::Map; +use toml::Value; +use toml::Value::{Array, Float, Integer, Table}; macro_rules! t { - ($e:expr) => (match $e { - Ok(t) => t, - Err(e) => panic!("{} failed with {}", stringify!($e), e), - }) + ($e:expr) => { + match $e { + Ok(t) => t, + Err(e) => panic!("{} failed with {}", stringify!($e), e), + } + }; } macro_rules! equivalent { - ($literal:expr, $toml:expr,) => ({ + ($literal:expr, $toml:expr,) => {{ let toml = $toml; let literal = $literal; @@ -38,17 +40,16 @@ macro_rules! equivalent { assert_eq!(literal, t!(toml::from_str(&toml.to_string()))); println!("toml, from_str(toml)"); assert_eq!(toml, t!(toml::from_str(&toml.to_string()))); - }) + }}; } macro_rules! error { - ($ty:ty, $toml:expr, $error:expr) => ({ + ($ty:ty, $toml:expr, $error:expr) => {{ println!("attempting parsing"); match toml::from_str::<$ty>(&$toml.to_string()) { Ok(_) => panic!("successful"), Err(e) => { - assert!(e.to_string().contains($error), - "bad error: {}", e); + assert!(e.to_string().contains($error), "bad error: {}", e); } } @@ -56,11 +57,10 @@ macro_rules! error { match $toml.try_into::<$ty>() { Ok(_) => panic!("successful"), Err(e) => { - assert!(e.to_string().contains($error), - "bad error: {}", e); + assert!(e.to_string().contains($error), "bad error: {}", e); } } - }) + }}; } macro_rules! map( ($($k:ident: $v:expr),*) => ({ @@ -72,12 +72,11 @@ macro_rules! map( ($($k:ident: $v:expr),*) => ({ #[test] fn smoke() { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] - struct Foo { a: isize } + struct Foo { + a: isize, + } - equivalent!( - Foo { a: 2 }, - Table(map! { a: Integer(2) }), - ); + equivalent!(Foo { a: 2 }, Table(map! { a: Integer(2) }),); } #[test] @@ -109,9 +108,14 @@ fn smoke_hyphen() { #[test] fn nested() { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] - struct Foo { a: isize, b: Bar } + struct Foo { + a: isize, + b: Bar, + } #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] - struct Bar { a: String } + struct Bar { + a: String, + } equivalent! { Foo { a: 2, b: Bar { a: "test".to_string() } }, @@ -129,14 +133,14 @@ fn application_decode_error() { #[derive(PartialEq, Debug)] struct Range10(usize); impl<'de> Deserialize<'de> for Range10 { - fn deserialize>(d: D) -> Result { - let x: usize = Deserialize::deserialize(d)?; - if x > 10 { - Err(serde::de::Error::custom("more than 10")) - } else { - Ok(Range10(x)) - } - } + fn deserialize>(d: D) -> Result { + let x: usize = Deserialize::deserialize(d)?; + if x > 10 { + Err(serde::de::Error::custom("more than 10")) + } else { + Ok(Range10(x)) + } + } } let d_good = Integer(5); let d_bad1 = Value::String("not an isize".to_string()); @@ -153,7 +157,9 @@ fn application_decode_error() { #[test] fn array() { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] - struct Foo { a: Vec } + struct Foo { + a: Vec, + } equivalent! { Foo { a: vec![1, 2, 3, 4] }, @@ -239,9 +245,13 @@ fn hashmap() { #[test] fn table_array() { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] - struct Foo { a: Vec, } + struct Foo { + a: Vec, + } #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] - struct Bar { a: isize } + struct Bar { + a: isize, + } equivalent! { Foo { a: vec![Bar { a: 1 }, Bar { a: 2 }] }, @@ -258,7 +268,9 @@ fn table_array() { fn type_errors() { #[derive(Deserialize)] #[allow(dead_code)] - struct Foo { bar: isize } + struct Foo { + bar: isize, + } error! { Foo, @@ -270,7 +282,9 @@ fn type_errors() { #[derive(Deserialize)] #[allow(dead_code)] - struct Bar { foo: Foo } + struct Bar { + foo: Foo, + } error! { Bar, @@ -286,7 +300,9 @@ fn type_errors() { #[test] fn missing_errors() { #[derive(Serialize, Deserialize, PartialEq, Debug)] - struct Foo { bar: isize } + struct Foo { + bar: isize, + } error! { Foo, @@ -298,7 +314,9 @@ fn missing_errors() { #[test] fn parse_enum() { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] - struct Foo { a: E } + struct Foo { + a: E, + } #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] #[serde(untagged)] enum E { @@ -330,7 +348,9 @@ fn parse_enum() { #[test] fn parse_enum_string() { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] - struct Foo { a: Sort } + struct Foo { + a: Sort, + } #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] #[serde(rename_all = "lowercase")] @@ -343,7 +363,6 @@ fn parse_enum_string() { Foo { a: Sort::Desc }, Table(map! { a: Value::String("desc".to_string()) }), } - } // #[test] @@ -474,7 +493,9 @@ fn parse_enum_string() { #[test] fn empty_arrays() { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] - struct Foo { a: Vec } + struct Foo { + a: Vec, + } #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] struct Bar; @@ -487,7 +508,9 @@ fn empty_arrays() { #[test] fn empty_arrays2() { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] - struct Foo { a: Option> } + struct Foo { + a: Option>, + } #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] struct Bar; @@ -496,7 +519,7 @@ fn empty_arrays2() { Table(map! {}), } - equivalent!{ + equivalent! { Foo { a: Some(vec![]) }, Table(map! { a: Array(vec![]) }), } @@ -505,7 +528,9 @@ fn empty_arrays2() { #[test] fn extra_keys() { #[derive(Serialize, Deserialize)] - struct Foo { a: isize } + struct Foo { + a: isize, + } let toml = Table(map! { a: Integer(2), b: Integer(2) }); assert!(toml.clone().try_into::().is_ok()); @@ -516,7 +541,7 @@ fn extra_keys() { fn newtypes() { #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] struct A { - b: B + b: B, } #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] @@ -531,19 +556,19 @@ fn newtypes() { #[test] fn newtypes2() { #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] - struct A { - b: B - } + struct A { + b: B, + } #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] - struct B(Option); + struct B(Option); #[derive(Deserialize, Serialize, PartialEq, Debug, Clone)] - struct C { - x: u32, - y: u32, - z: u32 - } + struct C { + x: u32, + y: u32, + z: u32, + } equivalent! { A { b: B(Some(C { x: 0, y: 1, z: 2 })) }, @@ -572,7 +597,10 @@ fn table_structs_empty() { expected.insert("baz".to_string(), CanBeEmpty::default()); expected.insert( "bazv".to_string(), - CanBeEmpty {a: Some("foo".to_string()), b: None}, + CanBeEmpty { + a: Some("foo".to_string()), + b: None, + }, ); expected.insert("foo".to_string(), CanBeEmpty::default()); assert_eq!(value, expected); @@ -583,7 +611,7 @@ fn table_structs_empty() { fn fixed_size_array() { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] struct Entity { - pos: [i32; 2] + pos: [i32; 2], } equivalent! { @@ -644,10 +672,13 @@ fn homogeneous_tuple_struct() { fn json_interoperability() { #[derive(Serialize, Deserialize)] struct Foo { - any: toml::Value + any: toml::Value, } - let _foo: Foo = serde_json::from_str(r#" + let _foo: Foo = serde_json::from_str( + r#" {"any":1} - "#).unwrap(); + "#, + ) + .unwrap(); } diff --git a/test-suite/tests/spanned.rs b/test-suite/tests/spanned.rs index 1b110f0..5f6d5a2 100644 --- a/test-suite/tests/spanned.rs +++ b/test-suite/tests/spanned.rs @@ -3,9 +3,9 @@ extern crate toml; #[macro_use] extern crate serde_derive; -use toml::Spanned; -use toml::value::Datetime; use std::collections::HashMap; +use toml::value::Datetime; +use toml::Spanned; /// A set of good datetimes. pub fn good_datetimes() -> Vec<&'static str> { @@ -31,7 +31,10 @@ fn test_spanned_field() { foo: Spanned, } - fn good<'de, T>(s: &'de str, expected: &str) where T: serde::Deserialize<'de> { + fn good<'de, T>(s: &'de str, expected: &str) + where + T: serde::Deserialize<'de>, + { let foo: Foo = toml::from_str(s).unwrap(); assert_eq!(6, foo.foo.start()); @@ -46,18 +49,12 @@ fn test_spanned_field() { // table good::>( "foo = {\"foo\" = 42, \"bar\" = 42}", - "{\"foo\" = 42, \"bar\" = 42}" + "{\"foo\" = 42, \"bar\" = 42}", ); // array - good::>( - "foo = [0, 1, 2, 3, 4]", - "[0, 1, 2, 3, 4]" - ); + good::>("foo = [0, 1, 2, 3, 4]", "[0, 1, 2, 3, 4]"); // datetime - good::( - "foo = \"1997-09-09T09:09:09Z\"", - "\"1997-09-09T09:09:09Z\"" - ); + good::("foo = \"1997-09-09T09:09:09Z\"", "\"1997-09-09T09:09:09Z\""); for expected in good_datetimes() { let s = format!("foo = {}", expected); diff --git a/test-suite/tests/tables-last.rs b/test-suite/tests/tables-last.rs index d05c8f0..b885a42 100644 --- a/test-suite/tests/tables-last.rs +++ b/test-suite/tests/tables-last.rs @@ -19,7 +19,9 @@ enum Value { #[test] fn always_works() { - let mut a = A { vals: HashMap::new() }; + let mut a = A { + vals: HashMap::new(), + }; a.vals.insert("foo", Value::Int(0)); let mut sub = HashMap::new(); diff --git a/test-suite/tests/valid.rs b/test-suite/tests/valid.rs index 6884584..6914edd 100644 --- a/test-suite/tests/valid.rs +++ b/test-suite/tests/valid.rs @@ -1,10 +1,10 @@ -extern crate toml; extern crate serde; extern crate serde_json; +extern crate toml; -use toml::{Value as Toml, to_string_pretty}; use serde::ser::Serialize; use serde_json::Value as Json; +use toml::{to_string_pretty, Value as Toml}; fn to_json(toml: toml::Value) -> Json { fn doit(s: &str, json: Json) -> Json { @@ -17,11 +17,18 @@ fn to_json(toml: toml::Value) -> Json { match toml { Toml::String(s) => doit("string", Json::String(s)), Toml::Integer(i) => doit("integer", Json::String(i.to_string())), - Toml::Float(f) => doit("float", Json::String({ - let s = format!("{:.15}", f); - let s = format!("{}", s.trim_end_matches('0')); - if s.ends_with('.') {format!("{}0", s)} else {s} - })), + Toml::Float(f) => doit( + "float", + Json::String({ + let s = format!("{:.15}", f); + let s = format!("{}", s.trim_end_matches('0')); + if s.ends_with('.') { + format!("{}0", s) + } else { + s + } + }), + ), Toml::Boolean(b) => doit("bool", Json::String(format!("{}", b))), Toml::Datetime(s) => doit("datetime", Json::String(s.to_string())), Toml::Array(arr) => { @@ -30,7 +37,11 @@ fn to_json(toml: toml::Value) -> Json { _ => false, }; let json = Json::Array(arr.into_iter().map(to_json).collect()); - if is_table {json} else {doit("array", json)} + if is_table { + json + } else { + doit("array", json) + } } Toml::Table(table) => { let mut map = serde_json::Map::new(); @@ -91,10 +102,12 @@ fn run(toml_raw: &str, json_raw: &str) { // Assert toml == json let toml_json = to_json(toml.clone()); - assert!(json == toml_json, - "expected\n{}\ngot\n{}\n", - serde_json::to_string_pretty(&json).unwrap(), - serde_json::to_string_pretty(&toml_json).unwrap()); + assert!( + json == toml_json, + "expected\n{}\ngot\n{}\n", + serde_json::to_string_pretty(&json).unwrap(), + serde_json::to_string_pretty(&toml_json).unwrap() + ); // Assert round trip println!("round trip parse: {}", toml); @@ -108,152 +121,250 @@ macro_rules! test( ($name:ident, $toml:expr, $json:expr) => ( fn $name() { run($toml, $json); } ) ); -test!(array_empty, - include_str!("valid/array-empty.toml"), - include_str!("valid/array-empty.json")); -test!(array_nospaces, - include_str!("valid/array-nospaces.toml"), - include_str!("valid/array-nospaces.json")); -test!(arrays_hetergeneous, - include_str!("valid/arrays-hetergeneous.toml"), - include_str!("valid/arrays-hetergeneous.json")); -test!(arrays, - include_str!("valid/arrays.toml"), - include_str!("valid/arrays.json")); -test!(arrays_nested, - include_str!("valid/arrays-nested.toml"), - include_str!("valid/arrays-nested.json")); -test!(empty, - include_str!("valid/empty.toml"), - include_str!("valid/empty.json")); -test!(bool, - include_str!("valid/bool.toml"), - include_str!("valid/bool.json")); -test!(comments_everywhere, - include_str!("valid/comments-everywhere.toml"), - include_str!("valid/comments-everywhere.json")); -test!(datetime, - include_str!("valid/datetime.toml"), - include_str!("valid/datetime.json")); -test!(example, - include_str!("valid/example.toml"), - include_str!("valid/example.json")); -test!(float, - include_str!("valid/float.toml"), - include_str!("valid/float.json")); -test!(implicit_and_explicit_after, - include_str!("valid/implicit-and-explicit-after.toml"), - include_str!("valid/implicit-and-explicit-after.json")); -test!(implicit_and_explicit_before, - include_str!("valid/implicit-and-explicit-before.toml"), - include_str!("valid/implicit-and-explicit-before.json")); -test!(implicit_groups, - include_str!("valid/implicit-groups.toml"), - include_str!("valid/implicit-groups.json")); -test!(integer, - include_str!("valid/integer.toml"), - include_str!("valid/integer.json")); -test!(key_equals_nospace, - include_str!("valid/key-equals-nospace.toml"), - include_str!("valid/key-equals-nospace.json")); -test!(key_space, - include_str!("valid/key-space.toml"), - include_str!("valid/key-space.json")); -test!(key_special_chars, - include_str!("valid/key-special-chars.toml"), - include_str!("valid/key-special-chars.json")); -test!(key_with_pound, - include_str!("valid/key-with-pound.toml"), - include_str!("valid/key-with-pound.json")); -test!(long_float, - include_str!("valid/long-float.toml"), - include_str!("valid/long-float.json")); -test!(long_integer, - include_str!("valid/long-integer.toml"), - include_str!("valid/long-integer.json")); -test!(multiline_string, - include_str!("valid/multiline-string.toml"), - include_str!("valid/multiline-string.json")); -test!(raw_multiline_string, - include_str!("valid/raw-multiline-string.toml"), - include_str!("valid/raw-multiline-string.json")); -test!(raw_string, - include_str!("valid/raw-string.toml"), - include_str!("valid/raw-string.json")); -test!(string_empty, - include_str!("valid/string-empty.toml"), - include_str!("valid/string-empty.json")); -test!(string_escapes, - include_str!("valid/string-escapes.toml"), - include_str!("valid/string-escapes.json")); -test!(string_simple, - include_str!("valid/string-simple.toml"), - include_str!("valid/string-simple.json")); -test!(string_with_pound, - include_str!("valid/string-with-pound.toml"), - include_str!("valid/string-with-pound.json")); -test!(table_array_implicit, - include_str!("valid/table-array-implicit.toml"), - include_str!("valid/table-array-implicit.json")); -test!(table_array_many, - include_str!("valid/table-array-many.toml"), - include_str!("valid/table-array-many.json")); -test!(table_array_nest, - include_str!("valid/table-array-nest.toml"), - include_str!("valid/table-array-nest.json")); -test!(table_array_one, - include_str!("valid/table-array-one.toml"), - include_str!("valid/table-array-one.json")); -test!(table_empty, - include_str!("valid/table-empty.toml"), - include_str!("valid/table-empty.json")); -test!(table_sub_empty, - include_str!("valid/table-sub-empty.toml"), - include_str!("valid/table-sub-empty.json")); -test!(table_multi_empty, - include_str!("valid/table-multi-empty.toml"), - include_str!("valid/table-multi-empty.json")); -test!(table_whitespace, - include_str!("valid/table-whitespace.toml"), - include_str!("valid/table-whitespace.json")); -test!(table_with_pound, - include_str!("valid/table-with-pound.toml"), - include_str!("valid/table-with-pound.json")); -test!(unicode_escape, - include_str!("valid/unicode-escape.toml"), - include_str!("valid/unicode-escape.json")); -test!(unicode_literal, - include_str!("valid/unicode-literal.toml"), - include_str!("valid/unicode-literal.json")); -test!(hard_example, - include_str!("valid/hard_example.toml"), - include_str!("valid/hard_example.json")); -test!(example2, - include_str!("valid/example2.toml"), - include_str!("valid/example2.json")); -test!(example3, - include_str!("valid/example-v0.3.0.toml"), - include_str!("valid/example-v0.3.0.json")); -test!(example4, - include_str!("valid/example-v0.4.0.toml"), - include_str!("valid/example-v0.4.0.json")); -test!(example_bom, - include_str!("valid/example-bom.toml"), - include_str!("valid/example.json")); +test!( + array_empty, + include_str!("valid/array-empty.toml"), + include_str!("valid/array-empty.json") +); +test!( + array_nospaces, + include_str!("valid/array-nospaces.toml"), + include_str!("valid/array-nospaces.json") +); +test!( + arrays_hetergeneous, + include_str!("valid/arrays-hetergeneous.toml"), + include_str!("valid/arrays-hetergeneous.json") +); +test!( + arrays, + include_str!("valid/arrays.toml"), + include_str!("valid/arrays.json") +); +test!( + arrays_nested, + include_str!("valid/arrays-nested.toml"), + include_str!("valid/arrays-nested.json") +); +test!( + empty, + include_str!("valid/empty.toml"), + include_str!("valid/empty.json") +); +test!( + bool, + include_str!("valid/bool.toml"), + include_str!("valid/bool.json") +); +test!( + comments_everywhere, + include_str!("valid/comments-everywhere.toml"), + include_str!("valid/comments-everywhere.json") +); +test!( + datetime, + include_str!("valid/datetime.toml"), + include_str!("valid/datetime.json") +); +test!( + example, + include_str!("valid/example.toml"), + include_str!("valid/example.json") +); +test!( + float, + include_str!("valid/float.toml"), + include_str!("valid/float.json") +); +test!( + implicit_and_explicit_after, + include_str!("valid/implicit-and-explicit-after.toml"), + include_str!("valid/implicit-and-explicit-after.json") +); +test!( + implicit_and_explicit_before, + include_str!("valid/implicit-and-explicit-before.toml"), + include_str!("valid/implicit-and-explicit-before.json") +); +test!( + implicit_groups, + include_str!("valid/implicit-groups.toml"), + include_str!("valid/implicit-groups.json") +); +test!( + integer, + include_str!("valid/integer.toml"), + include_str!("valid/integer.json") +); +test!( + key_equals_nospace, + include_str!("valid/key-equals-nospace.toml"), + include_str!("valid/key-equals-nospace.json") +); +test!( + key_space, + include_str!("valid/key-space.toml"), + include_str!("valid/key-space.json") +); +test!( + key_special_chars, + include_str!("valid/key-special-chars.toml"), + include_str!("valid/key-special-chars.json") +); +test!( + key_with_pound, + include_str!("valid/key-with-pound.toml"), + include_str!("valid/key-with-pound.json") +); +test!( + long_float, + include_str!("valid/long-float.toml"), + include_str!("valid/long-float.json") +); +test!( + long_integer, + include_str!("valid/long-integer.toml"), + include_str!("valid/long-integer.json") +); +test!( + multiline_string, + include_str!("valid/multiline-string.toml"), + include_str!("valid/multiline-string.json") +); +test!( + raw_multiline_string, + include_str!("valid/raw-multiline-string.toml"), + include_str!("valid/raw-multiline-string.json") +); +test!( + raw_string, + include_str!("valid/raw-string.toml"), + include_str!("valid/raw-string.json") +); +test!( + string_empty, + include_str!("valid/string-empty.toml"), + include_str!("valid/string-empty.json") +); +test!( + string_escapes, + include_str!("valid/string-escapes.toml"), + include_str!("valid/string-escapes.json") +); +test!( + string_simple, + include_str!("valid/string-simple.toml"), + include_str!("valid/string-simple.json") +); +test!( + string_with_pound, + include_str!("valid/string-with-pound.toml"), + include_str!("valid/string-with-pound.json") +); +test!( + table_array_implicit, + include_str!("valid/table-array-implicit.toml"), + include_str!("valid/table-array-implicit.json") +); +test!( + table_array_many, + include_str!("valid/table-array-many.toml"), + include_str!("valid/table-array-many.json") +); +test!( + table_array_nest, + include_str!("valid/table-array-nest.toml"), + include_str!("valid/table-array-nest.json") +); +test!( + table_array_one, + include_str!("valid/table-array-one.toml"), + include_str!("valid/table-array-one.json") +); +test!( + table_empty, + include_str!("valid/table-empty.toml"), + include_str!("valid/table-empty.json") +); +test!( + table_sub_empty, + include_str!("valid/table-sub-empty.toml"), + include_str!("valid/table-sub-empty.json") +); +test!( + table_multi_empty, + include_str!("valid/table-multi-empty.toml"), + include_str!("valid/table-multi-empty.json") +); +test!( + table_whitespace, + include_str!("valid/table-whitespace.toml"), + include_str!("valid/table-whitespace.json") +); +test!( + table_with_pound, + include_str!("valid/table-with-pound.toml"), + include_str!("valid/table-with-pound.json") +); +test!( + unicode_escape, + include_str!("valid/unicode-escape.toml"), + include_str!("valid/unicode-escape.json") +); +test!( + unicode_literal, + include_str!("valid/unicode-literal.toml"), + include_str!("valid/unicode-literal.json") +); +test!( + hard_example, + include_str!("valid/hard_example.toml"), + include_str!("valid/hard_example.json") +); +test!( + example2, + include_str!("valid/example2.toml"), + include_str!("valid/example2.json") +); +test!( + example3, + include_str!("valid/example-v0.3.0.toml"), + include_str!("valid/example-v0.3.0.json") +); +test!( + example4, + include_str!("valid/example-v0.4.0.toml"), + include_str!("valid/example-v0.4.0.json") +); +test!( + example_bom, + include_str!("valid/example-bom.toml"), + include_str!("valid/example.json") +); -test!(datetime_truncate, - include_str!("valid/datetime-truncate.toml"), - include_str!("valid/datetime-truncate.json")); -test!(key_quote_newline, - include_str!("valid/key-quote-newline.toml"), - include_str!("valid/key-quote-newline.json")); -test!(table_array_nest_no_keys, - include_str!("valid/table-array-nest-no-keys.toml"), - include_str!("valid/table-array-nest-no-keys.json")); -test!(dotted_keys, - include_str!("valid/dotted-keys.toml"), - include_str!("valid/dotted-keys.json")); +test!( + datetime_truncate, + include_str!("valid/datetime-truncate.toml"), + include_str!("valid/datetime-truncate.json") +); +test!( + key_quote_newline, + include_str!("valid/key-quote-newline.toml"), + include_str!("valid/key-quote-newline.json") +); +test!( + table_array_nest_no_keys, + include_str!("valid/table-array-nest-no-keys.toml"), + include_str!("valid/table-array-nest-no-keys.json") +); +test!( + dotted_keys, + include_str!("valid/dotted-keys.toml"), + include_str!("valid/dotted-keys.json") +); -test!(quote_surrounded_value, - include_str!("valid/quote-surrounded-value.toml"), - include_str!("valid/quote-surrounded-value.json")); +test!( + quote_surrounded_value, + include_str!("valid/quote-surrounded-value.toml"), + include_str!("valid/quote-surrounded-value.json") +); -- cgit v1.2.3