python (3.12.0)
1 from test.test_json import PyTest, CTest
2
3
4 # from https://json.org/JSON_checker/test/pass1.json
5 JSON = r'''
6 [
7 "JSON Test Pattern pass1",
8 {"object with 1 member":["array with 1 element"]},
9 {},
10 [],
11 -42,
12 true,
13 false,
14 null,
15 {
16 "integer": 1234567890,
17 "real": -9876.543210,
18 "e": 0.123456789e-12,
19 "E": 1.234567890E+34,
20 "": 23456789012E66,
21 "zero": 0,
22 "one": 1,
23 "space": " ",
24 "quote": "\"",
25 "backslash": "\\",
26 "controls": "\b\f\n\r\t",
27 "slash": "/ & \/",
28 "alpha": "abcdefghijklmnopqrstuvwyz",
29 "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
30 "digit": "0123456789",
31 "0123456789": "digit",
32 "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
33 "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
34 "true": true,
35 "false": false,
36 "null": null,
37 "array":[ ],
38 "object":{ },
39 "address": "50 St. James Street",
40 "url": "http://www.JSON.org/",
41 "comment": "// /* <!-- --",
42 "# -- --> */": " ",
43 " s p a c e d " :[1,2 , 3
44
45 ,
46
47 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
48 "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
49 "quotes": "" \u0022 %22 0x22 034 "",
50 "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
51 : "A key can be any string"
52 },
53 0.5 ,98.6
54 ,
55 99.44
56 ,
57
58 1066,
59 1e1,
60 0.1e1,
61 1e-1,
62 1e00,2e+00,2e-00
63 ,"rosebud"]
64 '''
65
66 class ESC[4;38;5;81mTestPass1:
67 def test_parse(self):
68 # test in/out equivalence and parsing
69 res = self.loads(JSON)
70 out = self.dumps(res)
71 self.assertEqual(res, self.loads(out))
72
73
74 class ESC[4;38;5;81mTestPyPass1(ESC[4;38;5;149mTestPass1, ESC[4;38;5;149mPyTest): pass
75 class ESC[4;38;5;81mTestCPass1(ESC[4;38;5;149mTestPass1, ESC[4;38;5;149mCTest): pass