Пример #1
0
 def test_table(self):
     source = textwrap.dedent('''\
         local table = {
             ['ok'] = true,
             foo = bar,
         }''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #2
0
 def test_func(self):
     source = textwrap.dedent('''\
         function nop(arg, ...)
             break
             return 1, 2, 3
         end''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #3
0
 def test_while(self):
     source = textwrap.dedent('''\
         while a[i] do
             print(a[i])
             i = i + 1
         end''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #4
0
 def test_if(self):
     source = textwrap.dedent('''\
         if op == "+" then
             r = a + b
         elseif op == "-" then
             r = a - b
         elseif op == "*" then
             r = a * b
         elseif op == "/" then
             r = a / b
         else
             error("invalid operation")
         end''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #5
0
 def test_anonymous_func(self):
     source = textwrap.dedent('''\
         local ano = function()
             nop()
         end''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #6
0
 def test_method(self):
     source = textwrap.dedent('''\
         function my:method(arg1, ...)
             nop()
         end''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #7
0
 def test_call_invoke(self):
     source = textwrap.dedent('''\
         call("foo")
         invoke:me("ok")''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #8
0
 def test_assign(self):
     source = textwrap.dedent('''\
         a = 42
         local b = "42"''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #9
0
 def test_for_in(self):
     source = textwrap.dedent('''\
         for key, value in pairs(t) do
             print(key, value)
         end''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #10
0
 def test_for_num(self):
     source = textwrap.dedent('''\
         for i = 1, 10 do
             print(i)
         end''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #11
0
 def test_goto(self):
     source = textwrap.dedent('''\
         ::label::
         goto label''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))
Пример #12
0
 def test_repeat(self):
     source = textwrap.dedent('''\
         repeat
             print("value of a:", a)
         until a > 15''')
     self.assertEqual(source, ast.to_lua_source(ast.parse(source)))