diff options
author | Eric Huss <eric@huss.org> | 2018-07-27 11:35:05 -0700 |
---|---|---|
committer | Eric Huss <eric@huss.org> | 2018-08-05 14:26:46 -0700 |
commit | 223e4b862b61afc610bf287feef02ad7745e668b (patch) | |
tree | 2b9f58e8eba6d21eb21a18aa6ed462bd4be1dab4 /test-suite | |
parent | 55a11b89550fb280e3f889cc1b8c9073de6fb937 (diff) | |
download | milf-rs-223e4b862b61afc610bf287feef02ad7745e668b.tar.gz milf-rs-223e4b862b61afc610bf287feef02ad7745e668b.zip |
Support the new 0.5 syntax in the toml! macro.
- Space in datetime.
- +- inf, nan, 0.0
- Dotted keys.
Diffstat (limited to 'test-suite')
-rw-r--r-- | test-suite/tests/macros.rs | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/test-suite/tests/macros.rs b/test-suite/tests/macros.rs index 439420d..6b77c81 100644 --- a/test-suite/tests/macros.rs +++ b/test-suite/tests/macros.rs @@ -1,8 +1,10 @@ -#![recursion_limit = "128"] +#![recursion_limit = "256"] #[macro_use] extern crate toml; +use std::f64; + macro_rules! table { ($($key:expr => $value:expr,)*) => {{ let mut table = toml::value::Table::new(); @@ -143,6 +145,19 @@ fn test_number() { negative = -1 table = { positive = 1, negative = -1 } array = [ 1, -1 ] + neg_zero = -0 + pos_zero = +0 + float = 3.14 + + sf1 = inf + sf2 = +inf + sf3 = -inf + sf7 = +0.0 + sf8 = -0.0 + + hex = 0xa_b_c + oct = 0o755 + bin = 0b11010110 }; let expected = table! { @@ -156,18 +171,42 @@ fn test_number() { 1, -1, }, + "neg_zero" => -0, + "pos_zero" => 0, + "float" => 3.14, + "sf1" => f64::INFINITY, + "sf2" => f64::INFINITY, + "sf3" => f64::NEG_INFINITY, + "sf7" => 0.0, + "sf8" => -0.0, + "hex" => 2748, + "oct" => 493, + "bin" => 214, }; assert_eq!(actual, expected); } #[test] +fn test_nan() { + let actual = toml! { + sf4 = nan + sf5 = +nan + sf6 = -nan + }; + assert!(actual["sf4"].as_float().unwrap().is_nan()); + assert!(actual["sf5"].as_float().unwrap().is_nan()); + assert!(actual["sf6"].as_float().unwrap().is_nan()); +} + +#[test] fn test_datetime() { let actual = toml! { // Copied from the TOML spec. odt1 = 1979-05-27T07:32:00Z odt2 = 1979-05-27T00:32:00-07:00 odt3 = 1979-05-27T00:32:00.999999-07:00 + odt4 = 1979-05-27 07:32:00Z ldt1 = 1979-05-27T07:32:00 ldt2 = 1979-05-27T00:32:00.999999 ld1 = 1979-05-27 @@ -178,6 +217,7 @@ fn test_datetime() { odt1 = 1979-05-27T07:32:00Z, odt2 = 1979-05-27T00:32:00-07:00, odt3 = 1979-05-27T00:32:00.999999-07:00, + odt4 = 1979-05-27 07:32:00Z, ldt1 = 1979-05-27T07:32:00, ldt2 = 1979-05-27T00:32:00.999999, ld1 = 1979-05-27, @@ -189,6 +229,7 @@ fn test_datetime() { 1979-05-27T07:32:00Z, 1979-05-27T00:32:00-07:00, 1979-05-27T00:32:00.999999-07:00, + 1979-05-27 07:32:00Z, 1979-05-27T07:32:00, 1979-05-27T00:32:00.999999, 1979-05-27, @@ -201,6 +242,7 @@ fn test_datetime() { "odt1" => datetime!("1979-05-27T07:32:00Z"), "odt2" => datetime!("1979-05-27T00:32:00-07:00"), "odt3" => datetime!("1979-05-27T00:32:00.999999-07:00"), + "odt4" => datetime!("1979-05-27 07:32:00Z"), "ldt1" => datetime!("1979-05-27T07:32:00"), "ldt2" => datetime!("1979-05-27T00:32:00.999999"), "ld1" => datetime!("1979-05-27"), @@ -211,6 +253,7 @@ fn test_datetime() { "odt1" => datetime!("1979-05-27T07:32:00Z"), "odt2" => datetime!("1979-05-27T00:32:00-07:00"), "odt3" => datetime!("1979-05-27T00:32:00.999999-07:00"), + "odt4" => datetime!("1979-05-27 07:32:00Z"), "ldt1" => datetime!("1979-05-27T07:32:00"), "ldt2" => datetime!("1979-05-27T00:32:00.999999"), "ld1" => datetime!("1979-05-27"), @@ -222,6 +265,7 @@ fn test_datetime() { datetime!("1979-05-27T07:32:00Z"), datetime!("1979-05-27T00:32:00-07:00"), datetime!("1979-05-27T00:32:00.999999-07:00"), + datetime!("1979-05-27 07:32:00Z"), datetime!("1979-05-27T07:32:00"), datetime!("1979-05-27T00:32:00.999999"), datetime!("1979-05-27"), @@ -284,3 +328,38 @@ fn test_empty() { assert_eq!(actual, expected); } + +#[test] +fn test_dotted_keys() { + let actual = toml! { + a.b = 123 + a.c = 1979-05-27T07:32:00Z + [table] + a.b.c = 1 + a . b . d = 2 + in = { type.name = "cat", type.color = "blue" } + }; + + let expected = table! { + "a" => table! { + "b" => 123, + "c" => datetime!("1979-05-27T07:32:00Z"), + }, + "table" => table! { + "a" => table! { + "b" => table! { + "c" => 1, + "d" => 2, + }, + }, + "in" => table! { + "type" => table! { + "name" => "cat", + "color" => "blue", + }, + }, + }, + }; + + assert_eq!(actual, expected); +} |