示例#1
0
 def test_parse_object(self):
     self.assertEqual(
         {
             "n": None,
             "f": False,
             "t": True,
             "i": 123.0,
             "s": "abc",
             "a": [1, 2, 3],
             "o": {
                 "1": 1,
                 "2": 2,
                 "3": 3
             }
         },
         parse(
             # self.assertEqual({'n': None}, lept_parse(
             " { "
             "\"n\" : null, "
             "\"f\" : false , "
             "\"t\" : true , "
             "\"i\" : 123 , "
             "\"s\" : \"abc\", "
             "\"a\" : [ 1, 2, 3 ],"
             "\"o\" : { \"1\" : 1, \"2\" : 2, \"3\" : 3 }"
             " } "))
示例#2
0
 def test_parse_string(self):
     self.assertEqual("", parse("\"\""))
     self.assertEqual("Hello", parse("\"Hello\""))
     self.assertEqual("Hello\nWorld", parse("\"Hello\\nWorld\""))
     self.assertEqual("\" \\ / \b \f \n \r \t",
                      parse("\"\\\" \\\\ \\/ \\b \\f \\n \\r \\t\""))
     self.assertEqual("\\\\", parse("\"\\\\\\\\\""))
     self.assertEqual("Hello\0World", parse("\"Hello\\u0000World\""))
     self.assertEqual("\x24", parse("\"\\u0024\""))
     self.assertEqual('\u00a2', parse("\"\\u00A2\""))
     self.assertEqual("\u20ac", parse("\"\\u20AC\""))
     self.assertEqual(b"\xF0\x9D\x84\x9E".decode('utf8'),
                      parse("\"\\uD834\\uDD1E\""))
     self.assertEqual("\x09", parse("\"\\u0009\""))
示例#3
0
 def test_null(self):
     self.assertTrue(parse("null") is None)
示例#4
0
 def test_parse_number(self):
     self.assertEqual(0, parse("0"))
     self.assertEqual(0.0, parse("0"))
     self.assertEqual(0.0, parse("-0"))
     self.assertEqual(0.0, parse("-0.0"))
     self.assertEqual(1.0, parse("1"))
     self.assertEqual(-1.0, parse("-1"))
     self.assertEqual(1.5, parse("1.5"))
     self.assertEqual(-1.5, parse("-1.5"))
     self.assertEqual(3.1416, parse("3.1416"))
     self.assertEqual(1E10, parse("1E10"))
     self.assertEqual(1e10, parse("1e10"))
     self.assertEqual(1E+10, parse("1E+10"))
     self.assertEqual(1E-10, parse("1E-10"))
     self.assertEqual(-1E10, parse("-1E10"))
     self.assertEqual(-1e10, parse("-1e10"))
     self.assertEqual(-1E+10, parse("-1E+10"))
     self.assertEqual(-1E-10, parse("-1E-10"))
     self.assertEqual(1.234E+10, parse("1.234E+10"))
     self.assertEqual(1.234E-10, parse("1.234E-10"))
     self.assertEqual(0.0, parse("1e-10000"))
     self.assertEqual(1.0000000000000002, parse("1.0000000000000002"))
     self.assertEqual(4.9406564584124654e-324,
                      parse("4.9406564584124654e-324"))
     self.assertEqual(-4.9406564584124654e-324,
                      parse("-4.9406564584124654e-324"))
     self.assertEqual(2.2250738585072009e-308,
                      parse("2.2250738585072009e-308"))
     self.assertEqual(-2.2250738585072009e-308,
                      parse("-2.2250738585072009e-308"))
     self.assertEqual(2.2250738585072014e-308,
                      parse("2.2250738585072014e-308"))
     self.assertEqual(-2.2250738585072014e-308,
                      parse("-2.2250738585072014e-308"))
     self.assertEqual(1.7976931348623157e+308,
                      parse("1.7976931348623157e+308"))
     self.assertEqual(-1.7976931348623157e+308,
                      parse("-1.7976931348623157e+308"))
示例#5
0
 def roundtrip(self, json_string):
     self.assertEqual(stringify(parse(json_string)), json_string)
示例#6
0
 def exception(self, json_string, msg):
     with self.assertRaises(LeptJsonParseError) as context:
         parse(json_string)
     self.assertEqual(context.exception.msg, msg)
示例#7
0
 def test_parse_false(self):
     self.assertFalse(parse("false"))
示例#8
0
 def test_parse_array(self):
     self.assertEqual([], parse("[ ]"))
     self.assertEqual([None, False, True, 123.0, 'abc'],
                      parse("[ null , false , true, 123, \"abc\"]"))
     self.assertEqual([[], [0], [0, 1], [0, 1, 2]],
                      parse("[ [ ] , [ 0 ] , [ 0 , 1 ] , [ 0 , 1 , 2 ] ] "))
示例#9
0
 def test_parse_true(self):
     self.assertTrue(parse("true"))