예제 #1
0
def test_evaluate_single_expression():
    ast = parse(tokenize('(add 1 2)'))
    result = evl(ast, ctx)
    assert result == 3
예제 #2
0
def test_eval_set_variable_string():
    ast = parse(tokenize('(set user-name "evren")'))
    result = evl(ast, ctx)
    assert ctx['user-name'] == "evren"
예제 #3
0
def test_eval_set_variable_number():
    ast = parse(tokenize('(set user-id 1546)'))
    result = evl(ast, ctx)
    assert ctx['user-id'] == 1546
예제 #4
0
def test_eval_list():
    ast = parse(tokenize("'(1 2 3)"))
    result = evl(ast, ctx)
    assert result == [1, 2, 3]
예제 #5
0
def test_eval_list_functions():
    ast = parse(tokenize("(avg '(1 2 3))"))
    result = evl(ast, ctx)
    assert result == 2.0
예제 #6
0
def test_if_false():
    ast = parse(tokenize('(if (= 5 1) TRUE FALSE)'))
    result = evl(ast, ctx)
    assert result == 'FALSE'
예제 #7
0
def test_if_true():
    ast = parse(tokenize('(if (= 1 1) TRUE FALSE)'))
    result = evl(ast, ctx)
    assert result == 'TRUE'
예제 #8
0
def test_define_function_in_local_scope():
    ast = parse(tokenize('(defun double (params x) (mul x 2))'))
    context = {}
    result = evl(ast, context)
    assert 'double' in context
예제 #9
0
def test_evaluate_list_of_expressions_return_last_one():
    ast = parse(tokenize('(add 1 2) (mul 9 8)'))
    result = evl(ast, ctx)
    assert result == 72
예제 #10
0
파일: runner.py 프로젝트: yortuc/lispip
def run(expr, context=ctx):
    return evl(parse(tokenize(expr)), context)