示例#1
0
 def test_empty_block(self):
     data = "create_object arg"
     print(parse(data))
     self.assertEqual(
         parse(data), {
             'body': [{
                 'name': 'create_object',
                 'value': 'arg',
                 'type': 'block',
                 'body': []
             }]
         })
示例#2
0
 def test_anon_block(self):
     data = "{ set_option }"
     self.assertEqual(parse(data),
                      {'body': [{
                          'name': 'set_option',
                          'type': 'set'
                      }]})
示例#3
0
 def test_set(self):
     data = "set_option"
     self.assertEqual(parse(data),
                      {'body': [{
                          'name': 'set_option',
                          'type': 'set'
                      }]})
示例#4
0
 def test_define(self):
     data = "#define LABEL"
     self.assertEqual(parse(data),
                      {'body': [{
                          'name': 'LABEL',
                          'type': 'define'
                      }]})
示例#5
0
 def test_comment(self):
     data = "/* hello */"
     self.assertEqual(
         parse(data),
         {'body': [{
             'value': '/* hello */',
             'type': 'comment'
         }]})
示例#6
0
 def test_section(self):
     data = "<test_section>"
     self.assertEqual(parse(data), {
         'body': [{
             'name': 'test_section',
             'type': 'section',
             'body': []
         }]
     })
示例#7
0
 def test_comment_unopened(self):
     data = "some_attr 1 */"
     self.assertEqual(parse(data), {
         'body': [{
             'name': 'some_attr',
             'value': ['1'],
             'type': 'attribute'
         }]
     })
示例#8
0
 def test_include(self):
     data = "#include_drs random_map.def"
     self.assertEqual(parse(data), {
         'body': [{
             'name': 'random_map.def',
             'value': None,
             'type': 'include'
         }]
     })
示例#9
0
 def test_const(self):
     data = "#const TEST 1"
     self.assertEqual(
         parse(data),
         {'body': [{
             'value': 1,
             'name': 'TEST',
             'type': 'const'
         }]})
示例#10
0
 def test_attribute(self):
     data = "some_attr 1 2"
     self.assertEqual(
         parse(data), {
             'body': [{
                 'name': 'some_attr',
                 'value': ['1', '2'],
                 'type': 'attribute'
             }]
         })
示例#11
0
 def test_conditional_orphan(self):
     data = "if TEST endif endif"
     self.assertEqual(
         parse(data), {
             'body': [{
                 'type': 'conditional',
                 'body': [{
                     'type': 'if',
                     'body': [],
                     'value': 'TEST'
                 }]
             }]
         })
示例#12
0
 def test_conditional_block_eof(self):
     data = "{if TEST}"
     self.assertEqual(
         parse(data), {
             'body': [{
                 'type': 'conditional',
                 'body': [{
                     'type': 'if',
                     'body': [],
                     'value': 'TEST'
                 }]
             }]
         })
示例#13
0
 def test_random(self):
     data = "start_random percent_chance 10 end_random"
     self.assertEqual(
         parse(data), {
             'body': [{
                 'type': 'random',
                 'body': [{
                     'type': 'chance',
                     'value': 10,
                     'body': []
                 }]
             }]
         })
示例#14
0
 def test_conditional(self):
     data = "if TEST elseif OTHER else endif"
     self.assertEqual(
         parse(data), {
             'body': [{
                 'type':
                 'conditional',
                 'body': [{
                     'type': 'if',
                     'body': [],
                     'value': 'TEST'
                 }, {
                     'type': 'elseif',
                     'body': [],
                     'value': 'OTHER'
                 }, {
                     'type': 'else',
                     'body': []
                 }]
             }]
         })
示例#15
0
 def test_invalid(self):
     data = "elseif X"
     with self.assertRaises(ValueError):
         parse(data)
示例#16
0
 def test_unmatched_closer(self):
     data = "endif"
     self.assertEqual(parse(data), {'body': []})