예제 #1
0
 def test_array_multiple_elements(self):
     code = '[1, 2]'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, [1, 2])
예제 #2
0
 def test_empty_array(self):
     code = '[]'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, [])
예제 #3
0
 def test_array_one_element(self):
     code = '[1]'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, [1])
예제 #4
0
 def test_object_one_pair(self):
     code = '{1: 2}'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, {1: 2})
예제 #5
0
 def test_object_multiple_pairs(self):
     code = '{1:2, 3:4}'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, {1: 2, 3: 4})
예제 #6
0
 def test_null(self):
     code = 'null'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, None)
예제 #7
0
 def test_positive_float(self):
     code = '3.14'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, 3.14)
예제 #8
0
 def test_invalid_syntax_array_key(self):
     with self.assertRaises(ParserError):
         result = Parser(Lexer('{[]: "no"}')).parse()
예제 #9
0
 def test_invalid_syntax_array_consume_eof(self):
     with self.assertRaises(ParserError):
         result = Parser(Lexer('[][]')).parse()
예제 #10
0
 def test_complex_object(self):
     code = '{2: [], "lol": {"omg": {"so": {"deep": []}}}}'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, {2: [], 'lol': {'omg': {'so': {'deep': []}}}})
예제 #11
0
 def test_invalid_syntax_solo_comma(self):
     with self.assertRaises(ParserError):
         result = Parser(Lexer(',')).parse()
예제 #12
0
 def test_complex_array(self):
     code = '[true, false, null, "lol", {"key": [{}, []]}]'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, [True, False, None, 'lol', {'key': [{}, []]}])
예제 #13
0
 def test_string(self):
     code = '"omg_kittens"'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, "omg_kittens")
예제 #14
0
 def test_negative_float(self):
     code = '-3.14'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, -3.14)
예제 #15
0
 def test_true(self):
     code = 'true'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, True)
예제 #16
0
 def test_invalid_keyword(self):
     with self.assertRaises(KeywordError):
         result = Parser(Lexer('falsey')).parse()
예제 #17
0
 def test_false(self):
     code = 'false'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, False)
예제 #18
0
 def test_empty_object(self):
     code = '{}'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, {})
예제 #19
0
 def test_positive_integer(self):
     code = '314'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, 314)
예제 #20
0
 def test_negative_integer(self):
     code = '-314'
     result = Parser(Lexer(code)).parse()
     self.assertEqual(result, -314)