From 0cb03b864e0310e21cb18005a024d66eb7240d18 Mon Sep 17 00:00:00 2001 From: trobro Date: Sun, 11 Dec 2022 11:22:06 +0100 Subject: [PATCH] Extended testing (#55) --- .github/workflows/test.yml | 12 ++- assets/charset2_result.json | 2 +- assets/charset_result.json | 2 +- assets/comments2/charset2_result.hjson | 5 + assets/comments2/charset_result.hjson | 5 + assets/comments2/comments2_result.hjson | 3 + assets/comments2/comments3_result.hjson | 3 + assets/comments2/comments4_result.hjson | 51 +++++++++ assets/comments2/comments5_result.hjson | 51 +++++++++ assets/comments2/comments6_result.hjson | 4 + assets/comments2/comments7_result.hjson | 10 ++ assets/comments2/comments_result.hjson | 42 ++++++++ assets/comments2/empty_result.hjson | 3 + assets/comments2/int64_result.hjson | 3 + assets/comments2/kan_result.hjson | 46 +++++++++ assets/comments2/keys_result.hjson | 43 ++++++++ assets/comments2/mltabs_result.hjson | 8 ++ assets/comments2/oa_result.hjson | 13 +++ assets/comments2/pass1_result.hjson | 75 ++++++++++++++ assets/comments2/pass2_result.hjson | 39 +++++++ assets/comments2/pass3_result.hjson | 6 ++ assets/comments2/pass4_result.hjson | 1 + assets/comments2/pass5_result.hjson | 4 + assets/comments2/passSingle_result.hjson | 1 + assets/comments2/root_result.hjson | 6 ++ assets/comments2/stringify1_result.hjson | 48 +++++++++ assets/comments2/strings2_result.hjson | 33 ++++++ assets/comments2/strings3_result.hjson | 6 ++ assets/comments2/strings_result.hjson | 91 ++++++++++++++++ assets/comments2/trail_result.hjson | 4 + assets/comments2/windowseol_result.hjson | 10 ++ assets/comments2_result.hjson | 1 + assets/comments2_result.json | 1 + assets/comments2_test.hjson | 3 + assets/comments3/charset2_result.hjson | 5 + assets/comments3/charset_result.hjson | 6 ++ assets/comments3/comments2_result.hjson | 3 + assets/comments3/comments3_result.hjson | 3 + assets/comments3/comments4_result.hjson | 51 +++++++++ assets/comments3/comments5_result.hjson | 51 +++++++++ assets/comments3/comments6_result.hjson | 4 + assets/comments3/comments7_result.hjson | 10 ++ assets/comments3/comments_result.hjson | 48 +++++++++ assets/comments3/empty_result.hjson | 3 + assets/comments3/int64_result.hjson | 3 + assets/comments3/kan_result.hjson | 49 +++++++++ assets/comments3/keys_result.hjson | 48 +++++++++ assets/comments3/mltabs_result.hjson | 8 ++ assets/comments3/oa_result.hjson | 13 +++ assets/comments3/pass1_result.hjson | 81 +++++++++++++++ assets/comments3/pass2_result.hjson | 39 +++++++ assets/comments3/pass3_result.hjson | 6 ++ assets/comments3/pass4_result.hjson | 2 + assets/comments3/pass5_result.hjson | 4 + assets/comments3/passSingle_result.hjson | 1 + assets/comments3/root_result.hjson | 6 ++ assets/comments3/stringify1_result.hjson | 50 +++++++++ assets/comments3/strings2_result.hjson | 36 +++++++ assets/comments3/strings3_result.hjson | 6 ++ assets/comments3/strings_result.hjson | 104 +++++++++++++++++++ assets/comments3/trail_result.hjson | 4 + assets/comments3/windowseol_result.hjson | 11 ++ assets/comments3_result.hjson | 1 + assets/comments3_result.json | 1 + assets/comments3_test.hjson | 3 + assets/comments4_result.hjson | 23 +++++ assets/comments4_result.json | 23 +++++ assets/comments4_test.hjson | 51 +++++++++ assets/comments5_result.hjson | 23 +++++ assets/comments5_result.json | 23 +++++ assets/comments5_test.hjson | 51 +++++++++ assets/comments6_result.hjson | 1 + assets/comments6_result.json | 1 + assets/comments6_test.hjson | 4 + assets/comments7_result.hjson | 7 ++ assets/comments7_result.json | 7 ++ assets/comments7_test.hjson | 8 ++ assets/comments_result.json | 2 +- assets/empty_result.json | 2 +- assets/failJSON02_test.json | 2 +- assets/failJSON05_test.json | 2 +- assets/failJSON06_test.json | 2 +- assets/failJSON07_test.json | 2 +- assets/failJSON08_test.json | 2 +- assets/failJSON10_test.json | 2 +- assets/failJSON11_test.json | 2 +- assets/failJSON12_test.json | 2 +- assets/failJSON13_test.json | 2 +- assets/failJSON14_test.json | 2 +- assets/failJSON15_test.json | 2 +- assets/failJSON16_test.json | 2 +- assets/failJSON17_test.json | 2 +- assets/failJSON19_test.json | 2 +- assets/failJSON20_test.json | 2 +- assets/failJSON21_test.json | 2 +- assets/failJSON22_test.json | 2 +- assets/failJSON23_test.json | 2 +- assets/failJSON24_test.json | 2 +- assets/failJSON26_test.json | 2 +- assets/failJSON28_test.json | 2 +- assets/failJSON29_test.json | 2 +- assets/failJSON30_test.json | 2 +- assets/failJSON31_test.json | 2 +- assets/failJSON32_test.json | 2 +- assets/failJSON33_test.json | 2 +- assets/int64_result.hjson | 3 + assets/int64_result.json | 3 + assets/int64_test.hjson | 3 + assets/kan_result.json | 2 +- assets/keys_result.json | 2 +- assets/mltabs_result.json | 2 +- assets/oa_result.json | 2 +- assets/pass1_result.json | 2 +- assets/pass1_test.json | 2 +- assets/pass2_result.json | 2 +- assets/pass2_test.json | 2 +- assets/pass3_result.json | 2 +- assets/pass4_result.json | 2 +- assets/pass5_result.hjson | 4 + assets/pass5_result.json | 4 + assets/pass5_test.hjson | 4 + assets/passSingle_result.json | 2 +- assets/passSingle_test.hjson | 2 +- assets/root_result.json | 2 +- assets/sorted/charset2_result.json | 2 +- assets/sorted/charset_result.json | 2 +- assets/sorted/comments2_result.hjson | 1 + assets/sorted/comments2_result.json | 1 + assets/sorted/comments3_result.hjson | 1 + assets/sorted/comments3_result.json | 1 + assets/sorted/comments4_result.hjson | 23 +++++ assets/sorted/comments4_result.json | 23 +++++ assets/sorted/comments5_result.hjson | 23 +++++ assets/sorted/comments5_result.json | 23 +++++ assets/sorted/comments6_result.hjson | 1 + assets/sorted/comments6_result.json | 1 + assets/sorted/comments7_result.hjson | 7 ++ assets/sorted/comments7_result.json | 7 ++ assets/sorted/comments_result.json | 2 +- assets/sorted/empty_result.json | 2 +- assets/sorted/int64_result.hjson | 3 + assets/sorted/int64_result.json | 3 + assets/sorted/kan_result.json | 4 +- assets/sorted/keys_result.json | 2 +- assets/sorted/mltabs_result.json | 2 +- assets/sorted/oa_result.json | 2 +- assets/sorted/pass1_result.json | 2 +- assets/sorted/pass2_result.json | 2 +- assets/sorted/pass3_result.json | 2 +- assets/sorted/pass4_result.json | 2 +- assets/sorted/pass5_result.hjson | 4 + assets/sorted/pass5_result.json | 4 + assets/sorted/passSingle_result.json | 2 +- assets/sorted/root_result.json | 2 +- assets/sorted/stringify1_result.json | 2 +- assets/sorted/strings2_result.json | 2 +- assets/sorted/strings3_result.hjson | 4 + assets/sorted/strings3_result.json | 4 + assets/sorted/strings_result.json | 2 +- assets/sorted/trail_result.json | 2 +- assets/sorted/windowseol_result.hjson | 10 ++ assets/sorted/windowseol_result.json | 6 ++ assets/stringify1_result.json | 2 +- assets/strings2_result.json | 2 +- assets/strings3_result.hjson | 4 + assets/strings3_result.json | 4 + assets/strings3_test.hjson | 6 ++ assets/strings_result.json | 2 +- assets/testlist.txt | 12 ++- assets/trail_result.json | 2 +- assets/windowseol_result.hjson | 10 ++ assets/windowseol_result.json | 6 ++ assets/windowseol_test.hjson | 13 +++ hjson_test.go | 126 ++++++++++++++++++----- 174 files changed, 1902 insertions(+), 95 deletions(-) create mode 100644 assets/comments2/charset2_result.hjson create mode 100644 assets/comments2/charset_result.hjson create mode 100644 assets/comments2/comments2_result.hjson create mode 100644 assets/comments2/comments3_result.hjson create mode 100644 assets/comments2/comments4_result.hjson create mode 100644 assets/comments2/comments5_result.hjson create mode 100644 assets/comments2/comments6_result.hjson create mode 100644 assets/comments2/comments7_result.hjson create mode 100644 assets/comments2/comments_result.hjson create mode 100644 assets/comments2/empty_result.hjson create mode 100644 assets/comments2/int64_result.hjson create mode 100644 assets/comments2/kan_result.hjson create mode 100644 assets/comments2/keys_result.hjson create mode 100644 assets/comments2/mltabs_result.hjson create mode 100644 assets/comments2/oa_result.hjson create mode 100644 assets/comments2/pass1_result.hjson create mode 100644 assets/comments2/pass2_result.hjson create mode 100644 assets/comments2/pass3_result.hjson create mode 100644 assets/comments2/pass4_result.hjson create mode 100644 assets/comments2/pass5_result.hjson create mode 100644 assets/comments2/passSingle_result.hjson create mode 100644 assets/comments2/root_result.hjson create mode 100644 assets/comments2/stringify1_result.hjson create mode 100644 assets/comments2/strings2_result.hjson create mode 100644 assets/comments2/strings3_result.hjson create mode 100644 assets/comments2/strings_result.hjson create mode 100644 assets/comments2/trail_result.hjson create mode 100644 assets/comments2/windowseol_result.hjson create mode 100644 assets/comments2_result.hjson create mode 100644 assets/comments2_result.json create mode 100644 assets/comments2_test.hjson create mode 100644 assets/comments3/charset2_result.hjson create mode 100644 assets/comments3/charset_result.hjson create mode 100644 assets/comments3/comments2_result.hjson create mode 100644 assets/comments3/comments3_result.hjson create mode 100644 assets/comments3/comments4_result.hjson create mode 100644 assets/comments3/comments5_result.hjson create mode 100644 assets/comments3/comments6_result.hjson create mode 100644 assets/comments3/comments7_result.hjson create mode 100644 assets/comments3/comments_result.hjson create mode 100644 assets/comments3/empty_result.hjson create mode 100644 assets/comments3/int64_result.hjson create mode 100644 assets/comments3/kan_result.hjson create mode 100644 assets/comments3/keys_result.hjson create mode 100644 assets/comments3/mltabs_result.hjson create mode 100644 assets/comments3/oa_result.hjson create mode 100644 assets/comments3/pass1_result.hjson create mode 100644 assets/comments3/pass2_result.hjson create mode 100644 assets/comments3/pass3_result.hjson create mode 100644 assets/comments3/pass4_result.hjson create mode 100644 assets/comments3/pass5_result.hjson create mode 100644 assets/comments3/passSingle_result.hjson create mode 100644 assets/comments3/root_result.hjson create mode 100644 assets/comments3/stringify1_result.hjson create mode 100644 assets/comments3/strings2_result.hjson create mode 100644 assets/comments3/strings3_result.hjson create mode 100644 assets/comments3/strings_result.hjson create mode 100644 assets/comments3/trail_result.hjson create mode 100644 assets/comments3/windowseol_result.hjson create mode 100644 assets/comments3_result.hjson create mode 100644 assets/comments3_result.json create mode 100644 assets/comments3_test.hjson create mode 100644 assets/comments4_result.hjson create mode 100644 assets/comments4_result.json create mode 100644 assets/comments4_test.hjson create mode 100644 assets/comments5_result.hjson create mode 100644 assets/comments5_result.json create mode 100644 assets/comments5_test.hjson create mode 100644 assets/comments6_result.hjson create mode 100644 assets/comments6_result.json create mode 100644 assets/comments6_test.hjson create mode 100644 assets/comments7_result.hjson create mode 100644 assets/comments7_result.json create mode 100644 assets/comments7_test.hjson create mode 100644 assets/int64_result.hjson create mode 100644 assets/int64_result.json create mode 100644 assets/int64_test.hjson create mode 100644 assets/pass5_result.hjson create mode 100644 assets/pass5_result.json create mode 100644 assets/pass5_test.hjson create mode 100644 assets/sorted/comments2_result.hjson create mode 100644 assets/sorted/comments2_result.json create mode 100644 assets/sorted/comments3_result.hjson create mode 100644 assets/sorted/comments3_result.json create mode 100644 assets/sorted/comments4_result.hjson create mode 100644 assets/sorted/comments4_result.json create mode 100644 assets/sorted/comments5_result.hjson create mode 100644 assets/sorted/comments5_result.json create mode 100644 assets/sorted/comments6_result.hjson create mode 100644 assets/sorted/comments6_result.json create mode 100644 assets/sorted/comments7_result.hjson create mode 100644 assets/sorted/comments7_result.json create mode 100644 assets/sorted/int64_result.hjson create mode 100644 assets/sorted/int64_result.json create mode 100644 assets/sorted/pass5_result.hjson create mode 100644 assets/sorted/pass5_result.json create mode 100644 assets/sorted/strings3_result.hjson create mode 100644 assets/sorted/strings3_result.json create mode 100644 assets/sorted/windowseol_result.hjson create mode 100644 assets/sorted/windowseol_result.json create mode 100644 assets/strings3_result.hjson create mode 100644 assets/strings3_result.json create mode 100644 assets/strings3_test.hjson create mode 100644 assets/windowseol_result.hjson create mode 100644 assets/windowseol_result.json create mode 100644 assets/windowseol_test.hjson diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3f80711..eeb30e4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,12 @@ jobs: - uses: actions/checkout@v3 - run: go version - run: go test -v - - run: | - cd hjson-cli - go install + - run: cd hjson-cli && go build + - if: runner.os == 'Linux' + run: hjson-cli/hjson-cli assets/comments_test.hjson | diff assets/sorted/comments_result.hjson - + - if: runner.os == 'Linux' + run: hjson-cli/hjson-cli -j assets/comments_test.hjson | diff assets/sorted/comments_result.json - + - if: runner.os == 'Linux' + run: hjson-cli/hjson-cli -preserveKeyOrder assets/comments_test.hjson | diff assets/comments_result.hjson - + - if: runner.os == 'Linux' + run: hjson-cli/hjson-cli -j -preserveKeyOrder assets/comments_test.hjson | diff assets/comments_result.json - diff --git a/assets/charset2_result.json b/assets/charset2_result.json index fe725ce..eca8829 100644 --- a/assets/charset2_result.json +++ b/assets/charset2_result.json @@ -2,4 +2,4 @@ "uescape": "\u0000,\u0001,￿", "umlaut": "äöüßÄÖÜ", "hex": "ģ䕧覫췯ꯍ" -} \ No newline at end of file +} diff --git a/assets/charset_result.json b/assets/charset_result.json index 6357d96..1e7db78 100644 --- a/assets/charset_result.json +++ b/assets/charset_result.json @@ -2,4 +2,4 @@ "ql-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", "js-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", "ml-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" -} \ No newline at end of file +} diff --git a/assets/comments2/charset2_result.hjson b/assets/comments2/charset2_result.hjson new file mode 100644 index 0000000..38f25c1 --- /dev/null +++ b/assets/comments2/charset2_result.hjson @@ -0,0 +1,5 @@ +{ + uescape: "\u0000,\u0001,\uffff" + umlaut: äöüßÄÖÜ + hex: ģ䕧覫췯ꯍ +} diff --git a/assets/comments2/charset_result.hjson b/assets/comments2/charset_result.hjson new file mode 100644 index 0000000..b7bd289 --- /dev/null +++ b/assets/comments2/charset_result.hjson @@ -0,0 +1,5 @@ +{ + ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + js-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + ml-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ +} diff --git a/assets/comments2/comments2_result.hjson b/assets/comments2/comments2_result.hjson new file mode 100644 index 0000000..0756a59 --- /dev/null +++ b/assets/comments2/comments2_result.hjson @@ -0,0 +1,3 @@ +// before +/* before2 */ 3 // after1 +// after2 diff --git a/assets/comments2/comments3_result.hjson b/assets/comments2/comments3_result.hjson new file mode 100644 index 0000000..a59bc4e --- /dev/null +++ b/assets/comments2/comments3_result.hjson @@ -0,0 +1,3 @@ +// before +/* before2 */ a string value // still part of the string +// after2 diff --git a/assets/comments2/comments4_result.hjson b/assets/comments2/comments4_result.hjson new file mode 100644 index 0000000..57e1d5a --- /dev/null +++ b/assets/comments2/comments4_result.hjson @@ -0,0 +1,51 @@ +// before +/* before2 */ [ #before1 + /*key1keycm*/a string value // still part of the string + /* key2keycm */ "a string value" // not part of the string + // map1before + /* map1key */ + {}//map2after + {} + { + // map3 inner comment + } + [] + // map4before + /*map4key*/{ + /* map4inner */ + } // map4after + //map5before + /*map5key*/ { + //map5ab4 + val5a: /* map5akey */ 1 // map5aAfter + val5b: 2 /* map5bb4comma */ #map5bAfter + #map5extra + } /* map5after */ + // vec1bbefore + /* vec1bkey */ + []//vec1bafter + [] + [ + // vec3 inner comment + ] + // vec4before + /*vec4key*/[ + /* vec4inner */ + ] // vec4after + //vec5before + /*vec5key*/ [ + //vec5ab4 + 1 // vec5aAfter + 2 /* vec5bb4comma */ #vec5bAfter + #vec5extra + ] /* map5after */ + // before3 + + 3 # after3 + # before4 + /*before4b*/4/*after4*/ + #after4b +] +// after2 + +/* after3 */ diff --git a/assets/comments2/comments5_result.hjson b/assets/comments2/comments5_result.hjson new file mode 100644 index 0000000..fafdff2 --- /dev/null +++ b/assets/comments2/comments5_result.hjson @@ -0,0 +1,51 @@ +// before +/* before2 */ { #before1 + key1:/*key1keycm*/a string value // still part of the string + key2: /* key2keycm */ "a string value" // not part of the string + // map1before + map1: /* map1key */ + {}//map2after + map2: {} + map3: { + // map3 inner comment + } + vec1: [] + // map4before + map4:/*map4key*/{ + /* map4inner */ + } // map4after + //map5before + map5: /*map5key*/ { + //map5ab4 + val5a: /* map5akey */ 1 // map5aAfter + val5b: 2 /* map5bb4comma */ #map5bAfter + #map5extra + } /* map5after */ + // vec1bbefore + vec1b: /* vec1bkey */ + []//vec1bafter + vec2: [] + vec3: [ + // vec3 inner comment + ] + // vec4before + vec4:/*vec4key*/[ + /* vec4inner */ + ] // vec4after + //vec5before + vec5: /*vec5key*/ [ + //vec5ab4 + 1 // vec5aAfter + 2 /* vec5bb4comma */ #vec5bAfter + #vec5extra + ] /* map5after */ + // before3 + + key3: 3 # after3 + # before4 + /*before4b*/key4: 4/*after4*/ + #after4b +} +// after2 + +/* after3 */ diff --git a/assets/comments2/comments6_result.hjson b/assets/comments2/comments6_result.hjson new file mode 100644 index 0000000..db31dd5 --- /dev/null +++ b/assets/comments2/comments6_result.hjson @@ -0,0 +1,4 @@ +// before +/* before2 */ 3 // after1 +// after2 + diff --git a/assets/comments2/comments7_result.hjson b/assets/comments2/comments7_result.hjson new file mode 100644 index 0000000..ab51af9 --- /dev/null +++ b/assets/comments2/comments7_result.hjson @@ -0,0 +1,10 @@ +{ +# comment before +b: /* key comment */ { + sub1: 3 # comment after + sub2: 4 # comment more after + } # cm after obj +// Comment B4 +a: 2 +/* Last comment */ +} diff --git a/assets/comments2/comments_result.hjson b/assets/comments2/comments_result.hjson new file mode 100644 index 0000000..6a1170a --- /dev/null +++ b/assets/comments2/comments_result.hjson @@ -0,0 +1,42 @@ +// test +# all +// comment +/* +styles +*/ +# with lf + + + +# ! + +{ + # hjson style comment + foo1: This is a string value. # part of the string + foo2: "This is a string value." # a comment + + // js style comment + bar1: This is a string value. // part of the string + bar2: "This is a string value." // a comment + + /* js block style comments */foobar1:/* more */This is a string value./* part of the string */ + /* js block style comments */foobar2:/* more */"This is a string value."/* a comment */ + rem1: "# test" + rem2: "// test" + rem3: "/* test */" + num1: 0 # comment + num2: 0 // comment + num3: 2 /* comment */ + true1: true # comment + true2: true // comment + true3: true /* comment */ + false1: false # comment + false2: false // comment + false3: false /* comment */ + null1: null # comment + null2: null // comment + null3: null /* comment */ + str1: 00 # part of the string + str2: 00.0 // part of the string + str3: 02 /* part of the string */ +} diff --git a/assets/comments2/empty_result.hjson b/assets/comments2/empty_result.hjson new file mode 100644 index 0000000..ac97a9d --- /dev/null +++ b/assets/comments2/empty_result.hjson @@ -0,0 +1,3 @@ +{ + "": empty +} diff --git a/assets/comments2/int64_result.hjson b/assets/comments2/int64_result.hjson new file mode 100644 index 0000000..a45ecc8 --- /dev/null +++ b/assets/comments2/int64_result.hjson @@ -0,0 +1,3 @@ +{ + bigInt: 144115188075855870 +} diff --git a/assets/comments2/kan_result.hjson b/assets/comments2/kan_result.hjson new file mode 100644 index 0000000..f6ebfae --- /dev/null +++ b/assets/comments2/kan_result.hjson @@ -0,0 +1,46 @@ +{ + # the comma forces a whitespace check + numbers: [ + 0 + 0 + 0 + 42 + 42.1 + -5 + -5.1 + 1701 + -1701 + 12.345 + -12.345 + ] + native: [ + true + true + false + false + null + null + ] + strings: [ + x 0 + .0 + 00 + 01 + 0 0 0 + 42 x + 42.1 asdf + 1.2.3 + -5 0 - + -5.1 -- + 17.01e2 + + -17.01e2 : + 12345e-3 @ + -12345e-3 $ + true true + x true + false false + x false + null null + x null + ] +} diff --git a/assets/comments2/keys_result.hjson b/assets/comments2/keys_result.hjson new file mode 100644 index 0000000..a8aaefd --- /dev/null +++ b/assets/comments2/keys_result.hjson @@ -0,0 +1,43 @@ +{ + # unquoted keys + unquoted_key: test + _unquoted: test + test-key: test + -test: test + .key: test + # trailing spaces in key names are ignored + trailing: test + trailing2: test + # comment char in key name + "#c1": test + "foo#bar": test + "//bar": test + "foo//bar": test + "/*foo*/": test + "foo/*foo*/bar": test + "/*": test + "foo/*bar": test + # quotes in key name + "\"": test + "foo\"bar": test + "'''": test + "foo'''bar": test + "'": test + "'foo": test + "foo'bar": test + # control char in key name + ":": test + "foo:bar": test + "{": test + "foo{bar": test + "}": test + "foo}bar": test + "[": test + "foo[bar": test + "]": test + "foo]bar": test + # newline + nl1: test + nl2: test + nl3: test +} diff --git a/assets/comments2/mltabs_result.hjson b/assets/comments2/mltabs_result.hjson new file mode 100644 index 0000000..d628bf6 --- /dev/null +++ b/assets/comments2/mltabs_result.hjson @@ -0,0 +1,8 @@ +{ + foo: + ''' + bar joe + oki doki + two tabs + ''' +} diff --git a/assets/comments2/oa_result.hjson b/assets/comments2/oa_result.hjson new file mode 100644 index 0000000..35bcdb4 --- /dev/null +++ b/assets/comments2/oa_result.hjson @@ -0,0 +1,13 @@ +[ + a + {} + {} + [] + [] + { + b: 1 + c: [] + d: {} + } + [] +] diff --git a/assets/comments2/pass1_result.hjson b/assets/comments2/pass1_result.hjson new file mode 100644 index 0000000..2cc3dce --- /dev/null +++ b/assets/comments2/pass1_result.hjson @@ -0,0 +1,75 @@ +[ + JSON Test Pattern pass1 + { + "object with 1 member": [ + array with 1 element + ] + } + {} + [] + -42 + true + false + null + { + integer: 1234567890 + real: -9876.54321 + e: 1.23456789e-13 + E: 1.23456789e+34 + -: 2.3456789012e+76 + zero: 0 + one: 1 + space: " " + quote: '''"''' + backslash: \ + controls: "\b\f\n\r\t" + slash: / & / + alpha: abcdefghijklmnopqrstuvwyz + ALPHA: ABCDEFGHIJKLMNOPQRSTUVWYZ + digit: 0123456789 + 0123456789: digit + special: `1~!@#$%^&*()_+-={':[,]}|;.? + hex: ģ䕧覫췯ꯍ + true: true + false: false + null: null + array: [] + object: {} + address: 50 St. James Street + url: http://www.JSON.org/ + comment: "// /* */": " " + " s p a c e d ": [ + 1 + 2 + 3 + 4 + 5 + 6 + 7 + ] + compact: [ + 1 + 2 + 3 + 4 + 5 + 6 + 7 + ] + jsontext: '''{"object with 1 member":["array with 1 element"]}''' + quotes: " " %22 0x22 034 " + "/\\\"쫾몾ꮘﳞ볚\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?": A key can be any string + } + 0.5 + 98.6 + 99.44 + 1066 + 10 + 1 + 0.1 + 1 + 2 + 2 + rosebud +] diff --git a/assets/comments2/pass2_result.hjson b/assets/comments2/pass2_result.hjson new file mode 100644 index 0000000..25a5bd4 --- /dev/null +++ b/assets/comments2/pass2_result.hjson @@ -0,0 +1,39 @@ +[ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + Not too deep + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] +] diff --git a/assets/comments2/pass3_result.hjson b/assets/comments2/pass3_result.hjson new file mode 100644 index 0000000..091f438 --- /dev/null +++ b/assets/comments2/pass3_result.hjson @@ -0,0 +1,6 @@ +{ + "JSON Test Pattern pass3": { + "The outermost value": must be an object or array. + "In this test": It is an object. + } +} diff --git a/assets/comments2/pass4_result.hjson b/assets/comments2/pass4_result.hjson new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/assets/comments2/pass4_result.hjson @@ -0,0 +1 @@ +10 diff --git a/assets/comments2/pass5_result.hjson b/assets/comments2/pass5_result.hjson new file mode 100644 index 0000000..b5697b8 --- /dev/null +++ b/assets/comments2/pass5_result.hjson @@ -0,0 +1,4 @@ +{ + bigDouble: 9.223372036854776e+58 + bigInt: 9.223372036854776e+58 +} diff --git a/assets/comments2/passSingle_result.hjson b/assets/comments2/passSingle_result.hjson new file mode 100644 index 0000000..da0c9e2 --- /dev/null +++ b/assets/comments2/passSingle_result.hjson @@ -0,0 +1 @@ +allow quoteless strings diff --git a/assets/comments2/root_result.hjson b/assets/comments2/root_result.hjson new file mode 100644 index 0000000..c0acd16 --- /dev/null +++ b/assets/comments2/root_result.hjson @@ -0,0 +1,6 @@ +// a object with the root braces omitted +database: +{ + host: 127.0.0.1 + port: 555 +} diff --git a/assets/comments2/stringify1_result.hjson b/assets/comments2/stringify1_result.hjson new file mode 100644 index 0000000..3b3f504 --- /dev/null +++ b/assets/comments2/stringify1_result.hjson @@ -0,0 +1,48 @@ +// test if stringify produces correct output +{ + quotes: { + num1: "1,2" + num2: "-1.1 ," + num3: "1e10 ,2" + num4: "-1e-10," + kw1: "true," + kw2: "false ," + kw3: "null,123" + close1: "1}" + close1b: "1 }" + close2: "1]" + close2b: "1 ]" + close3: "1," + close3b: "1 ," + comment1: "1#str" + comment2: "1//str" + comment3: "1/*str*/" + punc1: "{" + punc1b: "{foo" + punc2: "}" + punc2b: "}foo" + punc3: "[" + punc3b: "[foo" + punc4: "]" + punc4b: "]foo" + punc5: "," + punc5b: ",foo" + punc6: ":" + punc6b: ":foo" + } + noquotes: { + num0: .1,2 + num1: 1.1.1,2 + num2: -.1, + num3: 1e10e,2 + num4: -1e--10, + kw1: true1, + kw2: false0, + kw3: null0, + close1: a} + close2: a] + comment1: a#str + comment2: a//str + comment3: a/*str*/ + } +} diff --git a/assets/comments2/strings2_result.hjson b/assets/comments2/strings2_result.hjson new file mode 100644 index 0000000..0b84135 --- /dev/null +++ b/assets/comments2/strings2_result.hjson @@ -0,0 +1,33 @@ +{ + # Hjson 3 allows the use of single quotes + + key1: a key in single quotes + "key 2": a key in single quotes + "key \"": a key in single quotes + text: [ + single quoted string + '''You need quotes for escapes''' + " untrimmed " + "untrimmed " + containing " double quotes + containing " double quotes + containing " double quotes + '''"containing more " double quotes"''' + containing ' single quotes + containing ' single quotes + containing ' single quotes + "'containing more ' single quotes'" + "'containing more ' single quotes'" + "\n" + " \n" + "\n \n \n \n" + "\t\n" + ] + + # escapes/no escape + + foo3a: asdf''' + foo3b: "'''asdf" + foo4a: "asdf'''\nasdf" + foo4b: "asdf\n'''asdf" +} diff --git a/assets/comments2/strings3_result.hjson b/assets/comments2/strings3_result.hjson new file mode 100644 index 0000000..6811103 --- /dev/null +++ b/assets/comments2/strings3_result.hjson @@ -0,0 +1,6 @@ +{ + // Empty string + a: "" + // Unicode code points that require escape inside quotes. + b: "\u00ad\u0600\u0604\u070f\u17b4\u17b5\u200c\u200f\u2028\u202f\u2060\u206f\ufeff\ufff0\uffff" +} diff --git a/assets/comments2/strings_result.hjson b/assets/comments2/strings_result.hjson new file mode 100644 index 0000000..a5fa3ba --- /dev/null +++ b/assets/comments2/strings_result.hjson @@ -0,0 +1,91 @@ +{ + # simple + + text1: This is a valid string value. + text2: a \ is just a \ + text3: '''You need quotes for escapes''' + text4a: " untrimmed " + text4b: " untrimmed" + text4c: "untrimmed " + notml1: "\n" + notml2: " \n" + notml3: "\n \n \n \n" + notml4: "\t\n" + + # multiline string + + multiline1: + ''' + first line + indented line + last line + ''' + multiline2: + ''' + first line + indented line + last line + ''' + multiline3: + ''' + first line + indented line + last line + + ''' # trailing lf + multiline4: ←→±≠Я + + # escapes/no escape + + foo1a: asdf\"'a\s\w + foo1b: asdf\"'a\s\w + foo1c: asdf\"'a\s\w + foo2a: '''"asdf"''' + foo2b: '''"asdf"''' + foo3a: asdf''' + foo3b: "'''asdf" + foo4a: "asdf'''\nasdf" + foo4b: "asdf\n'''asdf" + + # in arrays + arr: [ + one + two + three + four + ] + + # not strings + not: { + number: 5 + negative: -4.2 + yes: true + no: false + null: null + array: [ + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + -1 + 0.5 + ] + } + + # special quoted + special: { + true: "true" + false: "false" + null: "null" + one: "1" + two: "2" + minus: "-3" + zero: "0" + } +} diff --git a/assets/comments2/trail_result.hjson b/assets/comments2/trail_result.hjson new file mode 100644 index 0000000..6d32a4d --- /dev/null +++ b/assets/comments2/trail_result.hjson @@ -0,0 +1,4 @@ +{ + // the following line contains trailing whitespace: + foo: 0 -- this string starts at 0 and ends at 1, preceding and trailing whitespace is ignored -- 1 +} diff --git a/assets/comments2/windowseol_result.hjson b/assets/comments2/windowseol_result.hjson new file mode 100644 index 0000000..90d9564 --- /dev/null +++ b/assets/comments2/windowseol_result.hjson @@ -0,0 +1,10 @@ +{ + ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + js-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + ml-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + newline: + ''' + 1 + 2 + ''' +} diff --git a/assets/comments2_result.hjson b/assets/comments2_result.hjson new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/assets/comments2_result.hjson @@ -0,0 +1 @@ +3 diff --git a/assets/comments2_result.json b/assets/comments2_result.json new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/assets/comments2_result.json @@ -0,0 +1 @@ +3 diff --git a/assets/comments2_test.hjson b/assets/comments2_test.hjson new file mode 100644 index 0000000..0756a59 --- /dev/null +++ b/assets/comments2_test.hjson @@ -0,0 +1,3 @@ +// before +/* before2 */ 3 // after1 +// after2 diff --git a/assets/comments3/charset2_result.hjson b/assets/comments3/charset2_result.hjson new file mode 100644 index 0000000..38f25c1 --- /dev/null +++ b/assets/comments3/charset2_result.hjson @@ -0,0 +1,5 @@ +{ + uescape: "\u0000,\u0001,\uffff" + umlaut: äöüßÄÖÜ + hex: ģ䕧覫췯ꯍ +} diff --git a/assets/comments3/charset_result.hjson b/assets/comments3/charset_result.hjson new file mode 100644 index 0000000..5108ce5 --- /dev/null +++ b/assets/comments3/charset_result.hjson @@ -0,0 +1,6 @@ +{ + ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + js-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + ml-ascii: + ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ +} diff --git a/assets/comments3/comments2_result.hjson b/assets/comments3/comments2_result.hjson new file mode 100644 index 0000000..0756a59 --- /dev/null +++ b/assets/comments3/comments2_result.hjson @@ -0,0 +1,3 @@ +// before +/* before2 */ 3 // after1 +// after2 diff --git a/assets/comments3/comments3_result.hjson b/assets/comments3/comments3_result.hjson new file mode 100644 index 0000000..a59bc4e --- /dev/null +++ b/assets/comments3/comments3_result.hjson @@ -0,0 +1,3 @@ +// before +/* before2 */ a string value // still part of the string +// after2 diff --git a/assets/comments3/comments4_result.hjson b/assets/comments3/comments4_result.hjson new file mode 100644 index 0000000..9d85df4 --- /dev/null +++ b/assets/comments3/comments4_result.hjson @@ -0,0 +1,51 @@ +// before +/* before2 */ [ #before1 + /*key1keycm*/a string value // still part of the string + /* key2keycm */ "a string value" // not part of the string + // map1before + /* map1key */ + {}//map2after + {} + { + // map3 inner comment + } + [] + // map4before + /*map4key*/{ + /* map4inner */ + } // map4after + //map5before + /*map5key*/ { + //map5ab4 + val5a: /* map5akey */ 1 // map5aAfter + val5b: 2 /* map5bb4comma */ #map5bAfter + #map5extra + } /* map5after */ + // vec1bbefore + /* vec1bkey */ + []//vec1bafter + [] + [ + // vec3 inner comment + ] + // vec4before + /*vec4key*/[ + /* vec4inner */ + ] // vec4after + //vec5before + /*vec5key*/ [ + //vec5ab4 + 1 // vec5aAfter + 2 /* vec5bb4comma */ #vec5bAfter + #vec5extra + ] /* map5after */ + // before3 + + 3 # after3 + # before4 + /*before4b*/4/*after4*/ + #after4b +] +// after2 + +/* after3 */ diff --git a/assets/comments3/comments5_result.hjson b/assets/comments3/comments5_result.hjson new file mode 100644 index 0000000..7a38c2f --- /dev/null +++ b/assets/comments3/comments5_result.hjson @@ -0,0 +1,51 @@ +// before +/* before2 */ { #before1 + key1:/*key1keycm*/a string value // still part of the string + key2: /* key2keycm */ "a string value" // not part of the string + // map1before + map1: /* map1key */ + {}//map2after + map2: {} + map3: { + // map3 inner comment + } + vec1: [] + // map4before + map4:/*map4key*/{ + /* map4inner */ + } // map4after + //map5before + map5: /*map5key*/ { + //map5ab4 + val5a: /* map5akey */ 1 // map5aAfter + val5b: 2 /* map5bb4comma */ #map5bAfter + #map5extra + } /* map5after */ + // vec1bbefore + vec1b: /* vec1bkey */ + []//vec1bafter + vec2: [] + vec3: [ + // vec3 inner comment + ] + // vec4before + vec4:/*vec4key*/[ + /* vec4inner */ + ] // vec4after + //vec5before + vec5: /*vec5key*/ [ + //vec5ab4 + 1 // vec5aAfter + 2 /* vec5bb4comma */ #vec5bAfter + #vec5extra + ] /* map5after */ + // before3 + + key3: 3 # after3 + # before4 + /*before4b*/key4: 4/*after4*/ + #after4b +} +// after2 + +/* after3 */ diff --git a/assets/comments3/comments6_result.hjson b/assets/comments3/comments6_result.hjson new file mode 100644 index 0000000..db31dd5 --- /dev/null +++ b/assets/comments3/comments6_result.hjson @@ -0,0 +1,4 @@ +// before +/* before2 */ 3 // after1 +// after2 + diff --git a/assets/comments3/comments7_result.hjson b/assets/comments3/comments7_result.hjson new file mode 100644 index 0000000..4375f7e --- /dev/null +++ b/assets/comments3/comments7_result.hjson @@ -0,0 +1,10 @@ +{ +# comment before +b: /* key comment */ { + sub1: 3 # comment after + sub2: 4 # comment more after + } # cm after obj +// Comment B4 +a: 2 +/* Last comment */ +} diff --git a/assets/comments3/comments_result.hjson b/assets/comments3/comments_result.hjson new file mode 100644 index 0000000..1004442 --- /dev/null +++ b/assets/comments3/comments_result.hjson @@ -0,0 +1,48 @@ +// test +# all +// comment +/* +styles +*/ +# with lf + + + +# ! + +{ + # hjson style comment + foo1: This is a string value. # part of the string + foo2: "This is a string value." # a comment + + // js style comment + bar1: This is a string value. // part of the string + bar2: "This is a string value." // a comment + + /* js block style comments */foobar1:/* more */This is a string value./* part of the string */ + /* js block style comments */foobar2:/* more */"This is a string value."/* a comment */ + + rem1: "# test" + rem2: "// test" + rem3: "/* test */" + + num1: 0 # comment + num2: 0 // comment + num3: 2 /* comment */ + + true1: true # comment + true2: true // comment + true3: true /* comment */ + + false1: false # comment + false2: false // comment + false3: false /* comment */ + + null1: null # comment + null2: null // comment + null3: null /* comment */ + + str1: 00 # part of the string + str2: 00.0 // part of the string + str3: 02 /* part of the string */ +} diff --git a/assets/comments3/empty_result.hjson b/assets/comments3/empty_result.hjson new file mode 100644 index 0000000..ac97a9d --- /dev/null +++ b/assets/comments3/empty_result.hjson @@ -0,0 +1,3 @@ +{ + "": empty +} diff --git a/assets/comments3/int64_result.hjson b/assets/comments3/int64_result.hjson new file mode 100644 index 0000000..a45ecc8 --- /dev/null +++ b/assets/comments3/int64_result.hjson @@ -0,0 +1,3 @@ +{ + bigInt: 144115188075855870 +} diff --git a/assets/comments3/kan_result.hjson b/assets/comments3/kan_result.hjson new file mode 100644 index 0000000..d2d7599 --- /dev/null +++ b/assets/comments3/kan_result.hjson @@ -0,0 +1,49 @@ +{ + # the comma forces a whitespace check + numbers: + [ + 0 + 0 + 0 + 42 + 42.1 + -5 + -5.1 + 1701 + -1701 + 12.345 + -12.345 + ] + native: + [ + true + true + false + false + null + null + ] + strings: + [ + x 0 + .0 + 00 + 01 + 0 0 0 + 42 x + 42.1 asdf + 1.2.3 + -5 0 - + -5.1 -- + 17.01e2 + + -17.01e2 : + 12345e-3 @ + -12345e-3 $ + true true + x true + false false + x false + null null + x null + ] +} diff --git a/assets/comments3/keys_result.hjson b/assets/comments3/keys_result.hjson new file mode 100644 index 0000000..65d1fef --- /dev/null +++ b/assets/comments3/keys_result.hjson @@ -0,0 +1,48 @@ +{ + # unquoted keys + unquoted_key: test + _unquoted: test + test-key: test + -test: test + .key: test + # trailing spaces in key names are ignored + trailing: test + trailing2: test + # comment char in key name + "#c1": test + "foo#bar": test + "//bar": test + "foo//bar": test + "/*foo*/": test + "foo/*foo*/bar": test + "/*": test + "foo/*bar": test + # quotes in key name + "\"": test + "foo\"bar": test + "'''": test + "foo'''bar": test + "'": test + "'foo": test + "foo'bar": test + # control char in key name + ":": test + "foo:bar": test + "{": test + "foo{bar": test + "}": test + "foo}bar": test + "[": test + "foo[bar": test + "]": test + "foo]bar": test + # newline + nl1: + test + nl2: + test + + nl3: + + test +} diff --git a/assets/comments3/mltabs_result.hjson b/assets/comments3/mltabs_result.hjson new file mode 100644 index 0000000..dae7f1a --- /dev/null +++ b/assets/comments3/mltabs_result.hjson @@ -0,0 +1,8 @@ +{ + foo: + ''' + bar joe + oki doki + two tabs + ''' +} diff --git a/assets/comments3/oa_result.hjson b/assets/comments3/oa_result.hjson new file mode 100644 index 0000000..35bcdb4 --- /dev/null +++ b/assets/comments3/oa_result.hjson @@ -0,0 +1,13 @@ +[ + a + {} + {} + [] + [] + { + b: 1 + c: [] + d: {} + } + [] +] diff --git a/assets/comments3/pass1_result.hjson b/assets/comments3/pass1_result.hjson new file mode 100644 index 0000000..b46d53e --- /dev/null +++ b/assets/comments3/pass1_result.hjson @@ -0,0 +1,81 @@ +[ + JSON Test Pattern pass1 + { + "object with 1 member": [ + array with 1 element + ] + } + {} + [] + -42 + true + false + null + { + integer: 1234567890 + real: -9876.54321 + e: 1.23456789e-13 + E: 1.23456789e+34 + -: 2.3456789012e+76 + zero: 0 + one: 1 + space: " " + quote: '''"''' + backslash: \ + controls: "\b\f\n\r\t" + slash: / & / + alpha: abcdefghijklmnopqrstuvwyz + ALPHA: ABCDEFGHIJKLMNOPQRSTUVWYZ + digit: 0123456789 + 0123456789: digit + special: `1~!@#$%^&*()_+-={':[,]}|;.? + hex: ģ䕧覫췯ꯍ + true: true + false: false + null: null + array: [ + ] + object: { + } + address: 50 St. James Street + url: http://www.JSON.org/ + comment: "// /* */": " " + " s p a c e d ": [ + 1 + 2 + 3 + + +4 + 5 + 6 + 7 + ] + compact: [ + 1 + 2 + 3 + 4 + 5 + 6 + 7 + ] + jsontext: '''{"object with 1 member":["array with 1 element"]}''' + quotes: " " %22 0x22 034 " + "/\\\"쫾몾ꮘﳞ볚\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?": + A key can be any string + } + 0.5 + 98.6 + 99.44 + +1066 + 10 + 1 + 0.1 + 1 + 2 + 2 + rosebud +] diff --git a/assets/comments3/pass2_result.hjson b/assets/comments3/pass2_result.hjson new file mode 100644 index 0000000..25a5bd4 --- /dev/null +++ b/assets/comments3/pass2_result.hjson @@ -0,0 +1,39 @@ +[ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + Not too deep + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] +] diff --git a/assets/comments3/pass3_result.hjson b/assets/comments3/pass3_result.hjson new file mode 100644 index 0000000..49c6547 --- /dev/null +++ b/assets/comments3/pass3_result.hjson @@ -0,0 +1,6 @@ +{ + "JSON Test Pattern pass3": { + "The outermost value": must be an object or array. + "In this test": It is an object. + } +} diff --git a/assets/comments3/pass4_result.hjson b/assets/comments3/pass4_result.hjson new file mode 100644 index 0000000..069c2ae --- /dev/null +++ b/assets/comments3/pass4_result.hjson @@ -0,0 +1,2 @@ + +10 diff --git a/assets/comments3/pass5_result.hjson b/assets/comments3/pass5_result.hjson new file mode 100644 index 0000000..b5697b8 --- /dev/null +++ b/assets/comments3/pass5_result.hjson @@ -0,0 +1,4 @@ +{ + bigDouble: 9.223372036854776e+58 + bigInt: 9.223372036854776e+58 +} diff --git a/assets/comments3/passSingle_result.hjson b/assets/comments3/passSingle_result.hjson new file mode 100644 index 0000000..da0c9e2 --- /dev/null +++ b/assets/comments3/passSingle_result.hjson @@ -0,0 +1 @@ +allow quoteless strings diff --git a/assets/comments3/root_result.hjson b/assets/comments3/root_result.hjson new file mode 100644 index 0000000..c0acd16 --- /dev/null +++ b/assets/comments3/root_result.hjson @@ -0,0 +1,6 @@ +// a object with the root braces omitted +database: +{ + host: 127.0.0.1 + port: 555 +} diff --git a/assets/comments3/stringify1_result.hjson b/assets/comments3/stringify1_result.hjson new file mode 100644 index 0000000..3230f62 --- /dev/null +++ b/assets/comments3/stringify1_result.hjson @@ -0,0 +1,50 @@ +// test if stringify produces correct output +{ + quotes: + { + num1: "1,2" + num2: "-1.1 ," + num3: "1e10 ,2" + num4: "-1e-10," + kw1: "true," + kw2: "false ," + kw3: "null,123" + close1: "1}" + close1b: "1 }" + close2: "1]" + close2b: "1 ]" + close3: "1," + close3b: "1 ," + comment1: "1#str" + comment2: "1//str" + comment3: "1/*str*/" + punc1: "{" + punc1b: "{foo" + punc2: "}" + punc2b: "}foo" + punc3: "[" + punc3b: "[foo" + punc4: "]" + punc4b: "]foo" + punc5: "," + punc5b: ",foo" + punc6: ":" + punc6b: ":foo" + } + noquotes: + { + num0: .1,2 + num1: 1.1.1,2 + num2: -.1, + num3: 1e10e,2 + num4: -1e--10, + kw1: true1, + kw2: false0, + kw3: null0, + close1: a} + close2: a] + comment1: a#str + comment2: a//str + comment3: a/*str*/ + } +} diff --git a/assets/comments3/strings2_result.hjson b/assets/comments3/strings2_result.hjson new file mode 100644 index 0000000..987c3fa --- /dev/null +++ b/assets/comments3/strings2_result.hjson @@ -0,0 +1,36 @@ +{ + # Hjson 3 allows the use of single quotes + + key1: a key in single quotes + "key 2": a key in single quotes + "key \"": a key in single quotes + + text: [ + single quoted string + '''You need quotes for escapes''' + " untrimmed " + "untrimmed " + containing " double quotes + containing " double quotes + containing " double quotes + '''"containing more " double quotes"''' + containing ' single quotes + containing ' single quotes + containing ' single quotes + "'containing more ' single quotes'" + "'containing more ' single quotes'" + + "\n" + " \n" + "\n \n \n \n" + "\t\n" + ] + + # escapes/no escape + + foo3a: asdf''' + foo3b: "'''asdf" + + foo4a: "asdf'''\nasdf" + foo4b: "asdf\n'''asdf" +} diff --git a/assets/comments3/strings3_result.hjson b/assets/comments3/strings3_result.hjson new file mode 100644 index 0000000..6811103 --- /dev/null +++ b/assets/comments3/strings3_result.hjson @@ -0,0 +1,6 @@ +{ + // Empty string + a: "" + // Unicode code points that require escape inside quotes. + b: "\u00ad\u0600\u0604\u070f\u17b4\u17b5\u200c\u200f\u2028\u202f\u2060\u206f\ufeff\ufff0\uffff" +} diff --git a/assets/comments3/strings_result.hjson b/assets/comments3/strings_result.hjson new file mode 100644 index 0000000..2a21fdd --- /dev/null +++ b/assets/comments3/strings_result.hjson @@ -0,0 +1,104 @@ +{ + # simple + + text1: This is a valid string value. + text2: a \ is just a \ + + text3: '''You need quotes for escapes''' + + text4a: " untrimmed " + text4b: " untrimmed" + text4c: "untrimmed " + + notml1: "\n" + notml2: " \n" + notml3: "\n \n \n \n" + notml4: "\t\n" + + # multiline string + + multiline1: + ''' + first line + indented line + last line + ''' + + multiline2: + ''' + first line + indented line + last line + ''' + + multiline3: + ''' + first line + indented line + last line + + ''' # trailing lf + + multiline4: + ←→±≠Я + + # escapes/no escape + + foo1a: asdf\"'a\s\w + foo1b: asdf\"'a\s\w + foo1c: asdf\"'a\s\w + + foo2a: '''"asdf"''' + foo2b: '''"asdf"''' + + foo3a: asdf''' + foo3b: "'''asdf" + + foo4a: "asdf'''\nasdf" + foo4b: "asdf\n'''asdf" + + # in arrays + arr: + [ + one + two + three + four + ] + + # not strings + not: + { + number: 5 + negative: -4.2 + yes: true + no: false + null: null + array: [ + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + -1 + 0.5 + ] + } + + # special quoted + special: + { + true: "true" + false: "false" + null: "null" + one: "1" + two: "2" + minus: "-3" + zero: "0" + } +} diff --git a/assets/comments3/trail_result.hjson b/assets/comments3/trail_result.hjson new file mode 100644 index 0000000..bbb50b7 --- /dev/null +++ b/assets/comments3/trail_result.hjson @@ -0,0 +1,4 @@ +{ + // the following line contains trailing whitespace: + foo: 0 -- this string starts at 0 and ends at 1, preceding and trailing whitespace is ignored -- 1 +} diff --git a/assets/comments3/windowseol_result.hjson b/assets/comments3/windowseol_result.hjson new file mode 100644 index 0000000..d735ba5 --- /dev/null +++ b/assets/comments3/windowseol_result.hjson @@ -0,0 +1,11 @@ +{ + ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + js-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + ml-ascii: + ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + newline: + ''' + 1 + 2 + ''' +} diff --git a/assets/comments3_result.hjson b/assets/comments3_result.hjson new file mode 100644 index 0000000..e181290 --- /dev/null +++ b/assets/comments3_result.hjson @@ -0,0 +1 @@ +a string value // still part of the string diff --git a/assets/comments3_result.json b/assets/comments3_result.json new file mode 100644 index 0000000..2ba2dd3 --- /dev/null +++ b/assets/comments3_result.json @@ -0,0 +1 @@ +"a string value // still part of the string" diff --git a/assets/comments3_test.hjson b/assets/comments3_test.hjson new file mode 100644 index 0000000..a59bc4e --- /dev/null +++ b/assets/comments3_test.hjson @@ -0,0 +1,3 @@ +// before +/* before2 */ a string value // still part of the string +// after2 diff --git a/assets/comments4_result.hjson b/assets/comments4_result.hjson new file mode 100644 index 0000000..4867600 --- /dev/null +++ b/assets/comments4_result.hjson @@ -0,0 +1,23 @@ +[ + a string value // still part of the string + a string value + {} + {} + {} + [] + {} + { + val5a: 1 + val5b: 2 + } + [] + [] + [] + [] + [ + 1 + 2 + ] + 3 + 4 +] diff --git a/assets/comments4_result.json b/assets/comments4_result.json new file mode 100644 index 0000000..9abb414 --- /dev/null +++ b/assets/comments4_result.json @@ -0,0 +1,23 @@ +[ + "a string value // still part of the string", + "a string value", + {}, + {}, + {}, + [], + {}, + { + "val5a": 1, + "val5b": 2 + }, + [], + [], + [], + [], + [ + 1, + 2 + ], + 3, + 4 +] diff --git a/assets/comments4_test.hjson b/assets/comments4_test.hjson new file mode 100644 index 0000000..35bb19e --- /dev/null +++ b/assets/comments4_test.hjson @@ -0,0 +1,51 @@ +// before +/* before2 */ [ #before1 + /*key1keycm*/a string value // still part of the string + /* key2keycm */ "a string value" // not part of the string + // map1before + /* map1key */ + {}//map2after + {} + { + // map3 inner comment + } + [] + // map4before + /*map4key*/{ + /* map4inner */ + } // map4after + //map5before + /*map5key*/ { + //map5ab4 + val5a: /* map5akey */ 1, // map5aAfter + val5b: 2 /* map5bb4comma */ , #map5bAfter + #map5extra + } /* map5after */ + // vec1bbefore + /* vec1bkey */ + []//vec1bafter + [] + [ + // vec3 inner comment + ] + // vec4before + /*vec4key*/[ + /* vec4inner */ + ] // vec4after + //vec5before + /*vec5key*/ [ + //vec5ab4 + 1, // vec5aAfter + 2 /* vec5bb4comma */ , #vec5bAfter + #vec5extra + ] /* map5after */ + // before3 + + 3 # after3 + # before4 + /*before4b*/4/*after4*/ + #after4b +] +// after2 + +/* after3 */ diff --git a/assets/comments5_result.hjson b/assets/comments5_result.hjson new file mode 100644 index 0000000..377ffe6 --- /dev/null +++ b/assets/comments5_result.hjson @@ -0,0 +1,23 @@ +{ + key1: a string value // still part of the string + key2: a string value + map1: {} + map2: {} + map3: {} + vec1: [] + map4: {} + map5: { + val5a: 1 + val5b: 2 + } + vec1b: [] + vec2: [] + vec3: [] + vec4: [] + vec5: [ + 1 + 2 + ] + key3: 3 + key4: 4 +} diff --git a/assets/comments5_result.json b/assets/comments5_result.json new file mode 100644 index 0000000..e53e617 --- /dev/null +++ b/assets/comments5_result.json @@ -0,0 +1,23 @@ +{ + "key1": "a string value // still part of the string", + "key2": "a string value", + "map1": {}, + "map2": {}, + "map3": {}, + "vec1": [], + "map4": {}, + "map5": { + "val5a": 1, + "val5b": 2 + }, + "vec1b": [], + "vec2": [], + "vec3": [], + "vec4": [], + "vec5": [ + 1, + 2 + ], + "key3": 3, + "key4": 4 +} diff --git a/assets/comments5_test.hjson b/assets/comments5_test.hjson new file mode 100644 index 0000000..071059d --- /dev/null +++ b/assets/comments5_test.hjson @@ -0,0 +1,51 @@ +// before +/* before2 */ { #before1 + key1:/*key1keycm*/a string value // still part of the string + key2: /* key2keycm */ "a string value" // not part of the string + // map1before + map1: /* map1key */ + {}//map2after + map2: {} + map3: { + // map3 inner comment + } + vec1: [] + // map4before + map4:/*map4key*/{ + /* map4inner */ + } // map4after + //map5before + map5: /*map5key*/ { + //map5ab4 + val5a: /* map5akey */ 1, // map5aAfter + val5b: 2 /* map5bb4comma */ , #map5bAfter + #map5extra + } /* map5after */ + // vec1bbefore + vec1b: /* vec1bkey */ + []//vec1bafter + vec2: [] + vec3: [ + // vec3 inner comment + ] + // vec4before + vec4:/*vec4key*/[ + /* vec4inner */ + ] // vec4after + //vec5before + vec5: /*vec5key*/ [ + //vec5ab4 + 1, // vec5aAfter + 2 /* vec5bb4comma */ , #vec5bAfter + #vec5extra + ] /* map5after */ + // before3 + + key3 : 3 # after3 + # before4 + /*before4b*/key4:4/*after4*/ + #after4b +} +// after2 + +/* after3 */ diff --git a/assets/comments6_result.hjson b/assets/comments6_result.hjson new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/assets/comments6_result.hjson @@ -0,0 +1 @@ +3 diff --git a/assets/comments6_result.json b/assets/comments6_result.json new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/assets/comments6_result.json @@ -0,0 +1 @@ +3 diff --git a/assets/comments6_test.hjson b/assets/comments6_test.hjson new file mode 100644 index 0000000..bd4597b --- /dev/null +++ b/assets/comments6_test.hjson @@ -0,0 +1,4 @@ +// before +/* before2 */ 3 // after1 +// after2 + diff --git a/assets/comments7_result.hjson b/assets/comments7_result.hjson new file mode 100644 index 0000000..aafb684 --- /dev/null +++ b/assets/comments7_result.hjson @@ -0,0 +1,7 @@ +{ + b: { + sub1: 3 + sub2: 4 + } + a: 2 +} diff --git a/assets/comments7_result.json b/assets/comments7_result.json new file mode 100644 index 0000000..1a272e8 --- /dev/null +++ b/assets/comments7_result.json @@ -0,0 +1,7 @@ +{ + "b": { + "sub1": 3, + "sub2": 4 + }, + "a": 2 +} diff --git a/assets/comments7_test.hjson b/assets/comments7_test.hjson new file mode 100644 index 0000000..1bb0342 --- /dev/null +++ b/assets/comments7_test.hjson @@ -0,0 +1,8 @@ +# comment before +b: /* key comment */ { + sub1: 3 # comment after + sub2: 4 # comment more after +} # cm after obj +// Comment B4 +a: 2 +/* Last comment */ diff --git a/assets/comments_result.json b/assets/comments_result.json index e247803..149ae7c 100644 --- a/assets/comments_result.json +++ b/assets/comments_result.json @@ -23,4 +23,4 @@ "str1": "00 # part of the string", "str2": "00.0 // part of the string", "str3": "02 /* part of the string */" -} \ No newline at end of file +} diff --git a/assets/empty_result.json b/assets/empty_result.json index 47f710f..d0eac64 100644 --- a/assets/empty_result.json +++ b/assets/empty_result.json @@ -1,3 +1,3 @@ { "": "empty" -} \ No newline at end of file +} diff --git a/assets/failJSON02_test.json b/assets/failJSON02_test.json index 6b7c11e..dce1699 100644 --- a/assets/failJSON02_test.json +++ b/assets/failJSON02_test.json @@ -1 +1 @@ -["Unclosed array" \ No newline at end of file +["Unclosed array" diff --git a/assets/failJSON05_test.json b/assets/failJSON05_test.json index ddf3ce3..4e140bb 100644 --- a/assets/failJSON05_test.json +++ b/assets/failJSON05_test.json @@ -1 +1 @@ -["double extra comma",,] \ No newline at end of file +["double extra comma",,] diff --git a/assets/failJSON06_test.json b/assets/failJSON06_test.json index ed91580..54c2c88 100644 --- a/assets/failJSON06_test.json +++ b/assets/failJSON06_test.json @@ -1 +1 @@ -[ , "<-- missing value"] \ No newline at end of file +[ , "<-- missing value"] diff --git a/assets/failJSON07_test.json b/assets/failJSON07_test.json index 8a96af3..ddef19b 100644 --- a/assets/failJSON07_test.json +++ b/assets/failJSON07_test.json @@ -1 +1 @@ -["Comma after the close"], \ No newline at end of file +["Comma after the close"], diff --git a/assets/failJSON08_test.json b/assets/failJSON08_test.json index b28479c..ca65a46 100644 --- a/assets/failJSON08_test.json +++ b/assets/failJSON08_test.json @@ -1 +1 @@ -["Extra close"]] \ No newline at end of file +["Extra close"]] diff --git a/assets/failJSON10_test.json b/assets/failJSON10_test.json index 5d8c004..d8bbf2e 100644 --- a/assets/failJSON10_test.json +++ b/assets/failJSON10_test.json @@ -1 +1 @@ -{"Extra value after close": true} "misplaced quoted value" \ No newline at end of file +{"Extra value after close": true} "misplaced quoted value" diff --git a/assets/failJSON11_test.json b/assets/failJSON11_test.json index 76eb95b..1b37f0e 100644 --- a/assets/failJSON11_test.json +++ b/assets/failJSON11_test.json @@ -1 +1 @@ -{"Illegal expression": 1 + 2} \ No newline at end of file +{"Illegal expression": 1 + 2} diff --git a/assets/failJSON12_test.json b/assets/failJSON12_test.json index 77580a4..d448115 100644 --- a/assets/failJSON12_test.json +++ b/assets/failJSON12_test.json @@ -1 +1 @@ -{"Illegal invocation": alert()} \ No newline at end of file +{"Illegal invocation": alert()} diff --git a/assets/failJSON13_test.json b/assets/failJSON13_test.json index 379406b..92983fe 100644 --- a/assets/failJSON13_test.json +++ b/assets/failJSON13_test.json @@ -1 +1 @@ -{"Numbers cannot have leading zeroes": 013} \ No newline at end of file +{"Numbers cannot have leading zeroes": 013} diff --git a/assets/failJSON14_test.json b/assets/failJSON14_test.json index 0ed366b..efb3a2e 100644 --- a/assets/failJSON14_test.json +++ b/assets/failJSON14_test.json @@ -1 +1 @@ -{"Numbers cannot be hex": 0x14} \ No newline at end of file +{"Numbers cannot be hex": 0x14} diff --git a/assets/failJSON15_test.json b/assets/failJSON15_test.json index fc8376b..1fb8b7f 100644 --- a/assets/failJSON15_test.json +++ b/assets/failJSON15_test.json @@ -1 +1 @@ -["Illegal backslash escape: \x15"] \ No newline at end of file +["Illegal backslash escape: \x15"] diff --git a/assets/failJSON16_test.json b/assets/failJSON16_test.json index 3fe21d4..d10078d 100644 --- a/assets/failJSON16_test.json +++ b/assets/failJSON16_test.json @@ -1 +1 @@ -[\naked] \ No newline at end of file +[\naked] diff --git a/assets/failJSON17_test.json b/assets/failJSON17_test.json index 62b9214..09bd8c3 100644 --- a/assets/failJSON17_test.json +++ b/assets/failJSON17_test.json @@ -1 +1 @@ -["Illegal backslash escape: \017"] \ No newline at end of file +["Illegal backslash escape: \017"] diff --git a/assets/failJSON19_test.json b/assets/failJSON19_test.json index 3b9c46f..4a49528 100644 --- a/assets/failJSON19_test.json +++ b/assets/failJSON19_test.json @@ -1 +1 @@ -{"Missing colon" null} \ No newline at end of file +{"Missing colon" null} diff --git a/assets/failJSON20_test.json b/assets/failJSON20_test.json index 27c1af3..14439b8 100644 --- a/assets/failJSON20_test.json +++ b/assets/failJSON20_test.json @@ -1 +1 @@ -{"Double colon":: null} \ No newline at end of file +{"Double colon":: null} diff --git a/assets/failJSON21_test.json b/assets/failJSON21_test.json index 6247457..753b4e9 100644 --- a/assets/failJSON21_test.json +++ b/assets/failJSON21_test.json @@ -1 +1 @@ -{"Comma instead of colon", null} \ No newline at end of file +{"Comma instead of colon", null} diff --git a/assets/failJSON22_test.json b/assets/failJSON22_test.json index a775258..dc62577 100644 --- a/assets/failJSON22_test.json +++ b/assets/failJSON22_test.json @@ -1 +1 @@ -["Colon instead of comma": false] \ No newline at end of file +["Colon instead of comma": false] diff --git a/assets/failJSON23_test.json b/assets/failJSON23_test.json index 494add1..871fcdb 100644 --- a/assets/failJSON23_test.json +++ b/assets/failJSON23_test.json @@ -1 +1 @@ -["Bad value", truth] \ No newline at end of file +["Bad value", truth] diff --git a/assets/failJSON24_test.json b/assets/failJSON24_test.json index caff239..a9b9cdd 100644 --- a/assets/failJSON24_test.json +++ b/assets/failJSON24_test.json @@ -1 +1 @@ -['single quote'] \ No newline at end of file +['single quote'] diff --git a/assets/failJSON26_test.json b/assets/failJSON26_test.json index 845d26a..ed456b8 100644 --- a/assets/failJSON26_test.json +++ b/assets/failJSON26_test.json @@ -1 +1 @@ -["tab\ character\ in\ string\ "] \ No newline at end of file +["tab\ character\ in\ string\ "] diff --git a/assets/failJSON28_test.json b/assets/failJSON28_test.json index 621a010..660959e 100644 --- a/assets/failJSON28_test.json +++ b/assets/failJSON28_test.json @@ -1,2 +1,2 @@ ["line\ -break"] \ No newline at end of file +break"] diff --git a/assets/failJSON29_test.json b/assets/failJSON29_test.json index 47ec421..63f1d6e 100644 --- a/assets/failJSON29_test.json +++ b/assets/failJSON29_test.json @@ -1 +1 @@ -[0e] \ No newline at end of file +[0e] diff --git a/assets/failJSON30_test.json b/assets/failJSON30_test.json index 8ab0bc4..023d4c1 100644 --- a/assets/failJSON30_test.json +++ b/assets/failJSON30_test.json @@ -1 +1 @@ -[0e+] \ No newline at end of file +[0e+] diff --git a/assets/failJSON31_test.json b/assets/failJSON31_test.json index 1cce602..f343fa1 100644 --- a/assets/failJSON31_test.json +++ b/assets/failJSON31_test.json @@ -1 +1 @@ -[0e+-1] \ No newline at end of file +[0e+-1] diff --git a/assets/failJSON32_test.json b/assets/failJSON32_test.json index 45cba73..e19f14e 100644 --- a/assets/failJSON32_test.json +++ b/assets/failJSON32_test.json @@ -1 +1 @@ -{"Comma instead if closing brace": true, \ No newline at end of file +{"Comma instead if closing brace": true, diff --git a/assets/failJSON33_test.json b/assets/failJSON33_test.json index ca5eb19..a232e15 100644 --- a/assets/failJSON33_test.json +++ b/assets/failJSON33_test.json @@ -1 +1 @@ -["mismatch"} \ No newline at end of file +["mismatch"} diff --git a/assets/int64_result.hjson b/assets/int64_result.hjson new file mode 100644 index 0000000..bd22f5d --- /dev/null +++ b/assets/int64_result.hjson @@ -0,0 +1,3 @@ +{ + bigInt: 144115188075855873 +} diff --git a/assets/int64_result.json b/assets/int64_result.json new file mode 100644 index 0000000..e612210 --- /dev/null +++ b/assets/int64_result.json @@ -0,0 +1,3 @@ +{ + "bigInt": 144115188075855873 +} diff --git a/assets/int64_test.hjson b/assets/int64_test.hjson new file mode 100644 index 0000000..bd22f5d --- /dev/null +++ b/assets/int64_test.hjson @@ -0,0 +1,3 @@ +{ + bigInt: 144115188075855873 +} diff --git a/assets/kan_result.json b/assets/kan_result.json index babb9d4..ff170f6 100644 --- a/assets/kan_result.json +++ b/assets/kan_result.json @@ -42,4 +42,4 @@ "null null", "x null" ] -} \ No newline at end of file +} diff --git a/assets/keys_result.json b/assets/keys_result.json index ead27f1..b8c38b8 100644 --- a/assets/keys_result.json +++ b/assets/keys_result.json @@ -34,4 +34,4 @@ "nl1": "test", "nl2": "test", "nl3": "test" -} \ No newline at end of file +} diff --git a/assets/mltabs_result.json b/assets/mltabs_result.json index d3ee977..b12f316 100644 --- a/assets/mltabs_result.json +++ b/assets/mltabs_result.json @@ -1,3 +1,3 @@ { "foo": "bar\tjoe\noki\tdoki\n\t\ttwo tabs" -} \ No newline at end of file +} diff --git a/assets/oa_result.json b/assets/oa_result.json index f0955ab..3952733 100644 --- a/assets/oa_result.json +++ b/assets/oa_result.json @@ -10,4 +10,4 @@ "d": {} }, [] -] \ No newline at end of file +] diff --git a/assets/pass1_result.json b/assets/pass1_result.json index 69b354d..748805f 100644 --- a/assets/pass1_result.json +++ b/assets/pass1_result.json @@ -72,4 +72,4 @@ 2, 2, "rosebud" -] \ No newline at end of file +] diff --git a/assets/pass1_test.json b/assets/pass1_test.json index 61cfd90..8b04f46 100644 --- a/assets/pass1_test.json +++ b/assets/pass1_test.json @@ -55,4 +55,4 @@ 0.1e1, 1e-1, 1e00,2e+00,2e-00 -,"rosebud"] \ No newline at end of file +,"rosebud"] diff --git a/assets/pass2_result.json b/assets/pass2_result.json index 2a71f58..6764f01 100644 --- a/assets/pass2_result.json +++ b/assets/pass2_result.json @@ -36,4 +36,4 @@ ] ] ] -] \ No newline at end of file +] diff --git a/assets/pass2_test.json b/assets/pass2_test.json index d3c63c7..fea5710 100644 --- a/assets/pass2_test.json +++ b/assets/pass2_test.json @@ -1 +1 @@ -[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] \ No newline at end of file +[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] diff --git a/assets/pass3_result.json b/assets/pass3_result.json index d98cd2f..270f890 100644 --- a/assets/pass3_result.json +++ b/assets/pass3_result.json @@ -3,4 +3,4 @@ "The outermost value": "must be an object or array.", "In this test": "It is an object." } -} \ No newline at end of file +} diff --git a/assets/pass4_result.json b/assets/pass4_result.json index 9a03714..f599e28 100644 --- a/assets/pass4_result.json +++ b/assets/pass4_result.json @@ -1 +1 @@ -10 \ No newline at end of file +10 diff --git a/assets/pass5_result.hjson b/assets/pass5_result.hjson new file mode 100644 index 0000000..aa20eed --- /dev/null +++ b/assets/pass5_result.hjson @@ -0,0 +1,4 @@ +{ + bigDouble: 9.22337203685478e+58 + bigInt: 9.22337203685478e+58 +} diff --git a/assets/pass5_result.json b/assets/pass5_result.json new file mode 100644 index 0000000..92f56d6 --- /dev/null +++ b/assets/pass5_result.json @@ -0,0 +1,4 @@ +{ + "bigDouble": 9.22337203685478e+58, + "bigInt": 9.22337203685478e+58 +} diff --git a/assets/pass5_test.hjson b/assets/pass5_test.hjson new file mode 100644 index 0000000..6232d61 --- /dev/null +++ b/assets/pass5_test.hjson @@ -0,0 +1,4 @@ +{ + bigDouble: 92233720368547758073829419051489548484843823585675828488686.0 + bigInt: 92233720368547758073829419051489548484843823585675828488686 +} diff --git a/assets/passSingle_result.json b/assets/passSingle_result.json index 1829d36..55f1262 100644 --- a/assets/passSingle_result.json +++ b/assets/passSingle_result.json @@ -1 +1 @@ -"allow quoteless strings" \ No newline at end of file +"allow quoteless strings" diff --git a/assets/passSingle_test.hjson b/assets/passSingle_test.hjson index e580fce..da0c9e2 100644 --- a/assets/passSingle_test.hjson +++ b/assets/passSingle_test.hjson @@ -1 +1 @@ -allow quoteless strings \ No newline at end of file +allow quoteless strings diff --git a/assets/root_result.json b/assets/root_result.json index 21b01cd..6899303 100644 --- a/assets/root_result.json +++ b/assets/root_result.json @@ -3,4 +3,4 @@ "host": "127.0.0.1", "port": 555 } -} \ No newline at end of file +} diff --git a/assets/sorted/charset2_result.json b/assets/sorted/charset2_result.json index 3fdfedb..55c6ff1 100644 --- a/assets/sorted/charset2_result.json +++ b/assets/sorted/charset2_result.json @@ -2,4 +2,4 @@ "hex": "ģ䕧覫췯ꯍ", "uescape": "\u0000,\u0001,￿", "umlaut": "äöüßÄÖÜ" -} \ No newline at end of file +} diff --git a/assets/sorted/charset_result.json b/assets/sorted/charset_result.json index 8604f0a..2321558 100644 --- a/assets/sorted/charset_result.json +++ b/assets/sorted/charset_result.json @@ -2,4 +2,4 @@ "js-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", "ml-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", "ql-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" -} \ No newline at end of file +} diff --git a/assets/sorted/comments2_result.hjson b/assets/sorted/comments2_result.hjson new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/assets/sorted/comments2_result.hjson @@ -0,0 +1 @@ +3 diff --git a/assets/sorted/comments2_result.json b/assets/sorted/comments2_result.json new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/assets/sorted/comments2_result.json @@ -0,0 +1 @@ +3 diff --git a/assets/sorted/comments3_result.hjson b/assets/sorted/comments3_result.hjson new file mode 100644 index 0000000..e181290 --- /dev/null +++ b/assets/sorted/comments3_result.hjson @@ -0,0 +1 @@ +a string value // still part of the string diff --git a/assets/sorted/comments3_result.json b/assets/sorted/comments3_result.json new file mode 100644 index 0000000..2ba2dd3 --- /dev/null +++ b/assets/sorted/comments3_result.json @@ -0,0 +1 @@ +"a string value // still part of the string" diff --git a/assets/sorted/comments4_result.hjson b/assets/sorted/comments4_result.hjson new file mode 100644 index 0000000..4867600 --- /dev/null +++ b/assets/sorted/comments4_result.hjson @@ -0,0 +1,23 @@ +[ + a string value // still part of the string + a string value + {} + {} + {} + [] + {} + { + val5a: 1 + val5b: 2 + } + [] + [] + [] + [] + [ + 1 + 2 + ] + 3 + 4 +] diff --git a/assets/sorted/comments4_result.json b/assets/sorted/comments4_result.json new file mode 100644 index 0000000..9abb414 --- /dev/null +++ b/assets/sorted/comments4_result.json @@ -0,0 +1,23 @@ +[ + "a string value // still part of the string", + "a string value", + {}, + {}, + {}, + [], + {}, + { + "val5a": 1, + "val5b": 2 + }, + [], + [], + [], + [], + [ + 1, + 2 + ], + 3, + 4 +] diff --git a/assets/sorted/comments5_result.hjson b/assets/sorted/comments5_result.hjson new file mode 100644 index 0000000..3ae7f99 --- /dev/null +++ b/assets/sorted/comments5_result.hjson @@ -0,0 +1,23 @@ +{ + key1: a string value // still part of the string + key2: a string value + key3: 3 + key4: 4 + map1: {} + map2: {} + map3: {} + map4: {} + map5: { + val5a: 1 + val5b: 2 + } + vec1: [] + vec1b: [] + vec2: [] + vec3: [] + vec4: [] + vec5: [ + 1 + 2 + ] +} diff --git a/assets/sorted/comments5_result.json b/assets/sorted/comments5_result.json new file mode 100644 index 0000000..52e89a9 --- /dev/null +++ b/assets/sorted/comments5_result.json @@ -0,0 +1,23 @@ +{ + "key1": "a string value // still part of the string", + "key2": "a string value", + "key3": 3, + "key4": 4, + "map1": {}, + "map2": {}, + "map3": {}, + "map4": {}, + "map5": { + "val5a": 1, + "val5b": 2 + }, + "vec1": [], + "vec1b": [], + "vec2": [], + "vec3": [], + "vec4": [], + "vec5": [ + 1, + 2 + ] +} diff --git a/assets/sorted/comments6_result.hjson b/assets/sorted/comments6_result.hjson new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/assets/sorted/comments6_result.hjson @@ -0,0 +1 @@ +3 diff --git a/assets/sorted/comments6_result.json b/assets/sorted/comments6_result.json new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/assets/sorted/comments6_result.json @@ -0,0 +1 @@ +3 diff --git a/assets/sorted/comments7_result.hjson b/assets/sorted/comments7_result.hjson new file mode 100644 index 0000000..19a13d1 --- /dev/null +++ b/assets/sorted/comments7_result.hjson @@ -0,0 +1,7 @@ +{ + a: 2 + b: { + sub1: 3 + sub2: 4 + } +} diff --git a/assets/sorted/comments7_result.json b/assets/sorted/comments7_result.json new file mode 100644 index 0000000..5c1eef3 --- /dev/null +++ b/assets/sorted/comments7_result.json @@ -0,0 +1,7 @@ +{ + "a": 2, + "b": { + "sub1": 3, + "sub2": 4 + } +} diff --git a/assets/sorted/comments_result.json b/assets/sorted/comments_result.json index e71f80c..dbc133a 100644 --- a/assets/sorted/comments_result.json +++ b/assets/sorted/comments_result.json @@ -23,4 +23,4 @@ "true1": true, "true2": true, "true3": true -} \ No newline at end of file +} diff --git a/assets/sorted/empty_result.json b/assets/sorted/empty_result.json index 47f710f..d0eac64 100644 --- a/assets/sorted/empty_result.json +++ b/assets/sorted/empty_result.json @@ -1,3 +1,3 @@ { "": "empty" -} \ No newline at end of file +} diff --git a/assets/sorted/int64_result.hjson b/assets/sorted/int64_result.hjson new file mode 100644 index 0000000..a45ecc8 --- /dev/null +++ b/assets/sorted/int64_result.hjson @@ -0,0 +1,3 @@ +{ + bigInt: 144115188075855870 +} diff --git a/assets/sorted/int64_result.json b/assets/sorted/int64_result.json new file mode 100644 index 0000000..060720d --- /dev/null +++ b/assets/sorted/int64_result.json @@ -0,0 +1,3 @@ +{ + "bigInt": 144115188075855870 +} diff --git a/assets/sorted/kan_result.json b/assets/sorted/kan_result.json index 251be30..717477e 100644 --- a/assets/sorted/kan_result.json +++ b/assets/sorted/kan_result.json @@ -10,7 +10,7 @@ "numbers": [ 0, 0, - 0, + -0, 42, 42.1, -5, @@ -42,4 +42,4 @@ "null null", "x null" ] -} \ No newline at end of file +} diff --git a/assets/sorted/keys_result.json b/assets/sorted/keys_result.json index d42daff..ed23433 100644 --- a/assets/sorted/keys_result.json +++ b/assets/sorted/keys_result.json @@ -34,4 +34,4 @@ "unquoted_key": "test", "{": "test", "}": "test" -} \ No newline at end of file +} diff --git a/assets/sorted/mltabs_result.json b/assets/sorted/mltabs_result.json index d3ee977..b12f316 100644 --- a/assets/sorted/mltabs_result.json +++ b/assets/sorted/mltabs_result.json @@ -1,3 +1,3 @@ { "foo": "bar\tjoe\noki\tdoki\n\t\ttwo tabs" -} \ No newline at end of file +} diff --git a/assets/sorted/oa_result.json b/assets/sorted/oa_result.json index f0955ab..3952733 100644 --- a/assets/sorted/oa_result.json +++ b/assets/sorted/oa_result.json @@ -10,4 +10,4 @@ "d": {} }, [] -] \ No newline at end of file +] diff --git a/assets/sorted/pass1_result.json b/assets/sorted/pass1_result.json index 50693ce..78cd260 100644 --- a/assets/sorted/pass1_result.json +++ b/assets/sorted/pass1_result.json @@ -72,4 +72,4 @@ 2, 2, "rosebud" -] \ No newline at end of file +] diff --git a/assets/sorted/pass2_result.json b/assets/sorted/pass2_result.json index 2a71f58..6764f01 100644 --- a/assets/sorted/pass2_result.json +++ b/assets/sorted/pass2_result.json @@ -36,4 +36,4 @@ ] ] ] -] \ No newline at end of file +] diff --git a/assets/sorted/pass3_result.json b/assets/sorted/pass3_result.json index 1350c35..0bd7b8f 100644 --- a/assets/sorted/pass3_result.json +++ b/assets/sorted/pass3_result.json @@ -3,4 +3,4 @@ "In this test": "It is an object.", "The outermost value": "must be an object or array." } -} \ No newline at end of file +} diff --git a/assets/sorted/pass4_result.json b/assets/sorted/pass4_result.json index 9a03714..f599e28 100644 --- a/assets/sorted/pass4_result.json +++ b/assets/sorted/pass4_result.json @@ -1 +1 @@ -10 \ No newline at end of file +10 diff --git a/assets/sorted/pass5_result.hjson b/assets/sorted/pass5_result.hjson new file mode 100644 index 0000000..b5697b8 --- /dev/null +++ b/assets/sorted/pass5_result.hjson @@ -0,0 +1,4 @@ +{ + bigDouble: 9.223372036854776e+58 + bigInt: 9.223372036854776e+58 +} diff --git a/assets/sorted/pass5_result.json b/assets/sorted/pass5_result.json new file mode 100644 index 0000000..7e0be2c --- /dev/null +++ b/assets/sorted/pass5_result.json @@ -0,0 +1,4 @@ +{ + "bigDouble": 9.223372036854776e+58, + "bigInt": 9.223372036854776e+58 +} diff --git a/assets/sorted/passSingle_result.json b/assets/sorted/passSingle_result.json index 1829d36..55f1262 100644 --- a/assets/sorted/passSingle_result.json +++ b/assets/sorted/passSingle_result.json @@ -1 +1 @@ -"allow quoteless strings" \ No newline at end of file +"allow quoteless strings" diff --git a/assets/sorted/root_result.json b/assets/sorted/root_result.json index 21b01cd..6899303 100644 --- a/assets/sorted/root_result.json +++ b/assets/sorted/root_result.json @@ -3,4 +3,4 @@ "host": "127.0.0.1", "port": 555 } -} \ No newline at end of file +} diff --git a/assets/sorted/stringify1_result.json b/assets/sorted/stringify1_result.json index 4b566b2..2cd294e 100644 --- a/assets/sorted/stringify1_result.json +++ b/assets/sorted/stringify1_result.json @@ -44,4 +44,4 @@ "punc6": ":", "punc6b": ":foo" } -} \ No newline at end of file +} diff --git a/assets/sorted/strings2_result.json b/assets/sorted/strings2_result.json index 5ada1b6..e48e78e 100644 --- a/assets/sorted/strings2_result.json +++ b/assets/sorted/strings2_result.json @@ -25,4 +25,4 @@ "\n \n \n \n", "\t\n" ] -} \ No newline at end of file +} diff --git a/assets/sorted/strings3_result.hjson b/assets/sorted/strings3_result.hjson new file mode 100644 index 0000000..8845dc5 --- /dev/null +++ b/assets/sorted/strings3_result.hjson @@ -0,0 +1,4 @@ +{ + a: "" + b: "\u00ad\u0600\u0604\u070f\u17b4\u17b5\u200c\u200f\u2028\u202f\u2060\u206f\ufeff\ufff0\uffff" +} diff --git a/assets/sorted/strings3_result.json b/assets/sorted/strings3_result.json new file mode 100644 index 0000000..fb702ca --- /dev/null +++ b/assets/sorted/strings3_result.json @@ -0,0 +1,4 @@ +{ + "a": "", + "b": "­؀؄܏឴឵‌‏\u2028 ⁠￰￿" +} diff --git a/assets/sorted/strings_result.json b/assets/sorted/strings_result.json index b00ad43..35deb0f 100644 --- a/assets/sorted/strings_result.json +++ b/assets/sorted/strings_result.json @@ -58,4 +58,4 @@ "text4a": " untrimmed ", "text4b": " untrimmed", "text4c": "untrimmed " -} \ No newline at end of file +} diff --git a/assets/sorted/trail_result.json b/assets/sorted/trail_result.json index 451c8ce..bb65b0c 100644 --- a/assets/sorted/trail_result.json +++ b/assets/sorted/trail_result.json @@ -1,3 +1,3 @@ { "foo": "0 -- this string starts at 0 and ends at 1, preceding and trailing whitespace is ignored -- 1" -} \ No newline at end of file +} diff --git a/assets/sorted/windowseol_result.hjson b/assets/sorted/windowseol_result.hjson new file mode 100644 index 0000000..4158af2 --- /dev/null +++ b/assets/sorted/windowseol_result.hjson @@ -0,0 +1,10 @@ +{ + js-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + ml-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + newline: + ''' + 1 + 2 + ''' + ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ +} diff --git a/assets/sorted/windowseol_result.json b/assets/sorted/windowseol_result.json new file mode 100644 index 0000000..d8ad05f --- /dev/null +++ b/assets/sorted/windowseol_result.json @@ -0,0 +1,6 @@ +{ + "js-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", + "ml-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", + "newline": "1\n2", + "ql-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" +} diff --git a/assets/stringify1_result.json b/assets/stringify1_result.json index 12514f8..c9245c1 100644 --- a/assets/stringify1_result.json +++ b/assets/stringify1_result.json @@ -44,4 +44,4 @@ "comment2": "a//str", "comment3": "a/*str*/" } -} \ No newline at end of file +} diff --git a/assets/strings2_result.json b/assets/strings2_result.json index 88b4ef2..96d4ff5 100644 --- a/assets/strings2_result.json +++ b/assets/strings2_result.json @@ -25,4 +25,4 @@ "foo3b": "'''asdf", "foo4a": "asdf'''\nasdf", "foo4b": "asdf\n'''asdf" -} \ No newline at end of file +} diff --git a/assets/strings3_result.hjson b/assets/strings3_result.hjson new file mode 100644 index 0000000..8845dc5 --- /dev/null +++ b/assets/strings3_result.hjson @@ -0,0 +1,4 @@ +{ + a: "" + b: "\u00ad\u0600\u0604\u070f\u17b4\u17b5\u200c\u200f\u2028\u202f\u2060\u206f\ufeff\ufff0\uffff" +} diff --git a/assets/strings3_result.json b/assets/strings3_result.json new file mode 100644 index 0000000..79bcfd6 --- /dev/null +++ b/assets/strings3_result.json @@ -0,0 +1,4 @@ +{ + "a": "", + "b": "\u00ad\u0600\u0604\u070f\u17b4\u17b5\u200c\u200f\u2028\u202f\u2060\u206f\ufeff\ufff0\uffff" +} diff --git a/assets/strings3_test.hjson b/assets/strings3_test.hjson new file mode 100644 index 0000000..6811103 --- /dev/null +++ b/assets/strings3_test.hjson @@ -0,0 +1,6 @@ +{ + // Empty string + a: "" + // Unicode code points that require escape inside quotes. + b: "\u00ad\u0600\u0604\u070f\u17b4\u17b5\u200c\u200f\u2028\u202f\u2060\u206f\ufeff\ufff0\uffff" +} diff --git a/assets/strings_result.json b/assets/strings_result.json index bc4c610..f4e946c 100644 --- a/assets/strings_result.json +++ b/assets/strings_result.json @@ -59,4 +59,4 @@ "minus": "-3", "zero": "0" } -} \ No newline at end of file +} diff --git a/assets/testlist.txt b/assets/testlist.txt index eae48cf..feb7854 100644 --- a/assets/testlist.txt +++ b/assets/testlist.txt @@ -1,6 +1,12 @@ charset2_test.hjson charset_test.hjson comments_test.hjson +comments2_test.hjson +comments3_test.hjson +comments4_test.hjson +comments5_test.hjson +comments6_test.hjson +comments7_test.hjson empty_test.hjson failCharset1_test.hjson failJSON02_test.json @@ -64,6 +70,7 @@ failStr6c_test.hjson failStr6d_test.hjson failStr7a_test.hjson failStr8a_test.hjson +int64_test.hjson kan_test.hjson keys_test.hjson mltabs_test.json @@ -72,9 +79,11 @@ pass1_test.json pass2_test.json pass3_test.json pass4_test.json +pass5_test.hjson passSingle_test.hjson stringify1_test.hjson strings2_test.hjson +strings3_test.hjson strings_test.hjson trail_test.hjson stringify/quotes_all_test.hjson @@ -82,6 +91,7 @@ stringify/quotes_always_test.hjson stringify/quotes_keys_test.hjson stringify/quotes_strings_ml_test.json stringify/quotes_strings_test.hjson +windowseol_test.hjson extra/notabs_test.json extra/root_test.hjson -extra/separator_test.json \ No newline at end of file +extra/separator_test.json diff --git a/assets/trail_result.json b/assets/trail_result.json index 451c8ce..bb65b0c 100644 --- a/assets/trail_result.json +++ b/assets/trail_result.json @@ -1,3 +1,3 @@ { "foo": "0 -- this string starts at 0 and ends at 1, preceding and trailing whitespace is ignored -- 1" -} \ No newline at end of file +} diff --git a/assets/windowseol_result.hjson b/assets/windowseol_result.hjson new file mode 100644 index 0000000..90d9564 --- /dev/null +++ b/assets/windowseol_result.hjson @@ -0,0 +1,10 @@ +{ + ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + js-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + ml-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + newline: + ''' + 1 + 2 + ''' +} diff --git a/assets/windowseol_result.json b/assets/windowseol_result.json new file mode 100644 index 0000000..83718a7 --- /dev/null +++ b/assets/windowseol_result.json @@ -0,0 +1,6 @@ +{ + "ql-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", + "js-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", + "ml-ascii": "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", + "newline": "1\n2" +} diff --git a/assets/windowseol_test.hjson b/assets/windowseol_test.hjson new file mode 100644 index 0000000..f1ac289 --- /dev/null +++ b/assets/windowseol_test.hjson @@ -0,0 +1,13 @@ +{ + ql-ascii: ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + js-ascii: "! \"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" + ml-ascii: + ''' + ! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + ''' + newline: + ''' + 1 + 2 + ''' +} diff --git a/hjson_test.go b/hjson_test.go index f023da1..3e42834 100644 --- a/hjson_test.go +++ b/hjson_test.go @@ -15,15 +15,19 @@ import ( "testing" ) +func fixEOL(data []byte) []byte { + // The output from Marshal() always uses Unix EOL, but git might have + // converted files to Windows EOL on Windows, therefore we convert all + // "\r\n" to "\n". + return bytes.Replace(data, []byte("\r\n"), []byte("\n"), -1) +} + func getContent(file string) []byte { - if data, err := ioutil.ReadFile(file); err != nil { + data, err := ioutil.ReadFile(file) + if err != nil { panic(err) - } else { - // The output from Marshal() always uses Unix EOL, but git might have - // converted files to Windows EOL on Windows, therefore we convert all - // "\r\n" to "\n". - return bytes.Replace(data, []byte("\r\n"), []byte("\n"), -1) } + return fixEOL(data) } func getTestContent(name string) []byte { @@ -34,10 +38,12 @@ func getTestContent(name string) []byte { return getContent(p) } -func getResultContent(name string) ([]byte, []byte) { +func getResultContent(name string) ([]byte, []byte, []byte, []byte) { p1 := fmt.Sprintf("./assets/sorted/%s_result.json", name) p2 := fmt.Sprintf("./assets/sorted/%s_result.hjson", name) - return getContent(p1), getContent(p2) + p3 := fmt.Sprintf("./assets/comments2/%s_result.hjson", name) + p4 := fmt.Sprintf("./assets/comments3/%s_result.hjson", name) + return getContent(p1), getContent(p2), getContent(p3), getContent(p4) } func fixJSON(data []byte) []byte { @@ -58,39 +64,109 @@ func run(t *testing.T, file string) { var data interface{} if err := Unmarshal(testContent, &data); err != nil { if !shouldFail { - panic(err) + t.Error(err) } else { return } } else if shouldFail { - panic(errors.New(name + " should_fail!")) + t.Error(errors.New(name + " should_fail!")) } - rjson, rhjson := getResultContent(name) + rjson, rhjson, cm2, cm3 := getResultContent(name) - actualHjson, _ := Marshal(data) + actualHjson, err := Marshal(data) + if err != nil { + t.Error(err) + } actualHjson = append(actualHjson, '\n') - actualJSON, _ := json.MarshalIndent(data, "", " ") + actualJSON, err := json.MarshalIndent(data, "", " ") + if err != nil { + t.Error(err) + } + actualJSON = append(actualJSON, '\n') actualJSON = fixJSON(actualJSON) - - // add fixes where go's json differs from javascript - switch name { - case "kan": - actualJSON = []byte(strings.Replace(string(actualJSON), " -0,", " 0,", -1)) - case "pass1": - actualJSON = []byte(strings.Replace(string(actualJSON), "1.23456789e+09", "1234567890", -1)) + var actualCm2 []byte + { + var node Node + decOpt := DefaultDecoderOptions() + decOpt.WhitespaceAsComments = false + if err := UnmarshalWithOptions(testContent, &node, decOpt); err != nil { + t.Error(err) + } + actualCm2, err = Marshal(node) + if err != nil { + t.Error(err) + } + if len(actualCm2) > 0 && actualCm2[len(actualCm2)-1] != '\n' { + actualCm2 = append(actualCm2, '\n') + } + } + var actualCm3 []byte + { + var node Node + if err := Unmarshal(testContent, &node); err != nil { + t.Error(err) + } + actualCm3, err = Marshal(node) + if err != nil { + t.Error(err) + } + if len(actualCm3) > 0 && actualCm3[len(actualCm3)-1] != '\n' { + actualCm3 = append(actualCm3, '\n') + } } hjsonOK := bytes.Equal(rhjson, actualHjson) jsonOK := bytes.Equal(rjson, actualJSON) + cm2OK := bytes.Equal(cm2, actualCm2) + cm3OK := bytes.Equal(cm3, actualCm3) if !hjsonOK { - t.Logf("%s\n---hjson expected\n%s\n---hjson actual\n%s\n---\n", name, rhjson, actualHjson) + t.Errorf("%s\n---hjson expected\n%s\n---hjson actual\n%s\n---\n", name, rhjson, actualHjson) + // err = ioutil.WriteFile(fmt.Sprintf("./assets/sorted/%s_result.hjson", name), actualHjson, 0644) + // if err != nil { + // t.Error(err) + // } } if !jsonOK { - t.Logf("%s\n---json expected\n%s\n---json actual\n%s\n---\n", name, rjson, actualJSON) + t.Errorf("%s\n---json expected\n%s\n---json actual\n%s\n---\n", name, rjson, actualJSON) + // err = ioutil.WriteFile(fmt.Sprintf("./assets/sorted/%s_result.json", name), actualJSON, 0644) + // if err != nil { + // t.Error(err) + // } + } + if !cm2OK { + t.Errorf("%s\n---cm2 expected\n%s\n---cm2 actual\n%s\n---\n", name, cm2, actualCm2) + // err = ioutil.WriteFile(fmt.Sprintf("./assets/comments2/%s_result.hjson", name), actualCm2, 0644) + // if err != nil { + // t.Error(err) + // } } - if !hjsonOK || !jsonOK { - panic("fail!") + { + var roundTrip interface{} + err = Unmarshal(actualCm2, &roundTrip) + if err != nil { + t.Error(err) + } + if !reflect.DeepEqual(data, roundTrip) { + t.Errorf("cm2 roundtrip failed!") + } + } + if !cm3OK { + t.Errorf("%s\n---cm3 expected\n%s\n---cm3 actual\n%s\n---\n", name, cm3, actualCm3) + // err = ioutil.WriteFile(fmt.Sprintf("./assets/comments3/%s_result.hjson", name), actualCm3, 0644) + // if err != nil { + // t.Error(err) + // } + } + { + var roundTrip interface{} + err = Unmarshal(actualCm3, &roundTrip) + if err != nil { + t.Error(err) + } + if !reflect.DeepEqual(data, roundTrip) { + t.Errorf("cm3 roundtrip failed!") + } } } @@ -99,7 +175,7 @@ func TestHjson(t *testing.T) { files := strings.Split(string(getContent("assets/testlist.txt")), "\n") for _, file := range files { - if !strings.HasPrefix(file, "stringify/quotes") && !strings.HasPrefix(file, "extra/") { + if file != "" && !strings.HasPrefix(file, "stringify/quotes") && !strings.HasPrefix(file, "extra/") { run(t, file) } }