Beispiel #1
0
    def test_basic_if(self, ptp):
        pseudo_str = """
if a then
    show a
end
if b then :
    show b
end
if c then:
    show c
end
if d :
    show d
end
        """

        py_str = """
if a:
    print(a)
if b:
    print(b)
if c:
    print(c)
if d:
    print(d)
        """

        assert ast_check(ptp, py_str, pseudo_str)
Beispiel #2
0
    def test_if_else(self, ptp):
        pseudo_str = """
if a then
    show a
else
    show "Not a"
end
if b then
    show b
else
    if c then
        show c
    else
        show d
    end
end
        """

        py_str = """
if a:
    print(a)
else:
    print('Not a')
if b:
    print(b)
elif c:
    print(c)
else:
    print(d)
        """

        assert ast_check(ptp, py_str, pseudo_str)
Beispiel #3
0
    def test_nested_while(self, ptp):
        pseudo_str = """
while a is greater than b do
    while b is greater than c do
        a equals a minus 1
    end
end
        """

        py_str = """
while a > b:
    while b > c:
        a = a - 1
        """

        assert ast_check(ptp, py_str, pseudo_str)
Beispiel #4
0
    def test_while_else(self, ptp):
        pseudo_str = """
while a is greater than b do
    a equals a minus 1
else
    show a
end
        """

        py_str = """
while a > b:
    a = a - 1
else:
    print(a)
        """

        assert ast_check(ptp, py_str, pseudo_str)
Beispiel #5
0
    def test_basic_while(self, ptp):
        pseudo_str = """
while a is greater than b do
    a equals a minus 1
end
while b is greater than c :
    b equals b minus 1
end
        """

        py_str = """
while a > b:
    a = a - 1
while b > c:
    b = b - 1
        """

        assert ast_check(ptp, py_str, pseudo_str)
Beispiel #6
0
    def test_nested_ifs(self, ptp):
        pseudo_str = """
if a :
    if b :
        if c :
            show c
        end
    end
end
        """

        py_str = """
if a:
    if b:
        if c:
            print(c)
        """

        assert ast_check(ptp, py_str, pseudo_str)
Beispiel #7
0
    def test_elif(self, ptp):
        pseudo_str = """
if a then
    show a
else if b then
    show b
else
    show c
end
        """

        py_str = """
if a:
    print(a)
elif b:
    print(b)
else:
    print(c)
        """

        assert ast_check(ptp, py_str, pseudo_str)
Beispiel #8
0
    def test_break_continue(self, ptp):
        pseudo_str = """
while a is greater than b do
    if a is equal to 2 then
        break
    end
    if a is equal to 3 then
        continue
    end
end
        """

        py_str = """
while a > b:
    if a == 2:
        break
    if a == 3:
        continue
        """

        assert ast_check(ptp, py_str, pseudo_str)