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 }" " } "))
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\""))
def test_null(self): self.assertTrue(parse("null") is None)
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"))
def roundtrip(self, json_string): self.assertEqual(stringify(parse(json_string)), json_string)
def exception(self, json_string, msg): with self.assertRaises(LeptJsonParseError) as context: parse(json_string) self.assertEqual(context.exception.msg, msg)
def test_parse_false(self): self.assertFalse(parse("false"))
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 ] ] "))
def test_parse_true(self): self.assertTrue(parse("true"))