Beispiel #1
0
def test_parse_example():
    lisp_code = "(first (list 1 (+ 2 3) 9))"
    ast, final_bracket = parse_lisp_helper(lisp_code, 0)
    assert final_bracket == len(lisp_code) - 1
    assert ["first", ["list", 1, ["+", 2, 3], 9]] == ast
Beispiel #2
0
def test_not_well_formatted():
    lisp_code = "(list 8 9 3"
    ast, final_bracket = parse_lisp_helper(lisp_code, 0)
    assert final_bracket != len(lisp_code) - 1
Beispiel #3
0
def test_parse_bracket_after_end():
    lisp_code = "(list 1 (+ 2 5) 4 (- 5 8))"
    ast, final_bracket = parse_lisp_helper(lisp_code, 0)
    assert final_bracket == len(lisp_code) - 1
    assert ["list", 1, ["+", 2, 5], 4, ["-", 5, 8]] == ast
Beispiel #4
0
def test_parse_double_empty():
    lisp_code = "(())"
    ast, final_bracket = parse_lisp_helper(lisp_code, 0)
    assert final_bracket == len(lisp_code) - 1
    assert [[]] == ast
Beispiel #5
0
def test_parse_one_layer():
    lisp_code = "(list 8 9 3)"
    ast, final_bracket = parse_lisp_helper(lisp_code, 0)
    assert final_bracket == len(lisp_code) - 1
    assert ["list", 8, 9, 3] == ast