Пример #1
0
def test_parse_params(s, expectations):
    parsed = parse_params(read(s))
    assert tuple(sym.name
                 for sym in parsed.required) == expectations['required']
    assert tuple(sym.name
                 for sym in parsed.optional) == expectations['optional']
    if expectations['rest'] is None:
        assert parsed.rest is None
    else:
        assert parsed.rest.name == expectations['rest']
Пример #2
0
def test_read_unclosed_list():
    with raises(EOF):
        read("(")
Пример #3
0
def test_read_special_form():
    assert read('def') == Symbol('def')
Пример #4
0
def test_read_qualified_symbol():
    assert read('foo/bar') == Symbol('bar', 'foo')
Пример #5
0
def test_read_unqualified_symbol():
    assert read('foo-bar') == Symbol('foo-bar', 'testing')
Пример #6
0
def test_read_string_with_invalid_escape_sequence():
    with raises(InvalidEscapeSequence):
        read('"h\\ello"')
Пример #7
0
def test_unbound_symbol_raises_error(evaluator):
    with raises(UnboundSymbol):
        evaluator.evaluate(read('foo'))
Пример #8
0
def test_read_list():
    obj = read('(foo 42 bar)')
    assert isinstance(obj, List)
    assert obj[0] == Symbol('foo', 'testing')
    assert obj[1] == 42
    assert obj[2] == Symbol('bar', 'testing')
Пример #9
0
def test_read_string():
    assert read('"hello"') == 'hello'
Пример #10
0
def test_parse_invalid_lambda():
    with raises(ParseError):
        parse_lambda(read('(lambda ((3)))'))
Пример #11
0
def test_parse_def():
    parsed = parse_def(read('(def foo 42)'))
    assert parsed.symbol.name == 'foo'
    assert parsed.value == 42
Пример #12
0
def test_parse_lambda():
    parsed = parse_lambda(read('(lambda (foo) bar)'))
    assert isinstance(parsed, Lambda)
    assert isinstance(parsed.params, Params)
    assert tuple(parsed.body) == ((Symbol('bar', 'testing'), ))
Пример #13
0
def test_parse_invalid_def():
    with raises(ParseError):
        parse_def(read('(def foo 42 bar)'))
Пример #14
0
def test_python_literal(evaluator):
    assert evaluator.evaluate(read('py/Exception')) == Exception
Пример #15
0
def test_read_unbalanced_delimiter():
    with raises(UnbalancedDelimiter):
        read(")")
Пример #16
0
def test_read_unterminated_string():
    with raises(EOF):
        read('"hello')
Пример #17
0
def test_read_empty_list():
    obj = read('()')
    assert isinstance(obj, List)
Пример #18
0
def test_read_string_with_escaped_quotes():
    assert read('"\\"hello\\""') == '"hello"'
Пример #19
0
def test_read_int():
    assert read('42') == 42
Пример #20
0
def test_lambda_invocation_wrong_arity(evaluator):
    with raises(WrongArity):
        evaluator.evaluate(read('((lambda ()) 1)'))