-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.p8p
71 lines (69 loc) · 3.25 KB
/
tests.p8p
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(lisp_assert "(+ 1E1 2)" 12)
(lisp_assert "'pass'" "pass")
(lisp_assert "{0 'foo' 1 'bar'}" ['foo' 'bar'])
(lisp_assert "(aget {'foo' 'bar'} 'foo')" 'bar')
(lisp_assert "(if (== (eval (unquote '(+ 1 2))) 3) 'pass' 'fail')" "pass")
(lisp_assert "(let [a '(1 2)] `(~a ~@a))" '('(1 2) 1 2))
(lisp_assert "(|| 1)" 1)
(lisp_assert "(|| 1 (throw (new Exception 'fail')))" 1)
(lisp_assert "(|| false 1)" 1)
(lisp_assert "(|| false false 0)" 0)
(lisp_assert "(&& false)" false)
(lisp_assert "(&& 1)" 1)
(lisp_assert "(&& 1 false (throw (new Exception 'fail')))" false)
(lisp_assert "(&& null 1)" false)
(lisp_assert "(&& false null 0)" false)
(lisp_assert "(&& 1 2 3)" 3)
(lisp_assert "(&& 1 null 3)" false)
(lisp_assert "(is_string '1')" true)
(lisp_assert "(empty? [])" true)
(lisp_assert "(empty? [ 1 ])" false)
(lisp_assert "(is_array [])" true)
(lisp_assert "(is_array '())" false)
(lisp_assert "(array 1 2 3)" [1 2 3])
(lisp_assert "(- 3 1)" 2)
(lisp_assert "(do (+ 1 1) (+ 1 2))" 3)
(lisp_assert "(drop 2 [1 2 3 4])" [3 4])
(lisp_assert "(assoc [ 1 2 3] 2 4)" [1 2 4])
(lisp_assert "(. 'pa' 'ss')" "pass")
(lisp_assert "(let [a 1] (set! a 2) a)" 2)
(lisp_assert "(map (function (v) (+ v 1)) [1 2 3])" [2 3 4])
(lisp_assert "(last (array 1 2 3))" 3)
(lisp_assert "(try (throw (new Exception 'pass'))
catch Exception e (->getMessage e))" "pass")
(lisp_assert "(try (try (throw (new Exception 'fail'))
finally (throw (new Exception 'pass')))
catch Exception f (->getMessage f))"
"pass")
(lisp_assert "(filter #(mod % 2) [1 2 3 4])" [1 3])
(lisp_assert "(unless false 'pass' 'fail')" "pass")
(lisp_assert "(if-let [a false] 'fail' 'pass')" "pass")
(lisp_assert "(if-let [a 'pass'] a)" "pass")
(lisp_assert "(rest [1 2 3])" [2 3])
(lisp_assert "(last [1 2 3])" 3)
(lisp_assert "(let [a 1 b (array 2 3)] `(+ a 0 ~a ~@b))" '(+ a 0 1 2 3))
(lisp_assert "(#(aget % 1) [1 2 3])" 2)
(lisp_assert "(#(+ %0 %1) 3 4)" 7)
(lisp_assert "(let [a 1] (let [b 2] (#(+ a b))))" 3)
(lisp_assert "(let [fn ''] (let [a 1] (set! fn #(set! a (+ a 2)))) (fn) (fn))" 5)
(lisp_assert "(let [a 1 inc_a #(set! a (+ a 1))] (inc_a) (inc_a))" 3)
(lisp_assert "(let [a [0 0 0]] (aset! (aset! (aset! a 0 3) 1 2) 2 1))" [3 2 1])
(lisp_assert "(let [a [0 [1] [[2]]]] (aset! a 2 0 0 (+ 1 (aget a 2 0 0))))" [0 [1] [[3]]])
(lisp_assert "(let [a []] (aset! a 0 1) a)" [1])
(lisp_assert "(if-null (+ 1 1) (throw (new Exception 'fail')))" 2)
(lisp_assert "(if-null null (+ 1 1))" 2)
(lisp_assert "(TestClass::a_static_var)" "Hi Static")
(lisp_assert "(TestClass::a_static_function)" "A static func")
(lisp_assert "(->a_regular_var (new TestClass))" "Hi Regular")
(lisp_assert "(let [a (new TestClass)] (set! ->a_regular_var a 'pass') (->a_regular_var a))" "pass")
(lisp_assert "(->a_regular_function (new TestClass) 'foo')" "Passed foo")
(lisp_assert "(->a_static_var (new TestClass))" "Hi Static")
(lisp_assert "(TestClass::a_constant)" "Hi const")
(lisp_assert "(add_one)" 2)
(lisp_assert "(add_one 2)" 3)
(lisp_assert "((function [a (b 2) (c 3)] (+ a b c)) 1)" 6)
(lisp_assert "(let [[a b & c] [1 2 3] d (+ 1 (first c))] (+ a b d))" 7)
(lisp_assert "(if-null (next []) 'pass')" 'pass')
(lisp_assert "(reduce + [1 2 3])" 6)
(lisp_assert "(reduce + 1 [2 3])" 6)
(lisp_assert "(partition 2 [1 2 3 4 5])" [[1 2][3 4]])