Esempio n. 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']
Esempio n. 2
0
def test_read_unclosed_list():
    with raises(EOF):
        read("(")
Esempio n. 3
0
def test_read_special_form():
    assert read('def') == Symbol('def')
Esempio n. 4
0
def test_read_qualified_symbol():
    assert read('foo/bar') == Symbol('bar', 'foo')
Esempio n. 5
0
def test_read_unqualified_symbol():
    assert read('foo-bar') == Symbol('foo-bar', 'testing')
Esempio n. 6
0
def test_read_string_with_invalid_escape_sequence():
    with raises(InvalidEscapeSequence):
        read('"h\\ello"')
Esempio n. 7
0
def test_unbound_symbol_raises_error(evaluator):
    with raises(UnboundSymbol):
        evaluator.evaluate(read('foo'))
Esempio n. 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')
Esempio n. 9
0
def test_read_string():
    assert read('"hello"') == 'hello'
Esempio n. 10
0
def test_parse_invalid_lambda():
    with raises(ParseError):
        parse_lambda(read('(lambda ((3)))'))
Esempio n. 11
0
def test_parse_def():
    parsed = parse_def(read('(def foo 42)'))
    assert parsed.symbol.name == 'foo'
    assert parsed.value == 42
Esempio n. 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'), ))
Esempio n. 13
0
def test_parse_invalid_def():
    with raises(ParseError):
        parse_def(read('(def foo 42 bar)'))
Esempio n. 14
0
def test_python_literal(evaluator):
    assert evaluator.evaluate(read('py/Exception')) == Exception
Esempio n. 15
0
def test_read_unbalanced_delimiter():
    with raises(UnbalancedDelimiter):
        read(")")
Esempio n. 16
0
def test_read_unterminated_string():
    with raises(EOF):
        read('"hello')
Esempio n. 17
0
def test_read_empty_list():
    obj = read('()')
    assert isinstance(obj, List)
Esempio n. 18
0
def test_read_string_with_escaped_quotes():
    assert read('"\\"hello\\""') == '"hello"'
Esempio n. 19
0
def test_read_int():
    assert read('42') == 42
Esempio n. 20
0
def test_lambda_invocation_wrong_arity(evaluator):
    with raises(WrongArity):
        evaluator.evaluate(read('((lambda ()) 1)'))