示例#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)