예제 #1
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_quasiquote():
    assert lsp("`(+ 1 2)") == lsp("'(+ 1 2)")

    loc = Env({'x': 2}, parent=top)
    assert lsp("(eval `(+ 1 ~x))", env=loc) == 3

    loc = Env({'x': [3, 4]}, parent=top)
    assert lsp("`(+ 1 2 ~@x)", env=loc) == read("(+ 1 2 3 4)")
예제 #2
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_fn():
    assert lsp('((fn () 1))') == 1
    assert lsp('((fn (x) x) 1)') == 1
    assert lsp('((fn (x) (+ x 1)) 1)') == 2

    assert read('(fn (x & xs) xs)') == \
        List(['fn', List(['x', '&', 'xs']), 'xs'])
    assert lsp('((fn (x & xs) xs) 1 2 3 4)') == List([2, 3, 4])
예제 #3
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_fact():
    fact = '''
(fn fact (x)
  (if (<= x 1)
    1
    (* x (fact (- x 1)))))
'''
    assert lsp('({0} 5)'.format(fact)) == 120
예제 #4
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_if():
    assert lsp('(if 1 2 3)') == 2
    assert lsp('(if 0 2 3)') == 2
    assert lsp('(if true 2 3)') == 2
    assert lsp('(if false 2 3)') == 3
    assert lsp('(if nil 2 3)') == 3
    assert lsp('(if (list) 2 3)') == 2
예제 #5
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_quote():
    assert lsp('(quote (+))') == List(['+'])
    assert lsp("'(+)") == List(['+'])

    assert lsp('(quote (1 2))') == List([1, 2])
    assert lsp("'(1 2)") == List([1, 2])

    assert lsp("'((1 2))") == List([List([1, 2])])
    assert lsp("'((1 2) (1 2))") == List([List([1, 2]), List([1, 2])])
예제 #6
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_gt():
    with raises(TypeError):
        lsp('(>)')
        lsp('(> 1)')
        lsp('(>=)')
        lsp('(>= 1)')

    assert lsp('(> 1 2)') == False
    assert lsp('(> 2 1)') == True
    assert lsp('(> 2 2)') == False

    assert lsp('(>= 1 2)') == False
    assert lsp('(>= 2 1)') == True
    assert lsp('(>= 2 2)') == True
예제 #7
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_def():
    lsp('(def a 1)')
    assert lsp('a') == 1
예제 #8
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_range():
    assert lsp("(range 1 5)") == List([1, 2, 3, 4])
    assert lsp("(range 1 5 2)") == List([1, 3])
예제 #9
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_comp():
    assert lsp("((comp inc inc) 2)") == 4
예제 #10
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_let():
    assert lsp("(let (a 2, b 3) (+ a b))") == 5
예제 #11
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_reduce():
    assert lsp("(reduce + 0 '(1 2 3))") == 6
예제 #12
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_plus():
    assert lsp('(+)') == 0
    assert lsp('(+ 1)') == 1
    assert lsp('(+ 1 2 3)') == 6
예제 #13
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_defmacro():
    lsp('(defmacro foo (x) x)')
    assert lsp('(foo 1)') == lsp('1')

    lsp('(defmacro foo (x) (quote x))')
    with raises(RuntimeError):
        assert lsp('(foo (+ 1 2))') == lsp('(quote (+ 1 2))')

    lsp('(defmacro foo (x) `(+ 1 ~x))')
    assert lsp('(foo 2)') == 3

    lsp('(defmacro foo (x) `(+ 1 ~@x))')
    assert lsp('(foo (2 3))') == 6
예제 #14
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_defn():
    lsp('(def f (fn () 1))')
    assert lsp('(f)') == 1
예제 #15
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_call_method():
    assert lsp("(. 1 __str__)") == "1"
    assert lsp("(. 1 __add__ 2)") == 3
예제 #16
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_list_slicing():
    assert lsp("('(1 2 3) 0)") == 1
    assert lsp("(first '(1 2 3))") == 1
    assert lsp("(rest '(1 2 3))") == List([2, 3])
예제 #17
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_minus():
    with raises(TypeError):
        assert lsp('(-)')

    assert lsp('(- 1)') == -1
    assert lsp('(- 1 2)') == -1
예제 #18
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_map():
    assert lsp("(map inc '(1 2 3))") == List([2, 3, 4])
예제 #19
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_multiply():
    assert lsp('(*)') == 1
    assert lsp('(* 2)') == 2
    assert lsp('(* 1 2 3)') == 6
예제 #20
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_filter():
    assert lsp("(filter (fn (x) (> x 2)) '(1 2 3 4))") == List([3, 4])
예제 #21
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_divide():
    assert lsp('(/ 10 5)') == 2
    assert lsp('(/ 10 5 3)') == lsp('(/ (/ 10 5) 3)')
    assert lsp('(/ 5 1/2)')
예제 #22
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_partial():
    assert lsp("((partial + 2) 2)") == 4
예제 #23
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_eq():
    assert lsp('(= 1 1)') == True
    assert lsp('(= 1 2)') == False
    assert lsp("(= (quote (1 2)) (quote (3 4)))") == False
    assert lsp("(= '(1 2) '(1 2))") == True
    assert lsp("(= '(1 2) '(3 4))") == False
예제 #24
0
import lsp
print(lsp.lsp())
예제 #25
0
파일: test_lsp.py 프로젝트: lucian1900/lsp
def test_lt():
    with raises(TypeError):
        lsp('(<)')
        lsp('(< 1)')
        lsp('(<=)')
        lsp('(<= 1)')

    assert lsp('(< 1 2)') == True
    assert lsp('(< 2 1)') == False
    assert lsp('(< 2 2)') == False

    assert lsp('(<= 1 2)') == True
    assert lsp('(<= 2 1)') == False
    assert lsp('(<= 2 2)') == True