diff options
author | Alex Crichton <alex@alexcrichton.com> | 2018-08-05 20:27:26 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-05 20:27:26 -0500 |
commit | 7c1da18505c5773cfb3653790976ab18837e9feb (patch) | |
tree | 2b9f58e8eba6d21eb21a18aa6ed462bd4be1dab4 | |
parent | 55a11b89550fb280e3f889cc1b8c9073de6fb937 (diff) | |
parent | 223e4b862b61afc610bf287feef02ad7745e668b (diff) | |
download | milf-rs-7c1da18505c5773cfb3653790976ab18837e9feb.tar.gz milf-rs-7c1da18505c5773cfb3653790976ab18837e9feb.zip |
Merge pull request #254 from ehuss/macro-0.5
Support the new 0.5 syntax in the toml! macro.
-rw-r--r-- | src/macros.rs | 179 | ||||
-rw-r--r-- | test-suite/tests/macros.rs | 81 |
2 files changed, 214 insertions, 46 deletions
diff --git a/src/macros.rs b/src/macros.rs index 7a2bcd3..b4c7b22 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -80,54 +80,75 @@ macro_rules! toml_internal { (@toplevel $root:ident [$($path:tt)*]) => {}; // Parse negative number `key = -value`. - (@toplevel $root:ident [$($path:tt)*] $($k:tt)-+ = - $v:tt $($rest:tt)*) => { - toml_internal!(@toplevel $root [$($path)*] $($k)-+ = (-$v) $($rest)*); + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = - $v:tt $($rest:tt)*) => { + toml_internal!(@toplevel $root [$($path)*] $($($k)-+).+ = (-$v) $($rest)*); + }; + + // Parse positive number `key = +value`. + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = + $v:tt $($rest:tt)*) => { + toml_internal!(@toplevel $root [$($path)*] $($($k)-+).+ = ($v) $($rest)*); }; // Parse offset datetime `key = 1979-05-27T00:32:00.999999-07:00`. - (@toplevel $root:ident [$($path:tt)*] $($k:tt)-+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => { - toml_internal!(@topleveldatetime $root [$($path)*] $($k)-+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + }; + // Space instead of T. + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); }; // Parse offset datetime `key = 1979-05-27T00:32:00-07:00`. - (@toplevel $root:ident [$($path:tt)*] $($k:tt)-+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => { - toml_internal!(@topleveldatetime $root [$($path)*] $($k)-+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); + }; + // Space instead of T. + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*); }; // Parse local datetime `key = 1979-05-27T00:32:00.999999`. - (@toplevel $root:ident [$($path:tt)*] $($k:tt)-+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => { - toml_internal!(@topleveldatetime $root [$($path)*] $($k)-+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); + }; + // Space instead of T. + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*); }; // Parse offset datetime `key = 1979-05-27T07:32:00Z` and local datetime `key = 1979-05-27T07:32:00`. - (@toplevel $root:ident [$($path:tt)*] $($k:tt)-+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt $($rest:tt)*) => { - toml_internal!(@topleveldatetime $root [$($path)*] $($k)-+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*); + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*); + }; + // Space instead of T. + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec) $($rest)*); }; // Parse local date `key = 1979-05-27`. - (@toplevel $root:ident [$($path:tt)*] $($k:tt)-+ = $yr:tt - $mo:tt - $day:tt $($rest:tt)*) => { - toml_internal!(@topleveldatetime $root [$($path)*] $($k)-+ = ($yr - $mo - $day) $($rest)*); + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($yr - $mo - $day) $($rest)*); }; // Parse local time `key = 00:32:00.999999`. - (@toplevel $root:ident [$($path:tt)*] $($k:tt)-+ = $hr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => { - toml_internal!(@topleveldatetime $root [$($path)*] $($k)-+ = ($hr : $min : $sec . $frac) $($rest)*); + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt . $frac:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($hr : $min : $sec . $frac) $($rest)*); }; // Parse local time `key = 07:32:00`. - (@toplevel $root:ident [$($path:tt)*] $($k:tt)-+ = $hr:tt : $min:tt : $sec:tt $($rest:tt)*) => { - toml_internal!(@topleveldatetime $root [$($path)*] $($k)-+ = ($hr : $min : $sec) $($rest)*); + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt $($rest:tt)*) => { + toml_internal!(@topleveldatetime $root [$($path)*] $($($k)-+).+ = ($hr : $min : $sec) $($rest)*); }; // Parse any other `key = value` including string, inline array, inline // table, number, and boolean. - (@toplevel $root:ident [$($path:tt)*] $($k:tt)-+ = $v:tt $($rest:tt)*) => { + (@toplevel $root:ident [$($path:tt)*] $($($k:tt)-+).+ = $v:tt $($rest:tt)*) => {{ $crate::macros::insert_toml( &mut $root, - &[$($path)* &concat!($("-", toml_internal!(@path $k),)+)[1..]], + &[$($path)* $(&concat!($("-", toml_internal!(@path $k),)+)[1..], )+], toml_internal!(@value $v)); toml_internal!(@toplevel $root [$($path)*] $($rest)*); - }; + }}; // Parse array header `[[bin]]`. (@toplevel $root:ident $oldpath:tt [[$($($path:tt)-+).+]] $($rest:tt)*) => { @@ -147,10 +168,10 @@ macro_rules! toml_internal { }; // Parse datetime from string and insert into table. - (@topleveldatetime $root:ident [$($path:tt)*] $($k:tt)-+ = ($($datetime:tt)+) $($rest:tt)*) => { + (@topleveldatetime $root:ident [$($path:tt)*] $($($k:tt)-+).+ = ($($datetime:tt)+) $($rest:tt)*) => { $crate::macros::insert_toml( &mut $root, - &[$($path)* &concat!($("-", toml_internal!(@path $k),)+)[1..]], + &[$($path)* $(&concat!($("-", toml_internal!(@path $k),)+)[1..], )+], $crate::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap())); toml_internal!(@toplevel $root [$($path)*] $($rest)*); }; @@ -168,9 +189,9 @@ macro_rules! toml_internal { // Construct a Value from an inline table. (@value { $($inline:tt)* }) => {{ - let mut table = $crate::value::Table::new(); + let mut table = $crate::Value::Table($crate::value::Table::new()); toml_internal!(@trailingcomma (@table table) $($inline)*); - $crate::Value::Table(table) + table }}; // Construct a Value from an inline array. @@ -180,6 +201,30 @@ macro_rules! toml_internal { $crate::Value::Array(array) }}; + (@value (-nan)) => { + $crate::Value::Float(-::std::f64::NAN) + }; + + (@value (nan)) => { + $crate::Value::Float(::std::f64::NAN) + }; + + (@value nan) => { + $crate::Value::Float(::std::f64::NAN) + }; + + (@value (-inf)) => { + $crate::Value::Float(::std::f64::NEG_INFINITY) + }; + + (@value (inf)) => { + $crate::Value::Float(::std::f64::INFINITY) + }; + + (@value inf) => { + $crate::Value::Float(::std::f64::INFINITY) + }; + // Construct a Value from any other type, probably string or boolean or number. (@value $v:tt) => {{ // TODO: Implement this with something like serde_json::to_value instead. @@ -191,57 +236,80 @@ macro_rules! toml_internal { (@table $root:ident) => {}; // Parse negative number `key = -value`. - (@table $root:ident $($k:tt)-+ = - $v:tt , $($rest:tt)*) => { - toml_internal!(@table $root $($k)-+ = (-$v) , $($rest)*); + (@table $root:ident $($($k:tt)-+).+ = - $v:tt , $($rest:tt)*) => { + toml_internal!(@table $root $($($k)-+).+ = (-$v) , $($rest)*); + }; + + // Parse positive number `key = +value`. + (@table $root:ident $($($k:tt)-+).+ = + $v:tt , $($rest:tt)*) => { + toml_internal!(@table $root $($($k)-+).+ = ($v) , $($rest)*); }; // Parse offset datetime `key = 1979-05-27T00:32:00.999999-07:00`. - (@table $root:ident $($k:tt)-+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { - toml_internal!(@tabledatetime $root $($k)-+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + }; + // Space instead of T. + (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); }; // Parse offset datetime `key = 1979-05-27T00:32:00-07:00`. - (@table $root:ident $($k:tt)-+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { - toml_internal!(@tabledatetime $root $($k)-+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); + (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); + }; + // Space instead of T. + (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*); }; // Parse local datetime `key = 1979-05-27T00:32:00.999999`. - (@table $root:ident $($k:tt)-+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { - toml_internal!(@tabledatetime $root $($k)-+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); + (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); + }; + // Space instead of T. + (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*); }; // Parse offset datetime `key = 1979-05-27T07:32:00Z` and local datetime `key = 1979-05-27T07:32:00`. - (@table $root:ident $($k:tt)-+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { - toml_internal!(@tabledatetime $root $($k)-+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*); + (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $dhr : $min : $sec) $($rest)*); + }; + // Space instead of T. + (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day T $hr : $min : $sec) $($rest)*); }; // Parse local date `key = 1979-05-27`. - (@table $root:ident $($k:tt)-+ = $yr:tt - $mo:tt - $day:tt , $($rest:tt)*) => { - toml_internal!(@tabledatetime $root $($k)-+ = ($yr - $mo - $day) $($rest)*); + (@table $root:ident $($($k:tt)-+).+ = $yr:tt - $mo:tt - $day:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($yr - $mo - $day) $($rest)*); }; // Parse local time `key = 00:32:00.999999`. - (@table $root:ident $($k:tt)-+ = $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { - toml_internal!(@tabledatetime $root $($k)-+ = ($hr : $min : $sec . $frac) $($rest)*); + (@table $root:ident $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($hr : $min : $sec . $frac) $($rest)*); }; // Parse local time `key = 07:32:00`. - (@table $root:ident $($k:tt)-+ = $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { - toml_internal!(@tabledatetime $root $($k)-+ = ($hr : $min : $sec) $($rest)*); + (@table $root:ident $($($k:tt)-+).+ = $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { + toml_internal!(@tabledatetime $root $($($k)-+).+ = ($hr : $min : $sec) $($rest)*); }; // Parse any other type, probably string or boolean or number. - (@table $root:ident $($k:tt)-+ = $v:tt , $($rest:tt)*) => { - $root.insert( - concat!($("-", toml_internal!(@path $k),)+)[1..].to_owned(), + (@table $root:ident $($($k:tt)-+).+ = $v:tt , $($rest:tt)*) => { + $crate::macros::insert_toml( + &mut $root, + &[$(&concat!($("-", toml_internal!(@path $k),)+)[1..], )+], toml_internal!(@value $v)); toml_internal!(@table $root $($rest)*); }; // Parse a Datetime from string and continue in @table state. - (@tabledatetime $root:ident $($k:tt)-+ = ($($datetime:tt)*) $($rest:tt)*) => { - $root.insert( - concat!($("-", toml_internal!(@path $k),)+)[1..].to_owned(), + (@tabledatetime $root:ident $($($k:tt)-+).+ = ($($datetime:tt)*) $($rest:tt)*) => { + $crate::macros::insert_toml( + &mut $root, + &[$(&concat!($("-", toml_internal!(@path $k),)+)[1..], )+], $crate::Value::Datetime(concat!($(stringify!($datetime)),+).parse().unwrap())); toml_internal!(@table $root $($rest)*); }; @@ -254,25 +322,46 @@ macro_rules! toml_internal { toml_internal!(@array $root (-$v) , $($rest)*); }; + // Parse positive number `+value`. + (@array $root:ident + $v:tt , $($rest:tt)*) => { + toml_internal!(@array $root ($v) , $($rest)*); + }; + // Parse offset datetime `1979-05-27T00:32:00.999999-07:00`. (@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); }; + // Space instead of T. + (@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { + toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec . $frac - $tzh : $tzm) $($rest)*); + }; // Parse offset datetime `1979-05-27T00:32:00-07:00`. (@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec - $tzh : $tzm) $($rest)*); }; + // Space instead of T. + (@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt - $tzh:tt : $tzm:tt , $($rest:tt)*) => { + toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec - $tzh : $tzm) $($rest)*); + }; // Parse local datetime `1979-05-27T00:32:00.999999`. (@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec . $frac) $($rest)*); }; + // Space instead of T. + (@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt . $frac:tt , $($rest:tt)*) => { + toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec . $frac) $($rest)*); + }; // Parse offset datetime `1979-05-27T07:32:00Z` and local datetime `1979-05-27T07:32:00`. (@array $root:ident $yr:tt - $mo:tt - $dhr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { toml_internal!(@arraydatetime $root ($yr - $mo - $dhr : $min : $sec) $($rest)*); }; + // Space instead of T. + (@array $root:ident $yr:tt - $mo:tt - $day:tt $hr:tt : $min:tt : $sec:tt , $($rest:tt)*) => { + toml_internal!(@arraydatetime $root ($yr - $mo - $day T $hr : $min : $sec) $($rest)*); + }; // Parse local date `1979-05-27`. (@array $root:ident $yr:tt - $mo:tt - $day:tt , $($rest:tt)*) => { 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); +} |