tjsontestsuite.nim 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. discard """
  2. disabled: true
  3. """
  4. ## JSON tests based on https://github.com/nst/JSONTestSuite
  5. import unittest,
  6. json,
  7. strutils
  8. let parsing_testdata = {
  9. "i_number_neg_int_huge_exp": """[-1e+9999]""",
  10. "i_number_pos_double_huge_exp": """[1.5e+9999]""",
  11. "i_object_key_lone_2nd_surrogate": """{"\uDFAA":0}""",
  12. "i_string_1st_surrogate_but_2nd_missing": """["\uDADA"]""",
  13. "i_string_1st_valid_surrogate_2nd_invalid": """["\uD888\u1234"]""",
  14. "i_string_incomplete_surrogate_and_escape_valid": """["\uD800\n"]""",
  15. "i_string_incomplete_surrogate_pair": """["\uDd1ea"]""",
  16. "i_string_incomplete_surrogates_escape_valid": """["\uD800\uD800\n"]""",
  17. "i_string_inverted_surrogates_U+1D11E": """["\uDd1e\uD834"]""",
  18. "i_string_lone_second_surrogate": """["\uDFAA"]""",
  19. "i_string_not_in_unicode_range": """["ô¿¿¿"]""",
  20. "i_string_truncated-utf-8": """["àÿ"]""",
  21. "i_string_unicode_U+10FFFE_nonchar": """["\uDBFF\uDFFE"]""",
  22. "i_string_unicode_U+1FFFE_nonchar": """["\uD83F\uDFFE"]""",
  23. "i_string_unicode_U+FDD0_nonchar": """["\uFDD0"]""",
  24. "i_string_unicode_U+FFFE_nonchar": """["\uFFFE"]""",
  25. "i_string_UTF-16_invalid_lonely_surrogate": """["\ud800"]""",
  26. "i_string_UTF-16_invalid_surrogate": """["\ud800abc"]""",
  27. "i_string_UTF-8_invalid_sequence": """["日шú"]""",
  28. "i_structure_500_nested_arrays": """[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]""",
  29. "i_structure_UTF-8_BOM_empty_object": """{}""",
  30. "n_array_1_true_without_comma": """[1 true]""",
  31. "n_array_a_invalid_utf8": """[aå]""",
  32. "n_array_colon_instead_of_comma": """["": 1]""",
  33. "n_array_comma_after_close": """[""],""",
  34. "n_array_comma_and_number": """[,1]""",
  35. "n_array_double_comma": """[1,,2]""",
  36. "n_array_double_extra_comma": """["x",,]""",
  37. "n_array_extra_close": """["x"]]""",
  38. "n_array_extra_comma": """["",]""",
  39. "n_array_incomplete_invalid_value": """[x""",
  40. "n_array_incomplete": """["x"""",
  41. "n_array_inner_array_no_comma": """[3[4]]""",
  42. "n_array_invalid_utf8": """[ÿ]""",
  43. "n_array_items_separated_by_semicolon": """[1:2]""",
  44. "n_array_just_comma": """[,]""",
  45. "n_array_just_minus": """[-]""",
  46. "n_array_missing_value": """[ , ""]""",
  47. "n_array_newlines_unclosed": """["a",""",
  48. "n_array_newlines_unclosed": """4""",
  49. "n_array_newlines_unclosed": """,1,""",
  50. "n_array_number_and_comma": """[1,]""",
  51. "n_array_number_and_several_commas": """[1,,]""",
  52. "n_array_spaces_vertical_tab_formfeed": """[" a"\f]""",
  53. "n_array_star_inside": """[*]""",
  54. "n_array_unclosed": """[""""",
  55. "n_array_unclosed_trailing_comma": """[1,""",
  56. "n_array_unclosed_with_new_lines": """[1,""",
  57. "n_array_unclosed_with_new_lines": """1""",
  58. "n_array_unclosed_with_new_lines": """,1""",
  59. "n_array_unclosed_with_object_inside": """[{}""",
  60. "n_incomplete_false": """[fals]""",
  61. "n_incomplete_null": """[nul]""",
  62. "n_incomplete_true": """[tru]""",
  63. "n_number_0.1.2": """[0.1.2]""",
  64. "n_number_-01": """[-01]""",
  65. "n_number_0.3e": """[0.3e]""",
  66. "n_number_0.3e+": """[0.3e+]""",
  67. "n_number_0_capital_E": """[0E]""",
  68. "n_number_0_capital_E+": """[0E+]""",
  69. "n_number_0.e1": """[0.e1]""",
  70. "n_number_0e": """[0e]""",
  71. "n_number_0e+": """[0e+]""",
  72. "n_number_1_000": """[1 000.0]""",
  73. "n_number_1.0e-": """[1.0e-]""",
  74. "n_number_1.0e": """[1.0e]""",
  75. "n_number_1.0e+": """[1.0e+]""",
  76. "n_number_-1.0.": """[-1.0.]""",
  77. "n_number_1eE2": """[1eE2]""",
  78. "n_number_.-1": """[.-1]""",
  79. "n_number_+1": """[+1]""",
  80. "n_number_.2e-3": """[.2e-3]""",
  81. "n_number_2.e-3": """[2.e-3]""",
  82. "n_number_2.e+3": """[2.e+3]""",
  83. "n_number_2.e3": """[2.e3]""",
  84. "n_number_-2.": """[-2.]""",
  85. "n_number_9.e+": """[9.e+]""",
  86. "n_number_expression": """[1+2]""",
  87. "n_number_hex_1_digit": """[0x1]""",
  88. "n_number_hex_2_digits": """[0x42]""",
  89. "n_number_infinity": """[Infinity]""",
  90. "n_number_+Inf": """[+Inf]""",
  91. "n_number_Inf": """[Inf]""",
  92. "n_number_invalid+-": """[0e+-1]""",
  93. "n_number_invalid-negative-real": """[-123.123foo]""",
  94. "n_number_invalid-utf-8-in-bigger-int": """[123å]""",
  95. "n_number_invalid-utf-8-in-exponent": """[1e1å]""",
  96. "n_number_invalid-utf-8-in-int": """[0å]""",
  97. "n_number_++": """[++1234]""",
  98. "n_number_minus_infinity": """[-Infinity]""",
  99. "n_number_minus_sign_with_trailing_garbage": """[-foo]""",
  100. "n_number_minus_space_1": """[- 1]""",
  101. "n_number_-NaN": """[-NaN]""",
  102. "n_number_NaN": """[NaN]""",
  103. "n_number_neg_int_starting_with_zero": """[-012]""",
  104. "n_number_neg_real_without_int_part": """[-.123]""",
  105. "n_number_neg_with_garbage_at_end": """[-1x]""",
  106. "n_number_real_garbage_after_e": """[1ea]""",
  107. "n_number_real_with_invalid_utf8_after_e": """[1eå]""",
  108. "n_number_real_without_fractional_part": """[1.]""",
  109. "n_number_starting_with_dot": """[.123]""",
  110. "n_number_then_00": """1\x00""",
  111. "n_number_U+FF11_fullwidth_digit_one": """[1]""",
  112. "n_number_with_alpha_char": """[1.8011670033376514H-308]""",
  113. "n_number_with_alpha": """[1.2a-3]""",
  114. "n_number_with_leading_zero": """[012]""",
  115. "n_object_bad_value": """["x", truth]""",
  116. "n_object_bracket_key": """{[: "x"}""",
  117. "n_object_comma_instead_of_colon": """{"x", null}""",
  118. "n_object_double_colon": """{"x"::"b"}""",
  119. "n_object_emoji": """{🇨🇭}""",
  120. "n_object_garbage_at_end": """{"a":"a" 123}""",
  121. "n_object_key_with_single_quotes": """{key: 'value'}""",
  122. "n_object_missing_colon": """{"a" b}""",
  123. "n_object_missing_key": """{:"b"}""",
  124. "n_object_missing_semicolon": """{"a" "b"}""",
  125. "n_object_missing_value": """{"a":""",
  126. "n_object_no-colon": """{"a"""",
  127. "n_object_non_string_key_but_huge_number_instead": """{9999E9999:1}""",
  128. "n_object_non_string_key": """{1:1}""",
  129. "n_object_pi_in_key_and_trailing_comma": """{"¹":"0",}""",
  130. "n_object_repeated_null_null": """{null:null,null:null}""",
  131. "n_object_several_trailing_commas": """{"id":0,,,,,}""",
  132. "n_object_single_quote": """{'a':0}""",
  133. "n_object_trailing_comma": """{"id":0,}""",
  134. "n_object_trailing_comment": """{"a":"b"}/**/""",
  135. "n_object_trailing_comment_open": """{"a":"b"}/**//""",
  136. "n_object_trailing_comment_slash_open_incomplete": """{"a":"b"}/""",
  137. "n_object_trailing_comment_slash_open": """{"a":"b"}//""",
  138. "n_object_two_commas_in_a_row": """{"a":"b",,"c":"d"}""",
  139. "n_object_unquoted_key": """{a: "b"}""",
  140. "n_object_unterminated-value": """{"a":"a""",
  141. "n_object_with_single_string": """{ "foo" : "bar", "a" }""",
  142. "n_object_with_trailing_garbage": """{"a":"b"}#""",
  143. "n_single_space": """ """,
  144. "n_string_1_surrogate_then_escape": """["\uD800\"]""",
  145. "n_string_1_surrogate_then_escape u1": """["\uD800\u1"]""",
  146. "n_string_1_surrogate_then_escape u1x": """["\uD800\u1x"]""",
  147. "n_string_1_surrogate_then_escape u": """["\uD800\u"]""",
  148. "n_string_accentuated_char_no_quotes": """[é]""",
  149. "n_string_backslash_00": """["\\x00"]""",
  150. "n_string_escaped_backslash_bad": """["\\\"]""",
  151. "n_string_escaped_ctrl_char_tab": """["\ "]""",
  152. "n_string_escaped_emoji": """["\🌀"]""",
  153. "n_string_escape_x": """["\x00"]""",
  154. "n_string_incomplete_escaped_character": """["\u00A"]""",
  155. "n_string_incomplete_escape": """["\"]""",
  156. "n_string_incomplete_surrogate_escape_invalid": """["\uD800\uD800\x"]""",
  157. "n_string_invalid_backslash_esc": """["\a"]""",
  158. "n_string_invalid_unicode_escape": """["\uqqqq"]""",
  159. "n_string_invalid_utf8_after_escape": """["\å"]""",
  160. "n_string_invalid-utf-8-in-escape": """["\uå"]""",
  161. "n_string_invalid_utf-8": """["ÿ"]""",
  162. "n_string_iso_latin_1": """["é"]""",
  163. "n_string_leading_uescaped_thinspace": """[\u0020"asd"]""",
  164. "n_string_lone_utf8_continuation_byte": """["�"]""",
  165. "n_string_no_quotes_with_bad_escape": """[\n]""",
  166. "n_string_overlong_sequence_2_bytes": """["À¯"]""",
  167. "n_string_overlong_sequence_6_bytes": """["üƒ¿¿¿¿"]""",
  168. "n_string_overlong_sequence_6_bytes_null": """["ü€€€€€"]""",
  169. "n_string_single_doublequote": """"""",
  170. "n_string_single_quote": """['single quote']""",
  171. "n_string_single_string_no_double_quotes": """abc""",
  172. "n_string_start_escape_unclosed": """["\""",
  173. "n_string_unescaped_ctrl_char": """["a\x00a"]""",
  174. "n_string_unescaped_newline": """["new
  175. line"]""",
  176. "n_string_unescaped_tab": """[" "]""",
  177. "n_string_unicode_CapitalU": """"\UA66D"""",
  178. "n_string_UTF-16_incomplete_surrogate": """["\uD834\uDd"]""",
  179. "n_string_UTF8_surrogate_U+D800": """["í €"]""",
  180. "n_string_with_trailing_garbage": """""x""",
  181. "n_structure_array_trailing_garbage": """[1]x""",
  182. "n_structure_array_with_extra_array_close": """[1]]""",
  183. "n_structure_array_with_unclosed_string": """["asd]""",
  184. "n_structure_ascii-unicode-identifier": """aå""",
  185. "n_structure_capitalized_True": """[True]""",
  186. "n_structure_close_unopened_array": """1]""",
  187. "n_structure_comma_instead_of_closing_brace": """{"x": true,""",
  188. "n_structure_double_array": """[][]""",
  189. "n_structure_end_array": """]""",
  190. "n_structure_incomplete_UTF8_BOM": """ï»{}""",
  191. "n_structure_<.>": """<.>""",
  192. "n_structure_lone-invalid-utf-8": """å""",
  193. "n_structure_lone-open-bracket": """[""",
  194. "n_structure_null-byte-outside-string": """[\00]""",
  195. "n_structure_<null>": """[<null>]""",
  196. "n_structure_number_with_trailing_garbage": """2@""",
  197. "n_structure_object_followed_by_closing_object": """{}}""",
  198. "n_structure_object_unclosed_no_value": """{"":""",
  199. "n_structure_object_with_comment": """{"a":/*comment*/"b"}""",
  200. "n_structure_object_with_trailing_garbage": """{"a": true} "x"""",
  201. "n_structure_open_array_apostrophe": """['""",
  202. "n_structure_open_array_comma": """[,""",
  203. "n_structure_open_array_open_object": """[{""",
  204. "n_structure_open_array_open_string": """["a""",
  205. "n_structure_open_array_string": """["a"""",
  206. "n_structure_open_object_close_array": """{]""",
  207. "n_structure_open_object_comma": """{,""",
  208. "n_structure_open_object": """{""",
  209. "n_structure_open_object_open_array": """{[""",
  210. "n_structure_open_object_open_string": """{"a""",
  211. "n_structure_open_object_string_with_apostrophes": """{'a'""",
  212. "n_structure_open_open": """["\{["\{["\{["\{""",
  213. "n_structure_single_point": """é""",
  214. "n_structure_single_star": """*""",
  215. "n_structure_trailing_#": """{"a":"b"}#{}""",
  216. "n_structure_U+2060_word_joined": """[�]""",
  217. "n_structure_uescaped_LF_before_string": """[\u000A""]""",
  218. "n_structure_unclosed_array": """[1""",
  219. "n_structure_unclosed_array_partial_null": """[ false, nul""",
  220. "n_structure_unclosed_array_unfinished_false": """[ true, fals""",
  221. "n_structure_unclosed_array_unfinished_true": """[ false, tru""",
  222. "n_structure_unclosed_object": """{"asd":"asd"""",
  223. "n_structure_unicode-identifier": """Ã¥""",
  224. "n_structure_UTF8_BOM_no_data": """""",
  225. "n_structure_whitespace_formfeed": """[ ]""",
  226. "n_structure_whitespace_U+2060_word_joiner": """[�]""",
  227. "y_array_arraysWithSpaces": """[[] ]""",
  228. "y_array_empty": """[]""",
  229. "y_array_empty-string": """[""]""",
  230. "y_array_ending_with_newline": """["a"]""",
  231. "y_array_false": """[false]""",
  232. "y_array_heterogeneous": """[null, 1, "1", {}]""",
  233. "y_array_null": """[null]""",
  234. "y_array_with_1_and_newline": """[1
  235. ]""",
  236. "y_array_with_leading_space": """ [1]""",
  237. "y_array_with_several_null": """[1,null,null,null,2]""",
  238. "y_array_with_trailing_space": """[2] """,
  239. "y_number_0e+1": """[0e+1]""",
  240. "y_number_0e1": """[0e1]""",
  241. "y_number_after_space": """[ 4]""",
  242. "y_number_double_close_to_zero": """[-0.000000000000000000000000000000000000000000000000000000000000000000000000000001]""",
  243. "y_number_double_huge_neg_exp": """[123.456e-789]""",
  244. "y_number_huge_exp": """[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]""",
  245. "y_number_int_with_exp": """[20e1]""",
  246. "y_number": """[123e65]""",
  247. "y_number_minus_zero": """[-0]""",
  248. "y_number_negative_int": """[-123]""",
  249. "y_number_negative_one": """[-1]""",
  250. "y_number_negative_zero": """[-0]""",
  251. "y_number_real_capital_e": """[1E22]""",
  252. "y_number_real_capital_e_neg_exp": """[1E-2]""",
  253. "y_number_real_capital_e_pos_exp": """[1E+2]""",
  254. "y_number_real_exponent": """[123e45]""",
  255. "y_number_real_fraction_exponent": """[123.456e78]""",
  256. "y_number_real_neg_exp": """[1e-2]""",
  257. "y_number_real_neg_overflow": """[-123123e100000]""",
  258. "y_number_real_pos_exponent": """[1e+2]""",
  259. "y_number_real_pos_overflow": """[123123e100000]""",
  260. "y_number_real_underflow": """[123e-10000000]""",
  261. "y_number_simple_int": """[123]""",
  262. "y_number_simple_real": """[123.456789]""",
  263. "y_number_too_big_neg_int": """[-123123123123123123123123123123]""",
  264. "y_number_too_big_pos_int": """[100000000000000000000]""",
  265. "y_number_very_big_negative_int": """[-237462374673276894279832749832423479823246327846]""",
  266. "y_object_basic": """{"asd":"sdf"}""",
  267. "y_object_duplicated_key_and_value": """{"a":"b","a":"b"}""",
  268. "y_object_duplicated_key": """{"a":"b","a":"c"}""",
  269. "y_object_empty": """{}""",
  270. "y_object_empty_key": """{"":0}""",
  271. "y_object_escaped_null_in_key": """{"foo\u0000bar": 42}""",
  272. "y_object_extreme_numbers": """{ "min": -1.0e+28, "max": 1.0e+28 }""",
  273. "y_object": """{"asd":"sdf", "dfg":"fgh"}""",
  274. "y_object_long_strings": """{"x":[{"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}], "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}""",
  275. "y_object_simple": """{"a":[]}""",
  276. "y_object_string_unicode": """{"title":"\u041f\u043e\u043b\u0442\u043e\u0440\u0430 \u0417\u0435\u043c\u043b\u0435\u043a\u043e\u043f\u0430" }""",
  277. "y_object_with_newlines": """{
  278. "a": "b"
  279. }""",
  280. "y_string_1_2_3_bytes_UTF-8_sequences": """["\u0060\u012a\u12AB"]""",
  281. "y_string_accepted_surrogate_pair": """["\uD801\udc37"]""",
  282. "y_string_accepted_surrogate_pairs": """["\ud83d\ude39\ud83d\udc8d"]""",
  283. "y_string_allowed_escapes": """["\"\\\/\b\f\n\r\t"]""",
  284. "y_string_backslash_and_u_escaped_zero": """["\\u0000"]""",
  285. "y_string_backslash_doublequotes": """["\""]""",
  286. "y_string_comments": """["a/*b*/c/*d//e"]""",
  287. "y_string_double_escape_a": """["\\a"]""",
  288. "y_string_double_escape_n": """["\\n"]""",
  289. "y_string_escaped_control_character": """["\u0012"]""",
  290. "y_string_escaped_noncharacter": """["\uFFFF"]""",
  291. "y_string_in_array": """["asd"]""",
  292. "y_string_in_array_with_leading_space": """[ "asd"]""",
  293. "y_string_last_surrogates_1_and_2": """["\uDBFF\uDFFF"]""",
  294. "y_string_newline_uescaped": """["new\u00A0line"]""",
  295. "y_string_nonCharacterInUTF-8_U+10FFFF": """["�"]""",
  296. "y_string_nonCharacterInUTF-8_U+1FFFF": """["𛿿"]""",
  297. "y_string_nonCharacterInUTF-8_U+FFFF": """["ï¿¿"]""",
  298. "y_string_null_escape": """["\u0000"]""",
  299. "y_string_one-byte-utf-8": """["\u002c"]""",
  300. "y_string_pi": """["Ï€"]""",
  301. "y_string_simple_ascii": """["asd "]""",
  302. "y_string_space": """" """",
  303. "y_string_three-byte-utf-8": """["\u0821"]""",
  304. "y_string_two-byte-utf-8": """["\u0123"]""",
  305. "y_string_u+2028_line_sep": """["
"]""",
  306. "y_string_u+2029_par_sep": """["
"]""",
  307. "y_string_uEscape": """["\u0061\u30af\u30EA\u30b9"]""",
  308. "y_string_unescaped_char_delete": """[""]""",
  309. "y_string_unicode_2": """["�㈴�"]""",
  310. "y_string_unicodeEscapedBackslash": """["\u005C"]""",
  311. "y_string_unicode_escaped_double_quote": """["\u0022"]""",
  312. "y_string_unicode": """["\uA66D"]""",
  313. "y_string_unicode_U+200B_ZERO_WIDTH_SPACE": """["\u200B"]""",
  314. "y_string_unicode_U+2064_invisible_plus": """["\u2064"]""",
  315. "y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF": """["\uD834\uDd1e"]""",
  316. "y_string_utf8": """["€�"]""",
  317. "y_string_with_del_character": """["aa"]""",
  318. "y_structure_lonely_false": """false""",
  319. "y_structure_lonely_int": """42""",
  320. "y_structure_lonely_negative_real": """-0.1""",
  321. "y_structure_lonely_null": """null""",
  322. "y_structure_lonely_string": """"asd"""",
  323. "y_structure_lonely_true": """true""",
  324. "y_structure_string_empty": """""""",
  325. "y_structure_trailing_newline": """["a"]""",
  326. "y_structure_true_in_array": """[true]""",
  327. "y_structure_whitespace_array": """ [] """,
  328. }
  329. suite "JSON":
  330. test "Multiple parsing tests":
  331. var test_is_failed = false
  332. for test_item in parsing_testdata:
  333. let name = test_item[0]
  334. let data = test_item[1]
  335. var
  336. parsed_successfully = false
  337. parsed: JsonNode
  338. exception_while_parsing = ""
  339. exception_while_rendering = ""
  340. try:
  341. parsed = parseJson(data)
  342. parsed_successfully = true
  343. except:
  344. exception_while_parsing = getCurrentExceptionMsg()
  345. proc echo_summary(msg: string) =
  346. var rendered = ""
  347. var render_successfully = false
  348. if parsed_successfully:
  349. try:
  350. rendered = $parsed
  351. render_successfully = true
  352. except:
  353. rendered = "[Fail to render:<$#>]" % getCurrentExceptionMsg()
  354. else:
  355. rendered = "<$#>" % exception_while_parsing
  356. echo name, repeat(' ', 60 - name.len), "[$#]" % msg, " ", rendered
  357. case name[0]
  358. of 'y':
  359. # Tests starting with y_ must parse
  360. if not parsed_successfully:
  361. echo_summary "Failed to parse"
  362. test_is_failed = true
  363. of 'n':
  364. # Tests starting with n_ should not parse
  365. if parsed_successfully:
  366. echo_summary "Failed to raise exception"
  367. of 'i':
  368. if parsed_successfully:
  369. echo_summary "OK"
  370. else:
  371. echo_summary "Not parsed"
  372. else: discard
  373. # FIXME: temporarily disabled until "y_" tests will succeed
  374. # if test_is_failed: fail()