예제 #1
0
def test_error():
    list = e.intern('list')

    error = e.intern('error')
    msg = e.str('An error message')
    with pytest.raises(e.Signal) as ex:
        error(msg)
    sym, data = ex.value.args
    assert e.eq(sym, e.intern('error'))
    assert e.equal(data, list(msg))

    throw = e.intern('throw')
    tag = e.intern('tag')
    value = e.int(1)
    with pytest.raises(e.Throw) as ex:
        throw(tag, value)
    sym, data = ex.value.args
    assert e.eq(sym, e.intern('tag'))
    assert e.equal_sign(data, value)

    def err():
        error = e.intern('error')
        list = e.intern('list')
        raise e.Signal(error, list(e.str('message')))

    func = e.function(err, 0, 0)
    with pytest.raises(e.Signal) as ex:
        func()
    sym, data = ex.value.args
    assert e.eq(sym, e.intern('error'))
    assert e.equal(data, list(e.str('message')))
예제 #2
0
def test_length():
    a = e.intern('a')
    b = e.intern('b')
    c = e.intern('c')

    assert len(e.list([a, b, c])) == 3
    assert len(e.vector([a, b])) == 2
    assert len(e.str('alpha')) == 5
    assert len(e.intern('nil')) == 0

    with pytest.raises(TypeError):
        len(e.cons(a, b))
예제 #3
0
def test_string():
    alpha = e.str('alpha')
    assert e.string_equal(alpha, e.str('alpha'))
    assert repr(alpha) == '"alpha"'
    assert str(alpha) == 'alpha'
    with pytest.raises(ValueError):
        int(alpha)
    with pytest.raises(ValueError):
        float(alpha)
    assert alpha.type() == 'string'
    assert alpha.is_a('string')
    assert not e.integerp(alpha)
    assert not e.floatp(alpha)
    assert e.stringp(alpha)
    assert not e.symbolp(alpha)
    assert not e.consp(alpha)
    assert not e.vectorp(alpha)
    assert not e.listp(alpha)
    assert not e.functionp(alpha)
    assert alpha

    assert str(e.str(2)) == '2'
    assert str(e.str(1.1)) == '1.1'

    s_one = e.str('1')
    i_one = int(s_one)
    assert i_one == 1

    s_two = e.str('2.2')
    f_two = float(s_two)
    assert f_two == 2.2
예제 #4
0
def test_num():
    assert e.int(0) + e.int(1) == 1
    assert e.int(3) + 8 == 11
    assert 7 + e.float(-3.1) == 3.9
    assert 'alpha' + e.str('bravo') == 'alphabravo'

    assert e.int(8) - e.int(1) == 7
    assert 13 - e.float(2.2) == 10.8

    assert e.int(5) * e.float(2.2) == 11.0
    assert 7 * e.int(2) == 14

    assert e.int(17) // 3 == 5
    assert 7 / e.int(2) == 3.5
    assert e.int(8) / e.int(-1) == -8.0

    assert divmod(e.int(10), e.int(3)) == (3, 1)

    assert 2**e.int(3) == 8
    assert e.float(3.0)**e.int(3) == 27.0
    assert pow(e.int(2), e.int(4), e.int(5)) == 1

    assert -e.int(2) == -2
    assert -e.float(-2.2) == 2.2

    assert +e.int(-2) == -2
    assert ~e.int(1) == ~1

    assert (e.int(8) << 1) == 16
    assert 8 >> e.int(1) == 4

    with pytest.raises(TypeError):
        13 - e.str('a')
    with pytest.raises(TypeError):
        e.intern('a') + 2
    with pytest.raises(TypeError):
        2 << e.intern('b')
    with pytest.raises(TypeError):
        pow(1, 2, e.intern('q'))
예제 #5
0
def test_function():
    def a():
        return e.int(1)

    func = e.function(a, 0, 0)
    assert e.functionp(func)
    ret = func()
    assert e.eq(ret, e.int(1))

    def b():
        return e.str('alpha')

    func = e.function(b)
    assert e.functionp(func)
    ret = func()
    assert e.string_equal(ret, e.str('alpha'))
예제 #6
0
 def err():
     error = e.intern('error')
     list = e.intern('list')
     raise e.Signal(error, list(e.str('message')))
예제 #7
0
def test_compare():
    assert e.int(0) == e.int(0)
    assert e.int(0) != e.int(1)
    assert e.int(0) < e.int(1)
    assert not e.int(1) <= e.int(0)

    assert e.int(0) == 0
    assert 0 == e.int(0)
    assert 1 < e.int(2)

    assert e.float(9.1) >= 9.1
    assert e.float(8) == 8
    assert 0 == e.float(0.0)

    assert 'a' == e.str('a')
    assert e.str('abc') < 'abd'
    assert 'q' != e.str('Q')

    assert not e.str('a') == []
    assert e.str('a') != []

    with pytest.raises(TypeError):
        e.str('a') < 1
    with pytest.raises(TypeError):
        e.str('a') > []
    with pytest.raises(TypeError):
        e.str('a') >= ()
예제 #8
0
 def b():
     return e.str('alpha')