28 | 28 |
assert.has.error -> const!\match { num }
|
29 | 29 |
assert.has.error -> evt!\match { str }
|
30 | 30 |
assert.has.error -> evt!\match { num }
|
|
31 |
assert.is.equal str, any!\match { str }
|
|
32 |
assert.is.equal num, any!\match { num }
|
31 | 33 |
|
32 | 34 |
str = mk_evt 'str'
|
33 | 35 |
num = mk_evt 'num'
|
|
37 | 39 |
assert.has.error -> const!\match { num }
|
38 | 40 |
assert.is.equal str, evt!\match { str }
|
39 | 41 |
assert.is.equal num, evt!\match { num }
|
|
42 |
assert.is.equal str, any!\match { str }
|
|
43 |
assert.is.equal num, any!\match { num }
|
|
44 |
assert.is.equal str, any!\match { str }
|
|
45 |
assert.is.equal num, any!\match { num }
|
40 | 46 |
|
41 | 47 |
str = mk_const 'str'
|
42 | 48 |
num = mk_const 'num'
|
|
46 | 52 |
assert.is.equal num, const!\match { num }
|
47 | 53 |
assert.has.error -> evt!\match { str }
|
48 | 54 |
assert.has.error -> evt!\match { num }
|
|
55 |
assert.is.equal str, any!\match { str }
|
|
56 |
assert.is.equal num, any!\match { num }
|
|
57 |
assert.is.equal str, any!\match { str }
|
|
58 |
assert.is.equal num, any!\match { num }
|
49 | 59 |
|
50 | 60 |
it 'can recall the type', ->
|
51 | 61 |
value = sig!!
|
52 | 62 |
event = evt!!
|
|
63 |
thing = any!!
|
53 | 64 |
two_equal_values = value + value
|
54 | 65 |
two_equal_events = event + event
|
|
66 |
two_equal_things = thing + thing
|
55 | 67 |
|
56 | 68 |
str1 = mk_val 'str'
|
57 | 69 |
str2 = mk_val 'str'
|
|
59 | 71 |
assert.is.same { str1, str2 }, two_equal_values\match { str1, str2 }
|
60 | 72 |
assert.is.same { str2, str1 }, two_equal_values\match { str2, str1 }
|
61 | 73 |
assert.is.same { num, num }, two_equal_values\match { num, num }
|
|
74 |
assert.is.same { str1, str2 }, two_equal_things\match { str1, str2 }
|
|
75 |
assert.is.same { str2, str1 }, two_equal_things\match { str2, str1 }
|
|
76 |
assert.is.same { num, num }, two_equal_things\match { num, num }
|
62 | 77 |
assert.has.error -> two_equal_values\match { str1, num }
|
63 | 78 |
assert.has.error -> two_equal_values\match { num, str2 }
|
|
79 |
assert.has.error -> two_equal_things\match { str1, num }
|
|
80 |
assert.has.error -> two_equal_things\match { num, str2 }
|
64 | 81 |
assert.has.error -> two_equal_events\match { str1, str2 }
|
65 | 82 |
|
66 | 83 |
str1 = mk_evt 'str'
|
|
69 | 86 |
assert.is.same { str1, str2 }, two_equal_events\match { str1, str2 }
|
70 | 87 |
assert.is.same { str2, str1 }, two_equal_events\match { str2, str1 }
|
71 | 88 |
assert.is.same { num, num }, two_equal_events\match { num, num }
|
|
89 |
assert.is.same { str1, str2 }, two_equal_things\match { str1, str2 }
|
|
90 |
assert.is.same { str2, str1 }, two_equal_things\match { str2, str1 }
|
|
91 |
assert.is.same { num, num }, two_equal_things\match { num, num }
|
72 | 92 |
assert.has.error -> two_equal_events\match { str1, num }
|
73 | 93 |
assert.has.error -> two_equal_events\match { num, str2 }
|
|
94 |
assert.has.error -> two_equal_things\match { str1, num }
|
|
95 |
assert.has.error -> two_equal_things\match { num, str2 }
|
74 | 96 |
assert.has.error -> two_equal_values\match { str1, str2 }
|
75 | 97 |
|
76 | 98 |
it 'stringifies well', ->
|
77 | 99 |
assert.is.equal 'any=', tostring const!
|
78 | 100 |
assert.is.equal 'any!', tostring evt!
|
79 | 101 |
assert.is.equal 'any~', tostring sig!
|
|
102 |
assert.is.equal 'any', tostring any!
|
80 | 103 |
|
81 | 104 |
describe 'typed shorthand', ->
|
82 | 105 |
it 'matches by metatype', ->
|
|
88 | 111 |
assert.has.error -> const.num\match { num }
|
89 | 112 |
assert.has.error -> evt.str\match { str }
|
90 | 113 |
assert.has.error -> evt.num\match { num }
|
|
114 |
assert.is.equal str, any.str\match { str }
|
|
115 |
assert.is.equal num, any.num\match { num }
|
91 | 116 |
|
92 | 117 |
str = mk_evt 'str'
|
93 | 118 |
num = mk_evt 'num'
|
|
97 | 122 |
assert.has.error -> const.num\match { num }
|
98 | 123 |
assert.is.equal str, evt.str\match { str }
|
99 | 124 |
assert.is.equal num, evt.num\match { num }
|
|
125 |
assert.is.equal str, any.str\match { str }
|
|
126 |
assert.is.equal num, any.num\match { num }
|
100 | 127 |
|
101 | 128 |
str = mk_const 'str'
|
102 | 129 |
num = mk_const 'num'
|
|
106 | 133 |
assert.is.equal num, const.num\match { num }
|
107 | 134 |
assert.has.error -> evt.str\match { str }
|
108 | 135 |
assert.has.error -> evt.num\match { num }
|
|
136 |
assert.is.equal str, any.str\match { str }
|
|
137 |
assert.is.equal num, any.num\match { num }
|
109 | 138 |
|
110 | 139 |
it 'matches by type', ->
|
111 | 140 |
str = mk_const 'str'
|
|
142 | 171 |
assert.is.equal 'num~', tostring sig.num
|
143 | 172 |
assert.is.equal 'str=', tostring const.str
|
144 | 173 |
assert.is.equal 'num=', tostring const.num
|
|
174 |
|
|
175 |
describe 'predicate shorthand', ->
|
|
176 |
sig_str = sig ((typ) -> typ == T.str), "str"
|
|
177 |
sig_num = sig ((typ) -> typ == T.num), "num"
|
|
178 |
const_str = const ((typ) -> typ == T.str), "str"
|
|
179 |
const_num = const ((typ) -> typ == T.num), "num"
|
|
180 |
evt_str = evt ((typ) -> typ == T.str), "str"
|
|
181 |
evt_num = evt ((typ) -> typ == T.num), "num"
|
|
182 |
any_str = any ((typ) -> typ == T.str), "str"
|
|
183 |
any_num = any ((typ) -> typ == T.num), "num"
|
|
184 |
|
|
185 |
it 'matches by metatype', ->
|
|
186 |
str = mk_val 'str'
|
|
187 |
num = mk_val 'num'
|
|
188 |
assert.is.equal str, sig_str\match { str }
|
|
189 |
assert.is.equal num, sig_num\match { num }
|
|
190 |
assert.has.error -> const_str\match { str }
|
|
191 |
assert.has.error -> const_num\match { num }
|
|
192 |
assert.has.error -> evt_str\match { str }
|
|
193 |
assert.has.error -> evt_num\match { num }
|
|
194 |
assert.is.equal str, any_str\match { str }
|
|
195 |
assert.is.equal num, any_num\match { num }
|
|
196 |
|
|
197 |
str = mk_evt 'str'
|
|
198 |
num = mk_evt 'num'
|
|
199 |
assert.has.error -> sig_str\match { str }
|
|
200 |
assert.has.error -> sig_num\match { num }
|
|
201 |
assert.has.error -> const_str\match { str }
|
|
202 |
assert.has.error -> const_num\match { num }
|
|
203 |
assert.is.equal str, evt_str\match { str }
|
|
204 |
assert.is.equal num, evt_num\match { num }
|
|
205 |
assert.is.equal str, any_str\match { str }
|
|
206 |
assert.is.equal num, any_num\match { num }
|
|
207 |
|
|
208 |
str = mk_const 'str'
|
|
209 |
num = mk_const 'num'
|
|
210 |
assert.is.equal str, sig_str\match { str }
|
|
211 |
assert.is.equal num, sig_num\match { num }
|
|
212 |
assert.is.equal str, const_str\match { str }
|
|
213 |
assert.is.equal num, const_num\match { num }
|
|
214 |
assert.has.error -> evt_str\match { str }
|
|
215 |
assert.has.error -> evt_num\match { num }
|
|
216 |
assert.is.equal str, any_str\match { str }
|
|
217 |
assert.is.equal num, any_num\match { num }
|
|
218 |
|
|
219 |
it 'matches by type', ->
|
|
220 |
str = mk_const 'str'
|
|
221 |
num = mk_const 'num'
|
|
222 |
assert.is.equal str, sig_str\match { str }
|
|
223 |
assert.is.equal num, sig_num\match { num }
|
|
224 |
assert.is.equal str, const_str\match { str }
|
|
225 |
assert.is.equal num, const_num\match { num }
|
|
226 |
assert.is.equal str, any_str\match { str }
|
|
227 |
assert.is.equal num, any_num\match { num }
|
|
228 |
assert.has.error -> sig_num\match { str }
|
|
229 |
assert.has.error -> sig_str\match { num }
|
|
230 |
|
|
231 |
str = mk_val 'str'
|
|
232 |
num = mk_val 'num'
|
|
233 |
assert.is.equal str, sig_str\match { str }
|
|
234 |
assert.is.equal num, sig_num\match { num }
|
|
235 |
assert.has.error -> const_num\match { str }
|
|
236 |
assert.has.error -> const_str\match { num }
|
|
237 |
assert.has.error -> sig_num\match { str }
|
|
238 |
assert.has.error -> sig_str\match { num }
|
|
239 |
|
|
240 |
str = mk_evt 'str'
|
|
241 |
num = mk_evt 'num'
|
|
242 |
assert.is.equal str, evt_str\match { str }
|
|
243 |
assert.is.equal num, evt_num\match { num }
|
|
244 |
assert.has.error -> const_num\match { str }
|
|
245 |
assert.has.error -> const_str\match { num }
|
|
246 |
assert.has.error -> evt_num\match { str }
|
|
247 |
assert.has.error -> evt_str\match { num }
|
|
248 |
|
|
249 |
assert.has.error -> any_str\match { num }
|
145 | 250 |
|
146 | 251 |
describe 'choice', ->
|
147 | 252 |
str = mk_val 'str'
|