From 9796059c58ec315dfc9b4ed0ba37c9e9318cb3fc Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 10 Jul 2018 23:29:47 -0700 Subject: 0.5: Support dotted keys. cc #224 --- test-suite/tests/invalid-misc.rs | 8 ++++++ test-suite/tests/valid.rs | 5 +++- test-suite/tests/valid/dotted-keys.json | 44 +++++++++++++++++++++++++++++++++ test-suite/tests/valid/dotted-keys.toml | 9 +++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 test-suite/tests/valid/dotted-keys.json create mode 100644 test-suite/tests/valid/dotted-keys.toml (limited to 'test-suite/tests') diff --git a/test-suite/tests/invalid-misc.rs b/test-suite/tests/invalid-misc.rs index 80421e3..5c7f779 100644 --- a/test-suite/tests/invalid-misc.rs +++ b/test-suite/tests/invalid-misc.rs @@ -17,4 +17,12 @@ fn bad() { bad("a = -0x1"); bad("a = 0x-1"); + + // Dotted keys. + bad("a.b.c = 1 + a.b = 2 + "); + bad("a = 1 + a.b = 2"); + bad("a = {k1 = 1, k1.name = \"joe\"}") } diff --git a/test-suite/tests/valid.rs b/test-suite/tests/valid.rs index b186800..d032ba5 100644 --- a/test-suite/tests/valid.rs +++ b/test-suite/tests/valid.rs @@ -45,7 +45,7 @@ fn to_json(toml: toml::Value) -> Json { fn run_pretty(toml: Toml) { // Assert toml == json println!("### pretty round trip parse."); - + // standard pretty let toml_raw = to_string_pretty(&toml).expect("to string"); let toml2 = toml_raw.parse().expect("from string"); @@ -247,3 +247,6 @@ test!(key_quote_newline, 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")); diff --git a/test-suite/tests/valid/dotted-keys.json b/test-suite/tests/valid/dotted-keys.json new file mode 100644 index 0000000..e32079a --- /dev/null +++ b/test-suite/tests/valid/dotted-keys.json @@ -0,0 +1,44 @@ +{ + "a": { + "b": { + "type": "integer", + "value": "123" + } + }, + "table": { + "a": { + "b": { + "c": { + "type": "integer", + "value": "1" + }, + "d": { + "type": "integer", + "value": "2" + } + } + }, + "in": { + "bar": { + "type": "integer", + "value": "2" + }, + "foo": { + "type": "integer", + "value": "1" + } + }, + "in2": { + "type": { + "color": { + "type": "string", + "value": "blue" + }, + "name": { + "type": "string", + "value": "cat" + } + } + } + } +} diff --git a/test-suite/tests/valid/dotted-keys.toml b/test-suite/tests/valid/dotted-keys.toml new file mode 100644 index 0000000..27dbd32 --- /dev/null +++ b/test-suite/tests/valid/dotted-keys.toml @@ -0,0 +1,9 @@ +a.b = 123 + +[table] +a.b.c = 1 +a . b . d = 2 +in = {foo = 1} +in.bar = 2 + +in2 = { type.name = "cat", type.color = "blue" } -- cgit v1.2.3