Exemplo n.º 1
0
    def test_byte(self):
        data = bytes("\xA0\x00\xBC\xFF\x98\x66\x66\xA0\x00\xBC\xFF\x98\x66\x66\x99\x80")
        f = test_file(data)

        p = Parser(f.name)
        for b in bytearray(data):
            assert p.byte() == b
Exemplo n.º 2
0
    def test_if_with_bool(self):
        f = test_file(src="""
            x = true
            y = false
            if x == true then
                print ("OK1")
            end

            if x ~= true then
                print ("F1")
            end

            if x == y then
                print("F2")
            end

            if x ~= y then
                print("OK2")
            end

            if true == x then
                print ("OK3")
            end

            if y == true then
                print("F3")
            end
            """, suffix=".l"
        )
        out =  subprocess.check_output([TestCompiled.PYLUA_BIN, f.name])
        assert out == "OK1\nOK2\nOK3\n"
Exemplo n.º 3
0
 def test_h(self):
     data = bytes("\xA0\x00\xBC\xFF\x98\x66\x66\xA0\x00\xBC\xFF\x98\x66\x66\x99\x80")
     f = test_file(data)
     # little endian 2 byte blocks
     bb = [0x00a0, 0xffbc, 0x6698, 0xa066, 0xbc00, 0x98ff, 0x6666, 0x8099]
     p = Parser(f.name)
     for h in bb:
         assert p.h() == h
Exemplo n.º 4
0
    def test_byte(self):
        data = bytes(
            "\xA0\x00\xBC\xFF\x98\x66\x66\xA0\x00\xBC\xFF\x98\x66\x66\x99\x80")
        f = test_file(data)

        p = Parser(f.name)
        for b in bytearray(data):
            assert p.byte() == b
Exemplo n.º 5
0
 def test_h(self):
     data = bytes(
         "\xA0\x00\xBC\xFF\x98\x66\x66\xA0\x00\xBC\xFF\x98\x66\x66\x99\x80")
     f = test_file(data)
     # little endian 2 byte blocks
     bb = [0x00a0, 0xffbc, 0x6698, 0xa066, 0xbc00, 0x98ff, 0x6666, 0x8099]
     p = Parser(f.name)
     for h in bb:
         assert p.h() == h
Exemplo n.º 6
0
    def test_word(self, ):
        data = bytes("\xA0\x00\xBC\xFF\x98\x66\x66\xA0\x00\xBC\xFF\x98\x66\x66\x99\x80")
        f = test_file(data)
        # little endian words (4 byte blocks)
        words = [0xffbc00a0,  0xa0666698, 0x98ffbc00, 0x80996666 ] 

        p = Parser(f.name)
        for w in words:
            x = p.word()
            print(hex(x))
            assert x == w
Exemplo n.º 7
0
    def test_if_with_str(self):
        f = test_file(src="""
            x = "foo"
            y = "bar"
            if x == "foo" then
                print ("OK1")
            end

            if x ~= "foo" then
                print ("F1")
            end

            if x < y then
                print ("F2")
            end

            if x <= y then
                print ("F3")
            end

            if x > y then
                print ("OK2")
            end

            if x >= y then
                print ("OK3")
            end

            if x == y then
                print ("F4")
            end

             if x ~= y then
                print ("OK4")
            end

            xx = "foo"

            if x == xx then
                print ("OK5")
            end

            if x >= xx then
                print ("OK6")
            end

            if x <= xx then
                print ("OK7")
            end
            """, suffix=".l"
        )
        out =  subprocess.check_output([TestCompiled.PYLUA_BIN, f.name])
        assert out == "OK1\nOK2\nOK3\nOK4\nOK5\nOK6\nOK7\n"
Exemplo n.º 8
0
    def test_word(self, ):
        data = bytes(
            "\xA0\x00\xBC\xFF\x98\x66\x66\xA0\x00\xBC\xFF\x98\x66\x66\x99\x80")
        f = test_file(data)
        # little endian words (4 byte blocks)
        words = [0xffbc00a0, 0xa0666698, 0x98ffbc00, 0x80996666]

        p = Parser(f.name)
        for w in words:
            x = p.word()
            print(hex(x))
            assert x == w
Exemplo n.º 9
0
    def test_recursive_call(self):

        f = test_file(src="""
            function fac(n)
                if n == 1 then
                    return 1
                end
                return fac(n-1) * n
            end
            x = fac(10)
            print(x)
            """, suffix=".l"
        )
        out =  subprocess.check_output([TestCompiled.PYLUA_BIN, f.name])
        assert out == "3628800\n"
Exemplo n.º 10
0
    def test_addition(self):
        f = test_file(src="""
            -- short add
            x = 10
            y = 5
            z = y + y + x
            print(z)
            print(z+y)
            --a = 100+y

            lx = 1234567890.55
            ly = 99999999
            print(lx+ly)
            --print(lx+1234567890)
            """, suffix=".l"
        )
        out =  subprocess.check_output([TestCompiled.PYLUA_BIN, f.name])
        assert out == "20\n25\n1334567889.550000\n"
Exemplo n.º 11
0
 def test_with_invalid_lua_file(self):
     f = test_file("this is no lua code", suffix=".l")
     assert ENTRY_POINT(['', f.name]) == 1
Exemplo n.º 12
0
 def test_with_invalid_extension(self):
     f = test_file("int main(void{};", suffix=".c")
     assert ENTRY_POINT(['', f.name]) == 1
Exemplo n.º 13
0
 def test_with_lua_file(self):
     f = test_file("x = 1", suffix=".l")
     assert ENTRY_POINT(['', f.name]) == 0
     assert os.path.exists(f.name + 'c')
Exemplo n.º 14
0
 def test_uleb(self):
     f = test_file("\xE5\x8E\x26")
     p = Parser(f.name)
     assert p.uleb() == 624485
Exemplo n.º 15
0
 def test_uleb(self):
     f = test_file("\xE5\x8E\x26")
     p = Parser(f.name)
     assert p.uleb() == 624485
Exemplo n.º 16
0
 def test_with_lua_file(self):
     f = test_file("x = 1", suffix=".l")
     assert ENTRY_POINT(['', f.name]) == 0
     assert os.path.exists(f.name+'c')
Exemplo n.º 17
0
 def test_with_invalid_extension(self):
     f = test_file("int main(void{};", suffix=".c")
     assert ENTRY_POINT(['', f.name]) == 1
Exemplo n.º 18
0
 def test_with_invalid_lua_file(self):
     f = test_file("this is no lua code", suffix=".l")
     assert ENTRY_POINT(['', f.name]) == 1