예제 #1
0
 def test_simple_object_2(self):
     p = Parser("""{"hello":1, '123': 0x123 ,_test: "test"}""")
     self.assertEquals({
         'hello': 1,
         '123': 0x123,
         '_test': 'test'
     }, p.parse())
예제 #2
0
 def test_simple_array_1(self):
     p = Parser('[1,2,3]')
     self.assertEquals([
         1,
         2,
         3,
     ], p.parse())
예제 #3
0
 def test_simple_array_2(self):
     p = Parser('[1 , 2 , 3,4 , 5,6 ]')
     self.assertEquals([
         1,
         2,
         3,
         4,
         5,
         6,
     ], p.parse())
예제 #4
0
 def test_complex(self):
     p = Parser(""" { id:'03684ca0-6dee-46d2-98b7-06f2cd079f5c',
             key:'5b2e34b4-995a-4d66-8b0f-392232bc1563',
             name:'Arduino Pins',
             deviceClass:{
                 name:'Arduino',
                 version:'1.0'},
                 equipment:[],
                 commands:[
                 {intent:1001,name:'getPinMode',params:[u8]},
                 {intent:1002,name:'setPinMode',params:{pin:u8,mode:u8}},
                 {intent:1003,name:'pinRead',params:[u8]},
                 {intent:1004,name:'pinWrite',params:{pin:u8,value:u16}}
                 ],
             notifications:[
                 {intent:2001,name:'pinMode',params:{pin:u8,mode:u8}},
                 {intent:2003,name:'pinRead',params:{pin:u8,value:u16}}
             ]
         }""")
     self.assertIsNotNone(p.parse())
예제 #5
0
 def test_complex(self):
     p = Parser(""" { id:'03684ca0-6dee-46d2-98b7-06f2cd079f5c',
             key:'5b2e34b4-995a-4d66-8b0f-392232bc1563',
             name:'Arduino Pins',
             deviceClass:{
                 name:'Arduino',
                 version:'1.0'},
                 equipment:[],
                 commands:[
                 {intent:1001,name:'getPinMode',params:[u8]},
                 {intent:1002,name:'setPinMode',params:{pin:u8,mode:u8}},
                 {intent:1003,name:'pinRead',params:[u8]},
                 {intent:1004,name:'pinWrite',params:{pin:u8,value:u16}}
                 ],
             notifications:[
                 {intent:2001,name:'pinMode',params:{pin:u8,mode:u8}},
                 {intent:2003,name:'pinRead',params:{pin:u8,value:u16}}
             ]
         }""")
     self.assertIsNotNone(p.parse())
예제 #6
0
 def test_parse_number_8(self):
     p = Parser('0')
     self.assertEqual(0, p.parse())
예제 #7
0
 def test_parse_number_10(self):
     p = Parser('123')
     self.assertEqual(123, p.parse())
예제 #8
0
 def test_esc_2(self):
     p = Parser(r'"\""')
     self.assertEqual('"', p.parse())
예제 #9
0
 def test_empty_2(self):
     p = Parser('   ')
     self.assertIsNone(p.parse())
예제 #10
0
 def test_order_test(self):
     p = Parser("""{"b1": 1, 'a2': 2, 'c3': 3 }""")
     r = [i for i in p.parse()]
     self.assertEqual('b1', r[0])
     self.assertEqual('a2', r[1])
     self.assertEqual('c3', r[2])
예제 #11
0
 def test_string_dq_and_space(self):
     p = Parser(' "hello all" ')
     self.assertEquals('hello all', p.parse())
예제 #12
0
 def test_string(self):
     p = Parser("'hello all'")
     self.assertEquals('hello all', p.parse())
예제 #13
0
 def test_esc_3(self):
     p = Parser(r'"\\""')
     self.assertEquals('\\', p.parse())
예제 #14
0
 def test_esc_2(self):
     p = Parser(r'"\""')
     self.assertEquals('"', p.parse())
