test_pass1.py 1.7 KB

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