This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
/
070inline.test
108 lines (85 loc) · 3.86 KB
/
070inline.test
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(test "inline - pass through atoms"
:valueof (inline '(34) (table))
:should be '(34))
(test "inline - pass through unknown calls"
:valueof (inline '((baz 3 4)) (table))
:should be '((baz 3 4)))
(test "inline - replace with body"
:valueof (inline '((foo)) (table 'foo (fn() 34)))
:should be '(34))
(test "inline - with args"
:valueof (inline '((foo 3 4)) (table 'foo (fn(a b) (+ a b))))
:should be '((+ 3 4)))
(test "inline - flattens"
:valueof (let env (table 'foo (fn(a b) (bar a b) (bar a b))
'bar (fn(x y) (+ y x)))
(inline '((foo 3 4) (bar 3 4)) env))
:should be '((+ 4 3) (+ 4 3) (+ 4 3)))
(test "inline - multiple levels"
:valueof (let env (table 'foo (fn(a b) (bar a b))
'bar (fn(x y) (+ y x)))
(inline '((foo 3 4)) env))
:should be '((+ 4 3)))
(test "inline - pass through compiled functions"
:valueof (and compiled-fn?.cons
(inline '((cons 3 4)) globals.))
:should be '((cons 3 4)))
(test "inline - handles varargs params"
:valueof (inline '((foo 3 4)) (table 'foo (fn params params)))
:should be '((list 3 4)))
(test "inline - handles varargs params - 2"
:valueof (inline '((foo 3 4)) (table 'foo (fn params (let (x y) params (list x y)))))
:should be '((let (x y) (list 3 4) (list x y))))
(test "inline - handles varargs params - 3"
:valueof (inline '((foo a b)) (table 'foo (fn params (let (x y) params (list x y)))))
:should be '((let (x y) (list a b) (list x y))))
(test "inline - handles quoted varargs params"
:valueof (inline '((foo a b)) (table 'foo (fn 'params (let (x y) params (list x y)))))
:should be '((let (x y) (list a b) (list x y))))
(test "inline - handles rest params"
:valueof (inline '((foo 3 4)) (table 'foo (fn(a . b) (bar a b))))
:should be '((bar 3 (list 4))))
(test "inline - handles destructured params"
:valueof (inline '((foo (3 4) 5)) (table 'foo (fn((a b) . c) (bar a b c))))
:should be '((bar 3 4 (list 5))))
(test "inline - handles quoted params"
:valueof (inline '((foo 3)) (table 'foo (fn'(x) (+ x 1))))
:should be '((+ 3 1)))
(test "inline - handles lexical bindings"
:valueof (inline '((foo 3)) (table 'foo (let bar (fn(a) a) (fn(x) (bar x)))))
:should be '(3))
(test "inline - handles lexical bindings"
:valueof (inline '((foo 3)) (table 'foo (with (bar (fn(a) (baz a))
baz (fn(a) a))
(fn(x) (bar x)))))
:should be '(3))
(test "inline - handles lexical bindings to compiled functions"
:valueof (inline '((foo 3)) (table 'foo (with (bar (fn(a) (baz a))
baz cons)
(fn(x) (bar x)))))
:should be '((baz 3)))
(test "inline - handles fn exprs"
:valueof (inline '(((fn(a b) (+ a b)) 3 4)) (table))
:should be '((+ 3 4)))
(test "inline - handles macros"
:valueof (inline '((foo 3)) (table 'foo (with (bar (fn(a) (baz a))
baz (mfn(a) a))
(fn(x) (bar x)))))
:should be '(3))
(test "inline - handles quotes"
:valueof (inline '((foo 3)) (table 'foo (fn(a) (list 'a a))))
:should be '((list 'a 3)))
(test "inline - handles bindings to macros"
:valueof (inline '((foo 3)) (table 'foo (with (bar (fn(a) (baz a))
baz do)
(fn(x) (bar x)))))
:should be '(3))
(test "inline - handles compound macro bodies"
:valueof (inline '((foo 3)) (table 'foo (mfn'(x) (prn "a") `(+ ,x 1))))
:should be '((prn "a") (+ 3 1)))
(test "inline - handles compound macro bodies - 2"
:valueof (inline '((foo 3)) (table 'foo (mfn'(x) (let y 4 `(+ ,x y)))))
:should be '((let y 4 (+ 3 y))))
(test "inline - handles unquote-splice"
:valueof (inline '((foo 3)) (table 'foo (mfn 'body `(list ,@body))))
:should be '((list 3)))