예제 #15
0
 def test_empty_array_1(self):
     p = Parser('[ ]')
     self.assertEqual([], p.parse())
예제 #16
0
 def test_simple_object_1(self):
     p = Parser('{"hello":1}')
     self.assertEqual({'hello':1}, p.parse())
예제 #17
0
 def test_parse_number_10(self):
     p = Parser('123')
     self.assertEquals(123, p.parse())
예제 #18
0
 def test_empty_2(self):
     p = Parser('   ')
     self.assertIsNone(p.parse())
예제 #19
0
 def test_parse_number_16(self):
     p = Parser('0x123')
     self.assertEquals(0x123, p.parse())
예제 #20
0
 def test_order_test(self):
     p = Parser("""{"b1": 1, 'a2': 2, 'c3': 3 }""")
     r = [i for i in p.parse()]
     self.assertEquals('b1', r[0])
     self.assertEquals('a2', r[1])
     self.assertEquals('c3', r[2])
예제 #21
0
 def test_parse_number_8(self):
     p = Parser('0')
     self.assertEquals(0, p.parse())
예제 #22
0
 def test_empty_3(self):
     p = Parser('\t \n')
     self.assertIsNone(p.parse())
예제 #23
0
 def test_parse_identifier_1(self):
     p = Parser('test123_321')
     self.assertEquals('test123_321', p.parse())
예제 #24
0
 def test_esc_3(self):
     p = Parser(r'"\\""')
     self.assertEqual('\\', p.parse())
예제 #25
0
 def test_parse_identifier_2(self):
     p = Parser('__test123_321')
     self.assertEquals('__test123_321', p.parse())
예제 #26
0
 def test_string_dq_and_space(self):
     p = Parser(' "hello all" ')
     self.assertEqual('hello all', p.parse())
예제 #27
0
 def test_simple_array_1(self):
     p = Parser('[1,2,3]')
     self.assertEquals([1,2,3], p.parse())
예제 #28
0
 def test_parse_number_16(self):
     p = Parser('0x123')
     self.assertEqual(0x123, p.parse())
예제 #29
0
 def test_simple_array_2(self):
     p = Parser('[1 , 2 , 3,4 , 5,6 ]')
     self.assertEquals([1,2,3,4,5,6], p.parse())
예제 #30
0
 def test_parse_identifier_2(self):
     p = Parser('__test123_321')
     self.assertEqual('__test123_321', p.parse())
예제 #31
0
 def test_empty_array_1(self):
     p = Parser('[ ]')
     self.assertEquals([], p.parse())
예제 #32
0
 def test_mixed_array(self):
     p = Parser('["test", 1, hello]')
     self.assertEqual(['test', 1, 'hello'], p.parse())
예제 #33
0
 def test_mixed_array(self):
     p = Parser('["test", 1, hello]')
     self.assertEquals(['test', 1, 'hello'], p.parse())
예제 #34
0
 def test_simple_complex_1(self):
     p = Parser("""{"arr": [ 1, 2 , 3], 'obj': { prop : 1 }}""")
     self.assertEqual({'arr':[1,2,3], 'obj': {'prop': 1}}, p.parse())
예제 #35
0
 def test_simple_object_1(self):
     p = Parser('{"hello":1}')
     self.assertEquals({'hello':1}, p.parse())
예제 #36
0
 def test_string(self):
     p = Parser("'hello all'")
     self.assertEqual('hello all', p.parse())
예제 #37
0
 def test_simple_object_2(self):
     p = Parser("""{"hello":1, '123': 0x123 ,_test: "test"}""")
     self.assertEquals({'hello':1, '123': 0x123, '_test': 'test'}, p.parse())
예제 #38
0
 def test_empty_3(self):
     p = Parser('\t \n')
     self.assertIsNone(p.parse())
예제 #39
0
 def test_simple_complex_1(self):
     p = Parser("""{"arr": [ 1, 2 , 3], 'obj': { prop : 1 }}""")
     self.assertEquals({'arr':[1,2,3], 'obj': {'prop': 1}}, p.parse())