-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.scss
170 lines (150 loc) · 3.53 KB
/
tests.scss
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright (C) 2016 Colin Fulton
// All rights reserved.
//
// This software may be modified and distributed under the
// terms of the three-clause BSD license. See LICENSE.txt
@import 'sassy_lisp';
Quote {
Assert: function_eval((q one two three));
Expect: one two three;
}
Single Line {
Assert: function_eval(q one two three);
Expect: one two three;
}
Multi Line {
Assert: function_eval(
(q one)
(q two)
);
Expect: two;
}
Cons {
Assert: function_eval(cons one (q two));
Expect: one two;
}
Math {
Assert: function_eval((add 0.25 (multiply 4 (multiply 5 2)) 1.75));
Expect: 42;
}
Booleans {
Assert: function_eval((bool_and 7 (bool_or (bool_and 9 (bool_not true)) 12)));
Expect: 12;
}
Globals {
Assert: function_eval(
(global two 2)
(add (add two 1) 1)
);
Expect: 4;
}
Lambdas As Named Functions {
Assert: function_eval(
(global add_two (lambda (value) (
(add 2 value)
)))
(add_two 3)
);
Expect: 5;
}
Calling Named Functions From Named Functions {
Assert: function_eval(
(global add_one (lambda (value) (
(add value 1)
)))
(global add_two (lambda (value) (
(add_one (add_one value)
))))
(add_two 1)
);
Expect: 3;
}
Lambdas As Arguments {
Assert: function_eval(
(global call_with_4 (lambda (func) (
(func 4)
)))
(call_with_4 (lambda (value) (
(add value 1)
)))
);
Expect: 5;
}
Parameters Take Precedence Over Globals {
Assert: function_eval(
(global value 999)
(global add_one (lambda (value) (
(add value 1)
)))
(add_one 1)
);
Expect: 2;
}
Locals Do Not Leak Out {
Assert: function_eval(
(global add_one (lambda (value) (
(local one 1)
(add value one)
)))
(add_one one)
);
Expect: one1;
}
Locals Are Captured When Lambda Is Created {
Assert: function_eval(
(local thing 1)
(global add_thing (lambda (value) (
(add value thing)
)))
(local thing 2)
(global add_another_thing (lambda (value) (
(add value thing)
)))
(add_thing (add_another_thing 3))
);
Expect: 6;
}
Lambdas Can Be Recursive {
Assert: function_eval(
(global fib (lambda (value) (
(cond
((less_than value 2) (identity value))
(else
(add
(fib (subtract value 1))
(fib (subtract value 2))
)
)
)
)))
(fib 6)
);
Expect: 8;
}
Conditionals {
Assert: function_eval(
(q
(cond
((equal 7 7) (identity yup))
((equal 1 2) (identity nope))
)
(cond
((greater_than 1 2) (identity nope))
((less_than 1 2) (identity yup))
)
(cond
((equal two 2) (identity nope))
(else (identity yup))
)
)
);
Expect: yup yup yup;
}
Conditionals Return null If Nothing Evaluates {
Assert: function_eval(
(inspect
(cond ((equal 1 2) (q nope)))
)
);
Expect: null;
}