示例#1
0
def test_car():
    '(car (t f t f f))'

    assert L(S('car'), L(S('quote'), L(S('t'), S('f')))).eval(env) == S('t')

    with pytest.raises(TypeError):
        L(S('car'), L(S('t'), S('f'))).eval(env)
示例#2
0
def test_atom():
    assert L(S('atom'), S('t')).eval(env) == T
    assert L(S('atom'), S('f')).eval(env) == T
    assert L(S('atom'), S('nil')).eval(env) == T

    assert L(S('atom'), L(S('quote'), L(S('t')))).eval(env) == F
    assert L(S('atom'), L(S('quote'), L(S('atom')))).eval(env) == F
示例#3
0
def test_eval_quoted_list():
    l = L(S('quote'), L(T, F, NIL)).eval(env)

    assert type(l) is L
    assert str(l) == '(t () NIL)'
示例#4
0
def test_eval_cannot_apply_to_symbol():
    with pytest.raises(TypeError):
        L(T, F, NIL).eval(env)
示例#5
0
def test_parser_14():
    assert parse("""
        (+ 1 2)
    """) == (L(S('+'), I(1), I(2)))
示例#6
0
def test_parser_13():
    assert parse("""
        (cons "1" '("2" "3"))
    """) == (L(S('cons'), Str('1'), L(S('quote'), L(Str('2'), Str('3')))))
示例#7
0
def test_parser_13():
    assert parse("""
        (cond (f "false") ((atom t) "true"))
    """) == (L(S('cond'), L(S('f'), Str("false")),
               L(L(S('atom'), T), Str('true'))))
示例#8
0
def test_parser_1():
    assert parse('(atom ())') == L(S('atom'), L())
示例#9
0
def test_parser_9():
    assert parse("(cons t '((atom ()) (atom t)))") == (L(
        S('cons'), T, L(S('quote'), L(L(S('atom'), L()), L(S('atom'), T)))))
示例#10
0
def test_parser_8():
    assert parse("(cons t '(t t))") == (L(S('cons'), T, L(S('quote'), L(T,
                                                                        T))))
示例#11
0
def test_parser_5():
    assert parse('()') == L()
示例#12
0
def test_parser_4():
    assert parse('((()) (() () ((()))) ())') == (L(L(L()),
                                                   L(L(), L(), L(L(L()))),
                                                   L()))
示例#13
0
def test_parser_3():
    assert parse('(quote () ((1 2)) (atom (t (t f))))') == (L(
        S('quote'), L(), L(L(I(1), I(2))),
        L(S('atom'), L(S('t'), L(S('t'), S('f'))))))
示例#14
0
def test_parser_2():
    assert parse('(atom (quote (t f t)))') == (L(
        S('atom'), L(S('quote'), L(S('t'), S('f'), S('t')))))
示例#15
0
def test_parser_10():
    assert parse("((()) (() () ((cons () '(() ())))) ())") == (L(
        L(L()), L(L(), L(), L(L(S('cons'), L(), L(S('quote'), L(F, F))))),
        L()))
示例#16
0
def test_eq():
    assert L(S('eq'), S('t'), S('t')).eval(env) == T
    assert L(S('eq'), S('t'), S('f')).eval(env) == F
    assert L(S('eq'), S('t'), L(S('quote'), S('f'))).eval(env) == F
示例#17
0
def test_parser_11():
    assert parse("'(t '(t '(() () ()) t))") == (L(
        S('quote'), L(T, L(S('quote'), L(T, L(S('quote'), L(F, F, F)), T)))))
示例#18
0
def test_cons():
    assert (
        L(S('cons'), S('t'), L(S('quote'), L(S('t'), S('f')))).eval(env)
    ) == (
        L(S('t'), S('t'), S('f'))
    )
示例#19
0
def test_parser_0():
    assert parse('(atom t)') == L(S('atom'), S('t'))