From fdd33ebd84df940cfb064cb0e8009d1de28b5fb2 Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 29 Jul 2018 09:33:53 -0400 Subject: [PATCH 01/15] Add test for accidental whitespace after continuation operator in multiline strings --- tests/valid/multiline-string-accidental-whitespace.json | 6 ++++++ tests/valid/multiline-string-accidental-whitespace.toml | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 tests/valid/multiline-string-accidental-whitespace.json create mode 100644 tests/valid/multiline-string-accidental-whitespace.toml diff --git a/tests/valid/multiline-string-accidental-whitespace.json b/tests/valid/multiline-string-accidental-whitespace.json new file mode 100644 index 0000000..3bc5199 --- /dev/null +++ b/tests/valid/multiline-string-accidental-whitespace.json @@ -0,0 +1,6 @@ +{ + "three_lines": { + "type": "string", + "value": "The quick brown fox jumps over the lazy dog." + } +} diff --git a/tests/valid/multiline-string-accidental-whitespace.toml b/tests/valid/multiline-string-accidental-whitespace.toml new file mode 100644 index 0000000..88c0452 --- /dev/null +++ b/tests/valid/multiline-string-accidental-whitespace.toml @@ -0,0 +1,5 @@ +three_lines = """\ + The quick brown \ + fox jumps over \ + the lazy dog.\ + """ From 65d5040816e116489182527face293e0bb765dc0 Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sat, 28 Jul 2018 16:59:33 -0400 Subject: [PATCH 02/15] Add test for offset datetime using space instead of T --- json.go | 5 +++-- tests/valid/datetime.json | 3 ++- tests/valid/datetime.toml | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/json.go b/json.go index 7cf4a5e..83856a6 100644 --- a/json.go +++ b/json.go @@ -3,6 +3,7 @@ package main import ( "strconv" "time" + "strings" ) // compareJson consumes the recursive structure of both `expected` and `test` @@ -173,13 +174,13 @@ func (r result) cmpFloats(e, t string) result { func (r result) cmpAsDatetimes(e, t string) result { var err error - ef, err := time.Parse(time.RFC3339Nano, e) + ef, err := time.Parse(time.RFC3339Nano, strings.Replace(e, " ", "T", 1)) if err != nil { return r.failedf("BUG in test case. Could not read '%s' as a "+ "datetime value for key '%s'.", e, r.key) } - tf, err := time.Parse(time.RFC3339Nano, t) + tf, err := time.Parse(time.RFC3339Nano, strings.Replace(t, " ", "T", 1)) if err != nil { return r.failedf("Malformed parser output. Could not read '%s' "+ "as datetime value for key '%s'.", t, r.key) diff --git a/tests/valid/datetime.json b/tests/valid/datetime.json index 4cdc000..57387b6 100644 --- a/tests/valid/datetime.json +++ b/tests/valid/datetime.json @@ -1,5 +1,6 @@ { "bestdayever": {"type": "datetime", "value": "1987-07-05T17:45:00Z"}, "numoffset": {"type": "datetime", "value": "1977-06-28T12:32:00Z"}, - "milliseconds": {"type": "datetime", "value": "1977-12-21T03:32:00.555+00:00"} + "milliseconds": {"type": "datetime", "value": "1977-12-21T03:32:00.555+00:00"}, + "bestdayever_with_space": {"type": "datetime", "value": "1987-07-05T17:45:00Z"} } diff --git a/tests/valid/datetime.toml b/tests/valid/datetime.toml index ee787b7..5fa9888 100644 --- a/tests/valid/datetime.toml +++ b/tests/valid/datetime.toml @@ -1,3 +1,4 @@ bestdayever = 1987-07-05T17:45:00Z numoffset = 1977-06-28T07:32:00-05:00 milliseconds = 1977-12-21T10:32:00.555+07:00 +bestdayever_with_space = 1987-07-05 17:45:00Z From 234df630598ebb1b978942e529d1bab22f702b4b Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 29 Jul 2018 09:23:26 -0400 Subject: [PATCH 03/15] Add support and tests for local datetime, local date, local time. Update README --- README.md | 9 +++++++-- json.go | 14 ++++++++++++++ tests/valid/local-date.json | 3 +++ tests/valid/local-date.toml | 1 + tests/valid/local-datetime.json | 5 +++++ tests/valid/local-datetime.toml | 3 +++ tests/valid/local-time.json | 4 ++++ tests/valid/local-time.toml | 3 +++ 8 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/valid/local-date.json create mode 100644 tests/valid/local-date.toml create mode 100644 tests/valid/local-datetime.json create mode 100644 tests/valid/local-datetime.toml create mode 100644 tests/valid/local-time.json create mode 100644 tests/valid/local-time.toml diff --git a/README.md b/README.md index c404a03..50ce235 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,10 @@ In the above, `TTYPE` may be one of: * string * integer * float -* datetime +* datetime (for offset date-time) +* local-datetime +* local-date +* local-time * bool * array @@ -101,7 +104,9 @@ and `TVALUE` is always a JSON string, except when `TTYPE` is `array` in which Empty hashes correspond to empty JSON objects (i.e., `{}`) and empty arrays correspond to empty JSON arrays (i.e., `[]`). -Datetime should be encoded following RFC 3339. +Offset datetimes should be encoded following RFC 3339. Local datetimes should be +encoded following RFC 3339, without the offset part. Local dates should be +encoded as the date part of RFC 3339 and Local times as the time part. ### Example JSON encoding diff --git a/json.go b/json.go index 83856a6..baf2a0a 100644 --- a/json.go +++ b/json.go @@ -138,6 +138,8 @@ func (r result) cmpJsonValues(e, t map[string]interface{}) result { return r.cmpFloats(evalue, tvalue); case "datetime": return r.cmpAsDatetimes(evalue, tvalue); + case "local-datetime": + return r.cmpAsLocalDateTimes(evalue, tvalue); default: return r.cmpAsStrings(evalue, tvalue); } @@ -152,6 +154,18 @@ func (r result) cmpAsStrings(e, t string) result { return r } +func (r result) cmpAsLocalDateTimes(e, t string) result { + ce := strings.Replace(strings.Replace(e, "t", "T", 1), " ", "T", 1) + ct := strings.Replace(strings.Replace(t, "t", "T", 1), " ", "T", 1) + + if ce != ct { + return r.failedf("Values for key '%s' don't match. Expected a "+ + "value of '%s' but got '%s'.", r.key, e, t) + } + return r +} + + func (r result) cmpFloats(e, t string) result { ef, err := strconv.ParseFloat(e, 64) if err != nil { diff --git a/tests/valid/local-date.json b/tests/valid/local-date.json new file mode 100644 index 0000000..ff2120e --- /dev/null +++ b/tests/valid/local-date.json @@ -0,0 +1,3 @@ +{ + "bestdayever": {"type": "local-date", "value": "1987-07-05"} +} diff --git a/tests/valid/local-date.toml b/tests/valid/local-date.toml new file mode 100644 index 0000000..1be4a5f --- /dev/null +++ b/tests/valid/local-date.toml @@ -0,0 +1 @@ +bestdayever = 1987-07-05 diff --git a/tests/valid/local-datetime.json b/tests/valid/local-datetime.json new file mode 100644 index 0000000..59a934f --- /dev/null +++ b/tests/valid/local-datetime.json @@ -0,0 +1,5 @@ +{ + "bestdayever": {"type": "local-datetime", "value": "1987-07-05T17:45:00"}, + "milliseconds": {"type": "local-datetime", "value": "1977-12-21T10:32:00.555"}, + "bestdayever_with_space": {"type": "local-datetime", "value": "1987-07-05T17:45:00"} +} diff --git a/tests/valid/local-datetime.toml b/tests/valid/local-datetime.toml new file mode 100644 index 0000000..cb62ef3 --- /dev/null +++ b/tests/valid/local-datetime.toml @@ -0,0 +1,3 @@ +bestdayever = 1987-07-05T17:45:00 +milliseconds = 1977-12-21T10:32:00.555 +bestdayever_with_space = 1987-07-05 17:45:00 diff --git a/tests/valid/local-time.json b/tests/valid/local-time.json new file mode 100644 index 0000000..a9ff3c8 --- /dev/null +++ b/tests/valid/local-time.json @@ -0,0 +1,4 @@ +{ + "besttimeever": {"type": "local-time", "value": "17:45:00"}, + "milliseconds": {"type": "local-time", "value": "10:32:00.555"} +} diff --git a/tests/valid/local-time.toml b/tests/valid/local-time.toml new file mode 100644 index 0000000..01a56a5 --- /dev/null +++ b/tests/valid/local-time.toml @@ -0,0 +1,3 @@ +besttimeever = 17:45:00 +milliseconds = 10:32:00.555 + From de1b2110d68c2b03f37a7916046b2f8825b0e6af Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Mon, 30 Jul 2018 20:38:42 -0400 Subject: [PATCH 04/15] Add support and tests for Nan and Infinity --- json.go | 29 +++++++++++++++++++++++++++++ tests/valid/infinity-and-nan.json | 8 ++++++++ tests/valid/infinity-and-nan.toml | 7 +++++++ 3 files changed, 44 insertions(+) create mode 100644 tests/valid/infinity-and-nan.json create mode 100644 tests/valid/infinity-and-nan.toml diff --git a/json.go b/json.go index baf2a0a..0e6940e 100644 --- a/json.go +++ b/json.go @@ -167,6 +167,35 @@ func (r result) cmpAsLocalDateTimes(e, t string) result { func (r result) cmpFloats(e, t string) result { + // Handle Infinity and NaN + tc := strings.ToLower(t) + ec := strings.ToLower(e) + + if ec == "nan" || ec == "-nan" || ec == "+nan" { + if tc == "nan" || tc == "-nan" || tc == "+nan" { + return r + } else { + return r.failedf("Value for key '%s' don't match. Expected either nan, -nan or +nan but got '%v'.", r.key, tc) + } + } + + if ec == "inf" || ec == "+inf" { + if tc == "inf" || tc == "+inf" { + return r + } else { + return r.failedf("Value for key '%s' don't match. Expected inf or +inf but got '%v'.", r.key, tc) + } + } + + if ec == "-inf" { + if tc == "-inf" { + return r + } else { + return r.failedf("Value for key '%s' don't match. Expected -inf but got '%v'.", r.key, tc) + } + } + + // Else, compare as regular floats ef, err := strconv.ParseFloat(e, 64) if err != nil { return r.failedf("BUG in test case. Could not read '%s' as a "+ diff --git a/tests/valid/infinity-and-nan.json b/tests/valid/infinity-and-nan.json new file mode 100644 index 0000000..c79e4f8 --- /dev/null +++ b/tests/valid/infinity-and-nan.json @@ -0,0 +1,8 @@ +{ + "nan": {"type": "float", "value": "nan"}, + "nan_neg": {"type": "float", "value": "nan"}, + "nan_plus": {"type": "float", "value": "+nan"}, + "infinity": {"type": "float", "value": "inf"}, + "infinity_neg": {"type": "float", "value": "-inf"}, + "infinity_plus": {"type": "float", "value": "+inf"} +} diff --git a/tests/valid/infinity-and-nan.toml b/tests/valid/infinity-and-nan.toml new file mode 100644 index 0000000..f8386a9 --- /dev/null +++ b/tests/valid/infinity-and-nan.toml @@ -0,0 +1,7 @@ +nan = nan +nan_neg = -nan +nan_plus = +nan +infinity = inf +infinity_neg = -inf +infinity_plus = +inf + From b86946c32c0189cc50719e542dd84c57e21e2e56 Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Fri, 3 Aug 2018 20:35:03 -0400 Subject: [PATCH 05/15] Add tests for dotted keys --- tests/valid/dotted-keys.json | 21 +++++++++++++++++++++ tests/valid/dotted-keys.toml | 5 +++++ 2 files changed, 26 insertions(+) create mode 100644 tests/valid/dotted-keys.json create mode 100644 tests/valid/dotted-keys.toml diff --git a/tests/valid/dotted-keys.json b/tests/valid/dotted-keys.json new file mode 100644 index 0000000..b702537 --- /dev/null +++ b/tests/valid/dotted-keys.json @@ -0,0 +1,21 @@ +{ + "name": { + "first": {"type": "string", "value": "Tom"}, + "last": {"type": "string", "value": "Preston-Werner"} + }, + "point": { + "x": {"type": "integer", "value": "1"}, + "y": {"type": "integer", "value": "2"} + }, + "l1": { + "l2": { + "l3": { + "l4": { + "l5": { + "l6": {"type": "integer", "value": "42"} + } + } + } + } + } +} diff --git a/tests/valid/dotted-keys.toml b/tests/valid/dotted-keys.toml new file mode 100644 index 0000000..f969273 --- /dev/null +++ b/tests/valid/dotted-keys.toml @@ -0,0 +1,5 @@ +name.first = "Tom" +name.last = "Preston-Werner" +point.x = 1 +point.y = 2 +l1.l2.l3 = {l4.l5.l6 = 42} From fee2d5fe5b2346071edaec3170d9f0802d639540 Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 9 Sep 2018 09:55:29 -0400 Subject: [PATCH 06/15] Add tests for bad unicode control characters From https://github.com/iarna 's test --- tests/invalid/string-basic-control-1.toml | Bin 0 -> 12 bytes tests/invalid/string-basic-control-2.toml | 1 + tests/invalid/string-basic-control-3.toml | 1 + tests/invalid/string-basic-control-4.toml | 1 + .../invalid/string-basic-multiline-control-1.toml | Bin 0 -> 16 bytes .../invalid/string-basic-multiline-control-2.toml | 1 + .../invalid/string-basic-multiline-control-3.toml | 1 + .../invalid/string-basic-multiline-control-4.toml | 1 + tests/invalid/string-literal-control-1.toml | Bin 0 -> 12 bytes tests/invalid/string-literal-control-2.toml | 1 + tests/invalid/string-literal-control-3.toml | 1 + tests/invalid/string-literal-control-4.toml | 1 + .../string-literal-multiline-control-1.toml | Bin 0 -> 16 bytes .../string-literal-multiline-control-2.toml | 1 + .../string-literal-multiline-control-3.toml | 1 + .../string-literal-multiline-control-4.toml | 1 + 16 files changed, 12 insertions(+) create mode 100644 tests/invalid/string-basic-control-1.toml create mode 100644 tests/invalid/string-basic-control-2.toml create mode 100644 tests/invalid/string-basic-control-3.toml create mode 100644 tests/invalid/string-basic-control-4.toml create mode 100644 tests/invalid/string-basic-multiline-control-1.toml create mode 100644 tests/invalid/string-basic-multiline-control-2.toml create mode 100644 tests/invalid/string-basic-multiline-control-3.toml create mode 100644 tests/invalid/string-basic-multiline-control-4.toml create mode 100644 tests/invalid/string-literal-control-1.toml create mode 100644 tests/invalid/string-literal-control-2.toml create mode 100644 tests/invalid/string-literal-control-3.toml create mode 100644 tests/invalid/string-literal-control-4.toml create mode 100644 tests/invalid/string-literal-multiline-control-1.toml create mode 100644 tests/invalid/string-literal-multiline-control-2.toml create mode 100644 tests/invalid/string-literal-multiline-control-3.toml create mode 100644 tests/invalid/string-literal-multiline-control-4.toml diff --git a/tests/invalid/string-basic-control-1.toml b/tests/invalid/string-basic-control-1.toml new file mode 100644 index 0000000000000000000000000000000000000000..351f8c7df8bf9d0c19ec9b8d9f211a52a370c50d GIT binary patch literal 12 TcmYdPuvJjXE6vGaP~rjr6l4PE literal 0 HcmV?d00001 diff --git a/tests/invalid/string-basic-control-2.toml b/tests/invalid/string-basic-control-2.toml new file mode 100644 index 0000000..e8c87ef --- /dev/null +++ b/tests/invalid/string-basic-control-2.toml @@ -0,0 +1 @@ +a = "null" diff --git a/tests/invalid/string-basic-control-3.toml b/tests/invalid/string-basic-control-3.toml new file mode 100644 index 0000000..0937f8d --- /dev/null +++ b/tests/invalid/string-basic-control-3.toml @@ -0,0 +1 @@ +a = "null" diff --git a/tests/invalid/string-basic-control-4.toml b/tests/invalid/string-basic-control-4.toml new file mode 100644 index 0000000..21b4ec1 --- /dev/null +++ b/tests/invalid/string-basic-control-4.toml @@ -0,0 +1 @@ +a = "null" diff --git a/tests/invalid/string-basic-multiline-control-1.toml b/tests/invalid/string-basic-multiline-control-1.toml new file mode 100644 index 0000000000000000000000000000000000000000..5b45dcd2e4165e032773a4249fcd15e000bcbed1 GIT binary patch literal 16 VcmYdPuvJh}QpzjM$zcG}TmT=I18@KU literal 0 HcmV?d00001 diff --git a/tests/invalid/string-basic-multiline-control-2.toml b/tests/invalid/string-basic-multiline-control-2.toml new file mode 100644 index 0000000..bb7eeb6 --- /dev/null +++ b/tests/invalid/string-basic-multiline-control-2.toml @@ -0,0 +1 @@ +a = """null""" diff --git a/tests/invalid/string-basic-multiline-control-3.toml b/tests/invalid/string-basic-multiline-control-3.toml new file mode 100644 index 0000000..45e378f --- /dev/null +++ b/tests/invalid/string-basic-multiline-control-3.toml @@ -0,0 +1 @@ +a = """null""" diff --git a/tests/invalid/string-basic-multiline-control-4.toml b/tests/invalid/string-basic-multiline-control-4.toml new file mode 100644 index 0000000..7d788a8 --- /dev/null +++ b/tests/invalid/string-basic-multiline-control-4.toml @@ -0,0 +1 @@ +a = """null""" diff --git a/tests/invalid/string-literal-control-1.toml b/tests/invalid/string-literal-control-1.toml new file mode 100644 index 0000000000000000000000000000000000000000..337fdc4d44fa2ba83d4c68c2533b280eb61d03d2 GIT binary patch literal 12 TcmYdPuvJjcE6vGaQ0D>w6qW+= literal 0 HcmV?d00001 diff --git a/tests/invalid/string-literal-control-2.toml b/tests/invalid/string-literal-control-2.toml new file mode 100644 index 0000000..a09c908 --- /dev/null +++ b/tests/invalid/string-literal-control-2.toml @@ -0,0 +1 @@ +a = 'null' diff --git a/tests/invalid/string-literal-control-3.toml b/tests/invalid/string-literal-control-3.toml new file mode 100644 index 0000000..74697de --- /dev/null +++ b/tests/invalid/string-literal-control-3.toml @@ -0,0 +1 @@ +a = 'null' diff --git a/tests/invalid/string-literal-control-4.toml b/tests/invalid/string-literal-control-4.toml new file mode 100644 index 0000000..6c11637 --- /dev/null +++ b/tests/invalid/string-literal-control-4.toml @@ -0,0 +1 @@ +a = 'null' diff --git a/tests/invalid/string-literal-multiline-control-1.toml b/tests/invalid/string-literal-multiline-control-1.toml new file mode 100644 index 0000000000000000000000000000000000000000..8510285b3a97583867499d9ac8772adc0141802e GIT binary patch literal 16 VcmYdPuvJi3SI;ZW$zcG}TmT?w1C9Uy literal 0 HcmV?d00001 diff --git a/tests/invalid/string-literal-multiline-control-2.toml b/tests/invalid/string-literal-multiline-control-2.toml new file mode 100644 index 0000000..9c02f11 --- /dev/null +++ b/tests/invalid/string-literal-multiline-control-2.toml @@ -0,0 +1 @@ +a = '''null''' diff --git a/tests/invalid/string-literal-multiline-control-3.toml b/tests/invalid/string-literal-multiline-control-3.toml new file mode 100644 index 0000000..0a96cc5 --- /dev/null +++ b/tests/invalid/string-literal-multiline-control-3.toml @@ -0,0 +1 @@ +a = '''null''' diff --git a/tests/invalid/string-literal-multiline-control-4.toml b/tests/invalid/string-literal-multiline-control-4.toml new file mode 100644 index 0000000..da40ffc --- /dev/null +++ b/tests/invalid/string-literal-multiline-control-4.toml @@ -0,0 +1 @@ +a = '''null''' From 9bf3057487c0a8a166787755390712e228a2ff32 Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 9 Sep 2018 09:57:42 -0400 Subject: [PATCH 07/15] Add some extra array tests From https://github.com/iarna 's test --- tests/invalid/array-7.toml | 1 + tests/invalid/array-of-tables-1.toml | 4 ++++ tests/invalid/array-of-tables-2.toml | 10 ++++++++++ 3 files changed, 15 insertions(+) create mode 100644 tests/invalid/array-7.toml create mode 100644 tests/invalid/array-of-tables-1.toml create mode 100644 tests/invalid/array-of-tables-2.toml diff --git a/tests/invalid/array-7.toml b/tests/invalid/array-7.toml new file mode 100644 index 0000000..0991019 --- /dev/null +++ b/tests/invalid/array-7.toml @@ -0,0 +1 @@ +arr6 = [ 1, 2.0 ] # INVALID diff --git a/tests/invalid/array-of-tables-1.toml b/tests/invalid/array-of-tables-1.toml new file mode 100644 index 0000000..01d4d13 --- /dev/null +++ b/tests/invalid/array-of-tables-1.toml @@ -0,0 +1,4 @@ +# INVALID TOML DOC +fruit = [] + +[[fruit]] # Not allowed diff --git a/tests/invalid/array-of-tables-2.toml b/tests/invalid/array-of-tables-2.toml new file mode 100644 index 0000000..a77b0e4 --- /dev/null +++ b/tests/invalid/array-of-tables-2.toml @@ -0,0 +1,10 @@ +# INVALID TOML DOC +[[fruit]] + name = "apple" + + [[fruit.variety]] + name = "red delicious" + + # This table conflicts with the previous table + [fruit.variety] + name = "granny smith" From feb6286e11aac9ca57609f0a8d10630080c7fff6 Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 9 Sep 2018 09:58:45 -0400 Subject: [PATCH 08/15] Add some out of range unicode escaped characters From https://github.com/iarna 's tests --- .../string-basic-multiline-out-of-range-unicode-escape-1.toml | 1 + .../string-basic-multiline-out-of-range-unicode-escape-2.toml | 1 + tests/invalid/string-basic-multiline-unknown-escape.toml | 1 + tests/invalid/string-basic-out-of-range-unicode-escape-1.toml | 1 + tests/invalid/string-basic-out-of-range-unicode-escape-2.toml | 1 + tests/invalid/string-basic-unknown-escape.toml | 1 + 6 files changed, 6 insertions(+) create mode 100644 tests/invalid/string-basic-multiline-out-of-range-unicode-escape-1.toml create mode 100644 tests/invalid/string-basic-multiline-out-of-range-unicode-escape-2.toml create mode 100644 tests/invalid/string-basic-multiline-unknown-escape.toml create mode 100644 tests/invalid/string-basic-out-of-range-unicode-escape-1.toml create mode 100644 tests/invalid/string-basic-out-of-range-unicode-escape-2.toml create mode 100644 tests/invalid/string-basic-unknown-escape.toml diff --git a/tests/invalid/string-basic-multiline-out-of-range-unicode-escape-1.toml b/tests/invalid/string-basic-multiline-out-of-range-unicode-escape-1.toml new file mode 100644 index 0000000..b27e203 --- /dev/null +++ b/tests/invalid/string-basic-multiline-out-of-range-unicode-escape-1.toml @@ -0,0 +1 @@ +a = """\UFFFFFFFF""" diff --git a/tests/invalid/string-basic-multiline-out-of-range-unicode-escape-2.toml b/tests/invalid/string-basic-multiline-out-of-range-unicode-escape-2.toml new file mode 100644 index 0000000..17a9361 --- /dev/null +++ b/tests/invalid/string-basic-multiline-out-of-range-unicode-escape-2.toml @@ -0,0 +1 @@ +a = """\U00D80000""" diff --git a/tests/invalid/string-basic-multiline-unknown-escape.toml b/tests/invalid/string-basic-multiline-unknown-escape.toml new file mode 100644 index 0000000..35c5cc5 --- /dev/null +++ b/tests/invalid/string-basic-multiline-unknown-escape.toml @@ -0,0 +1 @@ +a = """\@""" diff --git a/tests/invalid/string-basic-out-of-range-unicode-escape-1.toml b/tests/invalid/string-basic-out-of-range-unicode-escape-1.toml new file mode 100644 index 0000000..ada1f55 --- /dev/null +++ b/tests/invalid/string-basic-out-of-range-unicode-escape-1.toml @@ -0,0 +1 @@ +a = "\UFFFFFFFF" diff --git a/tests/invalid/string-basic-out-of-range-unicode-escape-2.toml b/tests/invalid/string-basic-out-of-range-unicode-escape-2.toml new file mode 100644 index 0000000..d4833b3 --- /dev/null +++ b/tests/invalid/string-basic-out-of-range-unicode-escape-2.toml @@ -0,0 +1 @@ +a = "\U00D80000" diff --git a/tests/invalid/string-basic-unknown-escape.toml b/tests/invalid/string-basic-unknown-escape.toml new file mode 100644 index 0000000..381dd85 --- /dev/null +++ b/tests/invalid/string-basic-unknown-escape.toml @@ -0,0 +1 @@ +a = "\@" From cd4ad349a7fd0e15fbcfe5ada71714dda6f5a044 Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 9 Sep 2018 09:59:22 -0400 Subject: [PATCH 09/15] Add some tests for invalid bare keys From https://github.com/iarna 's tests --- tests/invalid/bare-key-1.toml | 1 + tests/invalid/bare-key-2.toml | 2 ++ tests/invalid/bare-key-3.toml | 1 + 3 files changed, 4 insertions(+) create mode 100644 tests/invalid/bare-key-1.toml create mode 100644 tests/invalid/bare-key-2.toml create mode 100644 tests/invalid/bare-key-3.toml diff --git a/tests/invalid/bare-key-1.toml b/tests/invalid/bare-key-1.toml new file mode 100644 index 0000000..e50dbe3 --- /dev/null +++ b/tests/invalid/bare-key-1.toml @@ -0,0 +1 @@ +bare!key = 123 diff --git a/tests/invalid/bare-key-2.toml b/tests/invalid/bare-key-2.toml new file mode 100644 index 0000000..24acaa1 --- /dev/null +++ b/tests/invalid/bare-key-2.toml @@ -0,0 +1,2 @@ +barekey + = 123 diff --git a/tests/invalid/bare-key-3.toml b/tests/invalid/bare-key-3.toml new file mode 100644 index 0000000..6aeca14 --- /dev/null +++ b/tests/invalid/bare-key-3.toml @@ -0,0 +1 @@ +barekey = \ No newline at end of file From a333e043c237049c7efa4c98f5870539e726122f Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 9 Sep 2018 10:00:16 -0400 Subject: [PATCH 10/15] Add test for 0 padded int From https://github.com/iarna 's test --- tests/invalid/int-0-padded.toml | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/invalid/int-0-padded.toml diff --git a/tests/invalid/int-0-padded.toml b/tests/invalid/int-0-padded.toml new file mode 100644 index 0000000..74b4032 --- /dev/null +++ b/tests/invalid/int-0-padded.toml @@ -0,0 +1 @@ +int = 0123 From 3ac69cb5f592c2bd40c190f84135b2fb9db18aca Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 9 Sep 2018 10:01:09 -0400 Subject: [PATCH 11/15] Add a couple of tests for invalid redefinition of keys From https://github.com/iarna 's tests --- tests/invalid/multiple-dot-key.toml | 3 +++ tests/invalid/multiple-key.toml | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 tests/invalid/multiple-dot-key.toml create mode 100644 tests/invalid/multiple-key.toml diff --git a/tests/invalid/multiple-dot-key.toml b/tests/invalid/multiple-dot-key.toml new file mode 100644 index 0000000..38d928b --- /dev/null +++ b/tests/invalid/multiple-dot-key.toml @@ -0,0 +1,3 @@ +# THIS IS INVALID +a.b = 1 +a.b.c = 2 diff --git a/tests/invalid/multiple-key.toml b/tests/invalid/multiple-key.toml new file mode 100644 index 0000000..7847bd4 --- /dev/null +++ b/tests/invalid/multiple-key.toml @@ -0,0 +1,3 @@ +# DO NOT DO THIS +name = "Tom" +name = "Pradyun" From 1365b43901b774ded6cd45aa5768da7e824e55b6 Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 9 Sep 2018 10:02:59 -0400 Subject: [PATCH 12/15] Add tests for invalid table definitions --- tests/invalid/table-1.toml | 7 +++++++ tests/invalid/table-2.toml | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/invalid/table-1.toml create mode 100644 tests/invalid/table-2.toml diff --git a/tests/invalid/table-1.toml b/tests/invalid/table-1.toml new file mode 100644 index 0000000..560cbc8 --- /dev/null +++ b/tests/invalid/table-1.toml @@ -0,0 +1,7 @@ +# DO NOT DO THIS + +[a] +b = 1 + +[a] +c = 2 diff --git a/tests/invalid/table-2.toml b/tests/invalid/table-2.toml new file mode 100644 index 0000000..3699f7d --- /dev/null +++ b/tests/invalid/table-2.toml @@ -0,0 +1,7 @@ +# DO NOT DO THIS EITHER + +[a] +b = 1 + +[a.b] +c = 2 From 4d573c0375baf3f357a6c1214dd0af1b8cfc94f8 Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 9 Sep 2018 10:03:07 -0400 Subject: [PATCH 13/15] Add some tests for invalid key/value definitions From https://github.com/iarna 's tests --- tests/invalid/key-value-pair-1.toml | 1 + tests/invalid/no-key-name.toml | 1 + 2 files changed, 2 insertions(+) create mode 100644 tests/invalid/key-value-pair-1.toml create mode 100644 tests/invalid/no-key-name.toml diff --git a/tests/invalid/key-value-pair-1.toml b/tests/invalid/key-value-pair-1.toml new file mode 100644 index 0000000..56f085a --- /dev/null +++ b/tests/invalid/key-value-pair-1.toml @@ -0,0 +1 @@ +key = # INVALID diff --git a/tests/invalid/no-key-name.toml b/tests/invalid/no-key-name.toml new file mode 100644 index 0000000..cd9fa90 --- /dev/null +++ b/tests/invalid/no-key-name.toml @@ -0,0 +1 @@ += "no key name" # INVALID From 67c21d02b06bce14b98d35e897a7b6d248df998e Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 9 Sep 2018 11:05:39 -0400 Subject: [PATCH 14/15] Add test for non decimal integer representations --- tests/invalid/non-dec-integers.toml | 3 +++ tests/valid/non-dec-integers.json | 8 ++++++++ tests/valid/non-dec-integers.toml | 6 ++++++ 3 files changed, 17 insertions(+) create mode 100644 tests/invalid/non-dec-integers.toml create mode 100644 tests/valid/non-dec-integers.json create mode 100644 tests/valid/non-dec-integers.toml diff --git a/tests/invalid/non-dec-integers.toml b/tests/invalid/non-dec-integers.toml new file mode 100644 index 0000000..63c1370 --- /dev/null +++ b/tests/invalid/non-dec-integers.toml @@ -0,0 +1,3 @@ +bin1 = -0b11010110 # non decimal integers are only for non negative +oct1 = 0o_1 +hex3 = 0xdeadbeeg \ No newline at end of file diff --git a/tests/valid/non-dec-integers.json b/tests/valid/non-dec-integers.json new file mode 100644 index 0000000..5b38001 --- /dev/null +++ b/tests/valid/non-dec-integers.json @@ -0,0 +1,8 @@ +{ + "bin1": {"type": "integer", "value": "214"}, + "oct1": {"type": "integer", "value": "342391"}, + "oct2": {"type": "integer", "value": "493"}, + "hex1": {"type": "integer", "value": "3735928559"}, + "hex2": {"type": "integer", "value": "3735928559" }, + "hex3": {"type": "integer", "value": "3735928559"} +} diff --git a/tests/valid/non-dec-integers.toml b/tests/valid/non-dec-integers.toml new file mode 100644 index 0000000..6929c43 --- /dev/null +++ b/tests/valid/non-dec-integers.toml @@ -0,0 +1,6 @@ +bin1 = 0b11010110 +oct1 = 0o01234567 +oct2 = 0o755 +hex1 = 0xDEADBEEF +hex2 = 0xdeadbeef +hex3 = 0xdead_beef From ddae9c6318e7ad07c3001990b2a4e9d11b910a7d Mon Sep 17 00:00:00 2001 From: sergio garcia Date: Sun, 16 Sep 2018 19:19:34 -0400 Subject: [PATCH 15/15] Rename datetime types --- README.md | 6 +++--- json.go | 2 +- tests/valid/local-date.json | 2 +- tests/valid/local-datetime.json | 6 +++--- tests/valid/local-time.json | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 50ce235..d87b016 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,9 @@ In the above, `TTYPE` may be one of: * integer * float * datetime (for offset date-time) -* local-datetime -* local-date -* local-time +* datetime-local +* date +* time * bool * array diff --git a/json.go b/json.go index 0e6940e..dada813 100644 --- a/json.go +++ b/json.go @@ -138,7 +138,7 @@ func (r result) cmpJsonValues(e, t map[string]interface{}) result { return r.cmpFloats(evalue, tvalue); case "datetime": return r.cmpAsDatetimes(evalue, tvalue); - case "local-datetime": + case "datetime-local": return r.cmpAsLocalDateTimes(evalue, tvalue); default: return r.cmpAsStrings(evalue, tvalue); diff --git a/tests/valid/local-date.json b/tests/valid/local-date.json index ff2120e..655607c 100644 --- a/tests/valid/local-date.json +++ b/tests/valid/local-date.json @@ -1,3 +1,3 @@ { - "bestdayever": {"type": "local-date", "value": "1987-07-05"} + "bestdayever": {"type": "date", "value": "1987-07-05"} } diff --git a/tests/valid/local-datetime.json b/tests/valid/local-datetime.json index 59a934f..4636a9d 100644 --- a/tests/valid/local-datetime.json +++ b/tests/valid/local-datetime.json @@ -1,5 +1,5 @@ { - "bestdayever": {"type": "local-datetime", "value": "1987-07-05T17:45:00"}, - "milliseconds": {"type": "local-datetime", "value": "1977-12-21T10:32:00.555"}, - "bestdayever_with_space": {"type": "local-datetime", "value": "1987-07-05T17:45:00"} + "bestdayever": {"type": "datetime-local", "value": "1987-07-05T17:45:00"}, + "milliseconds": {"type": "datetime-local", "value": "1977-12-21T10:32:00.555"}, + "bestdayever_with_space": {"type": "datetime-local", "value": "1987-07-05T17:45:00"} } diff --git a/tests/valid/local-time.json b/tests/valid/local-time.json index a9ff3c8..8a7cc85 100644 --- a/tests/valid/local-time.json +++ b/tests/valid/local-time.json @@ -1,4 +1,4 @@ { - "besttimeever": {"type": "local-time", "value": "17:45:00"}, - "milliseconds": {"type": "local-time", "value": "10:32:00.555"} + "besttimeever": {"type": "time", "value": "17:45:00"}, + "milliseconds": {"type": "time", "value": "10:32:00.555"} }