/
syntax_spec.ik
209 lines (170 loc) · 4.74 KB
/
syntax_spec.ik
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
use("ispec")
describe(DefaultBehavior,
describe("syntax",
it("should name itself after the slot it's assigned to if it has no name",
x = syntax(nil)
cell(:x) name should == "x"
)
it("should not change it's name if it already has a name",
x = syntax(nil)
y = cell(:x)
cell(:y) name should == "x"
)
it("should know it's own name",
(x = syntax(nil)) name should == "x"
)
)
)
describe("DefaultSyntax",
it("should just remove itself if nil is returned",
Ground syntaxTest = []
ss = syntax(syntaxTest << :called. nil)
3 times(syntaxTest << :times1. ss. syntaxTest << :times2.)
syntaxTest should == [:times1, :called, :times2, :times1, :times2, :times1, :times2]
)
it("should work at the beginning of a message chain",
ss = syntax(Message from(1+1))
block = fn(ss * 2)
block call should == 4
block call should == 4
)
it("should work at the end of a message chain",
ss = syntax(Message from(1+1))
block = fn(nil. ss)
block call should == 2
block call should == 2
)
it("should work as a regular argument",
Ground syntaxTest = []
ss = syntax(syntaxTest << :called. Message from(1+1))
mm = method(arg, arg)
block = fn(mm(ss))
block call should == 2
block call should == 2
syntaxTest should == [:called]
)
it("should be possible to give it a documentation string",
syntax("foo is bar", nil) documentation should == "foo is bar"
)
it("should signal a condition if activating the kind",
fn(DefaultSyntax) should signal(Condition Error Invocation NotActivatable)
)
it("should have @ return the receiving object inside of a macro",
Ground syntaxTest = []
obj = Origin mimic
obj atSign = syntax(syntaxTest << @. nil)
obj2 = obj mimic
obj atSign
obj2 atSign
syntaxTest should == [obj, obj2]
)
it("should have @@ return the executing syntax inside of a syntax",
Ground syntaxTest = []
obj = Origin mimic
obj atAtSign = syntax(syntaxTest << @@. nil)
obj2 = obj mimic
obj atAtSign
obj2 atAtSign
syntaxTest should == [obj cell(:atAtSign), obj2 cell(:atAtSign)]
)
it("should have 'self' return the receiving object inside of a macro",
Ground syntaxTest = []
obj = Origin mimic
obj atSign = syntax(syntaxTest << self. nil)
obj2 = obj mimic
obj atSign
obj2 atSign
syntaxTest should == [obj, obj2]
)
it("should have 'call' defined inside the call to the macro",
Ground syntaxTest = []
syntax(syntaxTest << call. nil) call
syntaxTest[0] should have kind("Call")
)
it("should not evaluate it's arguments by default",
x=42
syntax(nil) call(x=13)
x should == 42
)
it("should take any kinds of arguments",
x = syntax(nil)
x(13, 42, foo: 42*13)
)
it("should be possible to return from it prematurely, with return",
Ground x_syntax_spec = 42
m = syntax(if(true, return(nil)). Ground x_syntax_spec = 24)
m()
x_syntax_spec should == 42
)
it("should return even from inside of a lexical block",
Ground x_syntax_spec = 42
Ground x = method(block, block call)
m = syntax(
Ground x(fn(Ground x_syntax_spec = 43. return(nil)))
Ground x_syntax_spec = 44. nil)
m()
x_syntax_spec should == 43
)
it("executes in the right scope the first time",
f = Origin mimic
f synt = syntax('x)
f x = "outer"
f meth = method(
x = "inner"
self synt
)
f meth should == "outer"
f meth should == "outer"
)
it("executes in the right scope the first time for local variables",
f = Origin mimic
f synt = syntax('x)
f x = "outer"
f meth = method(
x = "inner"
synt
)
f meth should == "inner"
f meth should == "inner"
)
describe("name",
it("should validate type of receiver",
syntax should checkReceiverTypeOn(:name)
)
)
describe("expand",
it("should validate type of receiver",
syntax should checkReceiverTypeOn(:expand)
)
)
describe("message",
it("should validate type of receiver",
syntax should checkReceiverTypeOn(:message)
)
)
describe("argumentsCode",
it("should validate type of receiver",
syntax should checkReceiverTypeOn(:argumentsCode)
)
)
describe("inspect",
it("should validate type of receiver",
syntax should checkReceiverTypeOn(:inspect)
)
)
describe("notice",
it("should validate type of receiver",
syntax should checkReceiverTypeOn(:notice)
)
)
describe("code",
it("should validate type of receiver",
syntax should checkReceiverTypeOn(:code)
)
)
describe("formattedCode",
it("should validate type of receiver",
syntax should checkReceiverTypeOn(:formattedCode)
)
)
)