From 60b874308e6792a73cc00517a60bbef60a12e3cc Mon Sep 17 00:00:00 2001 From: daubaris Date: Fri, 22 Nov 2019 18:28:29 +0200 Subject: Mixed type arrays (#358) * Added support of mixed-type arrays * Add tests cases * Replaced &'static str type for type_ and created a new enum instead * Restored ArrayMixedType --- test-suite/tests/invalid.rs | 15 --------------- .../tests/invalid/array-mixed-types-arrays-and-ints.toml | 1 - .../tests/invalid/array-mixed-types-ints-and-floats.toml | 1 - .../tests/invalid/array-mixed-types-strings-and-ints.toml | 1 - test-suite/tests/valid.rs | 15 +++++++++++++++ .../tests/valid/array-mixed-types-arrays-and-ints.json | 11 +++++++++++ .../tests/valid/array-mixed-types-arrays-and-ints.toml | 1 + .../tests/valid/array-mixed-types-ints-and-floats.json | 9 +++++++++ .../tests/valid/array-mixed-types-ints-and-floats.toml | 1 + .../tests/valid/array-mixed-types-strings-and-ints.json | 9 +++++++++ .../tests/valid/array-mixed-types-strings-and-ints.toml | 1 + test-suite/tests/valid/example-v0.4.0.toml | 3 ++- 12 files changed, 49 insertions(+), 19 deletions(-) delete mode 100644 test-suite/tests/invalid/array-mixed-types-arrays-and-ints.toml delete mode 100644 test-suite/tests/invalid/array-mixed-types-ints-and-floats.toml delete mode 100644 test-suite/tests/invalid/array-mixed-types-strings-and-ints.toml create mode 100644 test-suite/tests/valid/array-mixed-types-arrays-and-ints.json create mode 100644 test-suite/tests/valid/array-mixed-types-arrays-and-ints.toml create mode 100644 test-suite/tests/valid/array-mixed-types-ints-and-floats.json create mode 100644 test-suite/tests/valid/array-mixed-types-ints-and-floats.toml create mode 100644 test-suite/tests/valid/array-mixed-types-strings-and-ints.json create mode 100644 test-suite/tests/valid/array-mixed-types-strings-and-ints.toml (limited to 'test-suite/tests') diff --git a/test-suite/tests/invalid.rs b/test-suite/tests/invalid.rs index 3312629..ccc9338 100644 --- a/test-suite/tests/invalid.rs +++ b/test-suite/tests/invalid.rs @@ -14,21 +14,6 @@ macro_rules! test( ($name:ident, $s:expr, $msg:expr) => ( fn $name() { bad!($s, $msg); } ) ); -test!( - array_mixed_types_arrays_and_ints, - include_str!("invalid/array-mixed-types-arrays-and-ints.toml"), - "mixed types in an array at line 1 column 24" -); -test!( - array_mixed_types_ints_and_floats, - include_str!("invalid/array-mixed-types-ints-and-floats.toml"), - "mixed types in an array at line 1 column 23" -); -test!( - array_mixed_types_strings_and_ints, - include_str!("invalid/array-mixed-types-strings-and-ints.toml"), - "mixed types in an array at line 1 column 27" -); test!( datetime_malformed_no_leads, include_str!("invalid/datetime-malformed-no-leads.toml"), diff --git a/test-suite/tests/invalid/array-mixed-types-arrays-and-ints.toml b/test-suite/tests/invalid/array-mixed-types-arrays-and-ints.toml deleted file mode 100644 index 051ec73..0000000 --- a/test-suite/tests/invalid/array-mixed-types-arrays-and-ints.toml +++ /dev/null @@ -1 +0,0 @@ -arrays-and-ints = [1, ["Arrays are not integers."]] diff --git a/test-suite/tests/invalid/array-mixed-types-ints-and-floats.toml b/test-suite/tests/invalid/array-mixed-types-ints-and-floats.toml deleted file mode 100644 index a5aa9b7..0000000 --- a/test-suite/tests/invalid/array-mixed-types-ints-and-floats.toml +++ /dev/null @@ -1 +0,0 @@ -ints-and-floats = [1, 1.1] diff --git a/test-suite/tests/invalid/array-mixed-types-strings-and-ints.toml b/test-suite/tests/invalid/array-mixed-types-strings-and-ints.toml deleted file mode 100644 index f348308..0000000 --- a/test-suite/tests/invalid/array-mixed-types-strings-and-ints.toml +++ /dev/null @@ -1 +0,0 @@ -strings-and-ints = ["hi", 42] diff --git a/test-suite/tests/valid.rs b/test-suite/tests/valid.rs index e080958..0bb7caa 100644 --- a/test-suite/tests/valid.rs +++ b/test-suite/tests/valid.rs @@ -146,6 +146,21 @@ test!( include_str!("valid/arrays-nested.toml"), include_str!("valid/arrays-nested.json") ); +test!( + array_mixed_types_ints_and_floats, + include_str!("valid/array-mixed-types-ints-and-floats.toml"), + include_str!("valid/array-mixed-types-ints-and-floats.json") +); +test!( + array_mixed_types_arrays_and_ints, + include_str!("valid/array-mixed-types-arrays-and-ints.toml"), + include_str!("valid/array-mixed-types-arrays-and-ints.json") +); +test!( + array_mixed_types_strings_and_ints, + include_str!("valid/array-mixed-types-strings-and-ints.toml"), + include_str!("valid/array-mixed-types-strings-and-ints.json") +); test!( empty, include_str!("valid/empty.toml"), diff --git a/test-suite/tests/valid/array-mixed-types-arrays-and-ints.json b/test-suite/tests/valid/array-mixed-types-arrays-and-ints.json new file mode 100644 index 0000000..10074ec --- /dev/null +++ b/test-suite/tests/valid/array-mixed-types-arrays-and-ints.json @@ -0,0 +1,11 @@ +{ + "arrays-and-ints": { + "type": "array", + "value": [ + {"type": "integer", "value": "1"}, + {"type": "array", "value": [ + { "type": "string", "value":"Arrays are not integers."} + ]} + ] + } +} diff --git a/test-suite/tests/valid/array-mixed-types-arrays-and-ints.toml b/test-suite/tests/valid/array-mixed-types-arrays-and-ints.toml new file mode 100644 index 0000000..051ec73 --- /dev/null +++ b/test-suite/tests/valid/array-mixed-types-arrays-and-ints.toml @@ -0,0 +1 @@ +arrays-and-ints = [1, ["Arrays are not integers."]] diff --git a/test-suite/tests/valid/array-mixed-types-ints-and-floats.json b/test-suite/tests/valid/array-mixed-types-ints-and-floats.json new file mode 100644 index 0000000..c90665e --- /dev/null +++ b/test-suite/tests/valid/array-mixed-types-ints-and-floats.json @@ -0,0 +1,9 @@ +{ + "ints-and-floats": { + "type": "array", + "value": [ + {"type": "integer", "value": "1"}, + {"type": "float", "value": "1.1"} + ] + } +} diff --git a/test-suite/tests/valid/array-mixed-types-ints-and-floats.toml b/test-suite/tests/valid/array-mixed-types-ints-and-floats.toml new file mode 100644 index 0000000..a5aa9b7 --- /dev/null +++ b/test-suite/tests/valid/array-mixed-types-ints-and-floats.toml @@ -0,0 +1 @@ +ints-and-floats = [1, 1.1] diff --git a/test-suite/tests/valid/array-mixed-types-strings-and-ints.json b/test-suite/tests/valid/array-mixed-types-strings-and-ints.json new file mode 100644 index 0000000..8ae322e --- /dev/null +++ b/test-suite/tests/valid/array-mixed-types-strings-and-ints.json @@ -0,0 +1,9 @@ +{ + "strings-and-ints": { + "type": "array", + "value": [ + {"type": "string", "value": "hi"}, + {"type": "integer", "value": "42"} + ] + } +} diff --git a/test-suite/tests/valid/array-mixed-types-strings-and-ints.toml b/test-suite/tests/valid/array-mixed-types-strings-and-ints.toml new file mode 100644 index 0000000..f348308 --- /dev/null +++ b/test-suite/tests/valid/array-mixed-types-strings-and-ints.toml @@ -0,0 +1 @@ +strings-and-ints = ["hi", 42] diff --git a/test-suite/tests/valid/example-v0.4.0.toml b/test-suite/tests/valid/example-v0.4.0.toml index ffbcce0..69f1c1b 100644 --- a/test-suite/tests/valid/example-v0.4.0.toml +++ b/test-suite/tests/valid/example-v0.4.0.toml @@ -170,7 +170,8 @@ False = false ## Array # Arrays are square brackets with other primitives inside. Whitespace is -# ignored. Elements are separated by commas. Data types may not be mixed. +# ignored. Elements are separated by commas. Since 2019-11-06 data types can be +# mixed. [array] -- cgit v1.2.3