Exemplo n.º 1
0
    def test_pretty_def_lambda(self):
        s = StringIO("def identity:\n lambda x:\n              x\n")
        l = lexer.Lexer(s)
        p = parser.Parser(l)
        tree = p.program()
        pstr = pretty.make_pretty(tree)

        assert pstr == "def identity:\n    lambda x:\n        x\n"
Exemplo n.º 2
0
    def test_pretty_def(self):
        s = StringIO("def var:\n  5\n")
        l = lexer.Lexer(s)
        p = parser.Parser(l)
        tree = p.program()
        pstr = pretty.make_pretty(tree)

        print(pstr)
        assert pstr == "def var:\n    5\n"
Exemplo n.º 3
0
    def test_pretty_tree_empty(self):
        s = StringIO("")
        l = lexer.Lexer(s)
        p = parser.Parser(l)
        tree = p.program()
        pstr = pretty.make_pretty(tree)

        print(pstr)
        assert pstr == ""
Exemplo n.º 4
0
    def test_pretty_case_tuples(self):
        with open("tests/case/tuple.swl") as s:
            l = lexer.Lexer(s)
            p = parser.Parser(l)
            tree = p.program()
            pstr = pretty.make_pretty(tree)

            cstr = 'def a_tuple:\n    `["Item1" 2 ["Nested" "Tuples"] 3 4]\nprint(a_tuple)\n'
            print(pstr)
            print(cstr)
            assert pstr == cstr
Exemplo n.º 5
0
    def test_pretty_case_mandelbrot(self):
        with open("tests/case/mandelbrot.swl") as s:
            l = lexer.Lexer(s)
            p = parser.Parser(l)
            tree = p.program()
            pstr = pretty.make_pretty(tree)

            cstr = "def square:\n    lambda x:\n        mul(x x)\ndef mandelbrot_iter:\n    lambda iterations:\n        lambda x y:\n            def helper:\n                lambda iter_left r s:\n                    if equal(iter_left 0):\n                        0\n                    elif gt(sqrt(add(square(r) square(s))) 2):\n                        sub(iterations iter_left)\n                    else:\n                        helper(sub(iter_left 1) add(sub(square(r) square(s)) x) add(mul(2 r s) y))\n            helper(iterations 0 0)\n"
            print(pstr)
            print(cstr)
            assert pstr == cstr
Exemplo n.º 6
0
    def test_pretty_quote_symbol(self):
        s = StringIO("def s:\n  `symbol\n")
        l = lexer.Lexer(s)
        p = parser.Parser(l)
        tree = p.program()
        pstr = pretty.make_pretty(tree)

        cstr = "def s:\n    `symbol\n"
        print(pstr)
        print(cstr)
        assert pstr == cstr