aboutsummaryrefslogtreecommitdiff
path: root/test-suite
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-07-11 09:01:53 -0500
committerGitHub <noreply@github.com>2018-07-11 09:01:53 -0500
commitf99ab3f5e30f2ce00de9bc15083d2671107f1fcf (patch)
tree3a1715fa18ba7640c12fea20ffaa762206c95c62 /test-suite
parent2be7ce9079fa02d9dd42958410ba1c40cef9811c (diff)
parent69b4571c6bafcd7d9f675d3eb49d4c088d372eea (diff)
downloadmilf-rs-f99ab3f5e30f2ce00de9bc15083d2671107f1fcf.tar.gz
milf-rs-f99ab3f5e30f2ce00de9bc15083d2671107f1fcf.zip
Merge pull request #248 from ehuss/float-0.5
0.5: Support floats nan, inf, and +/-0.0.
Diffstat (limited to 'test-suite')
-rw-r--r--test-suite/build.rs1
-rw-r--r--test-suite/tests/float.rs79
-rw-r--r--test-suite/tests/invalid-encoder-misc.rs14
-rw-r--r--test-suite/tests/invalid-misc.rs3
-rw-r--r--test-suite/tests/valid/integer.json4
-rw-r--r--test-suite/tests/valid/integer.toml2
6 files changed, 85 insertions, 18 deletions
diff --git a/test-suite/build.rs b/test-suite/build.rs
index ca63946..5a9a55a 100644
--- a/test-suite/build.rs
+++ b/test-suite/build.rs
@@ -4,5 +4,6 @@ use rustc_version::{version, Version};
fn main() {
if version().unwrap() >= Version::parse("1.20.0").unwrap() {
println!(r#"cargo:rustc-cfg=feature="test-quoted-keys-in-macro""#);
+ println!(r#"cargo:rustc-cfg=feature="test-nan-sign""#);
}
}
diff --git a/test-suite/tests/float.rs b/test-suite/tests/float.rs
new file mode 100644
index 0000000..6590fe4
--- /dev/null
+++ b/test-suite/tests/float.rs
@@ -0,0 +1,79 @@
+extern crate toml;
+#[macro_use]
+extern crate serde_derive;
+
+use toml::Value;
+
+macro_rules! float_inf_tests {
+ ($ty:ty) => {{
+ #[derive(Serialize, Deserialize)]
+ struct S {
+ sf1: $ty,
+ sf2: $ty,
+ sf3: $ty,
+ sf4: $ty,
+ sf5: $ty,
+ sf6: $ty,
+ sf7: $ty,
+ sf8: $ty,
+ }
+ let inf: S = toml::from_str(
+ r"
+ # infinity
+ sf1 = inf # positive infinity
+ sf2 = +inf # positive infinity
+ sf3 = -inf # negative infinity
+
+ # not a number
+ sf4 = nan # actual sNaN/qNaN encoding is implementation specific
+ sf5 = +nan # same as `nan`
+ sf6 = -nan # valid, actual encoding is implementation specific
+
+ # zero
+ sf7 = +0.0
+ sf8 = -0.0
+ ").expect("Parse infinities.");
+
+ assert!(inf.sf1.is_infinite());
+ assert!(inf.sf1.is_sign_positive());
+ assert!(inf.sf2.is_infinite());
+ assert!(inf.sf2.is_sign_positive());
+ assert!(inf.sf3.is_infinite());
+ assert!(inf.sf3.is_sign_negative());
+
+ assert!(inf.sf4.is_nan());
+ assert!(inf.sf4.is_sign_positive());
+ assert!(inf.sf5.is_nan());
+ assert!(inf.sf5.is_sign_positive());
+ assert!(inf.sf6.is_nan());
+ assert!(inf.sf6.is_sign_negative());
+
+ assert_eq!(inf.sf7, 0.0);
+ assert!(inf.sf7.is_sign_positive());
+ assert_eq!(inf.sf8, 0.0);
+ assert!(inf.sf8.is_sign_negative());
+
+ let s = toml::to_string(&inf).unwrap();
+ assert_eq!(
+ s, "\
+sf1 = inf
+sf2 = inf
+sf3 = -inf
+sf4 = nan
+sf5 = nan
+sf6 = -nan
+sf7 = 0.0
+sf8 = -0.0
+"
+ );
+
+ toml::from_str::<Value>(&s).expect("roundtrip");
+ }};
+}
+
+#[test]
+#[cfg(feature = "test-nan-sign")]
+fn float_inf() {
+ float_inf_tests!(f32);
+ float_inf_tests!(f64);
+}
diff --git a/test-suite/tests/invalid-encoder-misc.rs b/test-suite/tests/invalid-encoder-misc.rs
deleted file mode 100644
index 272f58f..0000000
--- a/test-suite/tests/invalid-encoder-misc.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-extern crate toml;
-
-use std::f64;
-
-#[test]
-fn test_invalid_float_encode() {
- fn bad(value: toml::Value) {
- assert!(toml::to_string(&value).is_err());
- }
-
- bad(toml::Value::Float(f64::INFINITY));
- bad(toml::Value::Float(f64::NEG_INFINITY));
- bad(toml::Value::Float(f64::NAN));
-}
diff --git a/test-suite/tests/invalid-misc.rs b/test-suite/tests/invalid-misc.rs
index bb70b97..18edf90 100644
--- a/test-suite/tests/invalid-misc.rs
+++ b/test-suite/tests/invalid-misc.rs
@@ -10,8 +10,5 @@ fn bad() {
bad("a = 1__1");
bad("a = 1_");
bad("''");
- bad("a = nan");
- bad("a = -inf");
- bad("a = inf");
bad("a = 9e99999");
}
diff --git a/test-suite/tests/valid/integer.json b/test-suite/tests/valid/integer.json
index 61985a1..86f779f 100644
--- a/test-suite/tests/valid/integer.json
+++ b/test-suite/tests/valid/integer.json
@@ -1,4 +1,6 @@
{
"answer": {"type": "integer", "value": "42"},
- "neganswer": {"type": "integer", "value": "-42"}
+ "neganswer": {"type": "integer", "value": "-42"},
+ "neg_zero": {"type": "integer", "value": "0"},
+ "pos_zero": {"type": "integer", "value": "0"}
}
diff --git a/test-suite/tests/valid/integer.toml b/test-suite/tests/valid/integer.toml
index c4f6297..2bdca34 100644
--- a/test-suite/tests/valid/integer.toml
+++ b/test-suite/tests/valid/integer.toml
@@ -1,2 +1,4 @@
answer = 42
neganswer = -42
+neg_zero = -0
+pos_zero = +0