diff options
Diffstat (limited to 'spec/inputs/destructure.yue')
-rw-r--r-- | spec/inputs/destructure.yue | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue index 674dfe4..b6250d0 100644 --- a/spec/inputs/destructure.yue +++ b/spec/inputs/destructure.yue | |||
@@ -94,7 +94,7 @@ do | |||
94 | -- | 94 | -- |
95 | 95 | ||
96 | do | 96 | do |
97 | with {a,b} = thing | 97 | with {a,b} := thing |
98 | print a, b | 98 | print a, b |
99 | 99 | ||
100 | 100 | ||
@@ -240,5 +240,43 @@ do | |||
240 | switch tb | 240 | switch tb |
241 | when {c: {<"abc">: meta_field = "def"}, <[[any string]]>: {d: abc = 123}, <'str'>: {e: def = {}}} | 241 | when {c: {<"abc">: meta_field = "def"}, <[[any string]]>: {d: abc = 123}, <'str'>: {e: def = {}}} |
242 | print meta_field, abc, def | 242 | print meta_field, abc, def |
243 | |||
244 | do | ||
245 | clients = ["VIP_Alice", "User_Bob", "User_Clara", "VIP_Eva"] | ||
246 | [vipStart, ...regulars, vipEnd] = clients | ||
247 | print vipStart -- "VIP_Alice" | ||
248 | print regulars -- {"User_Bob", "User_Clara"} | ||
249 | print vipEnd -- "VIP_Eva" | ||
250 | |||
251 | do | ||
252 | setupMeeting = (participants) -> | ||
253 | [chair, ..._, secretary] = participants | ||
254 | print chair, secretary | ||
255 | |||
256 | setupMeeting ["Alice", "Bob", "Charlie", "David"] | ||
257 | -- Output: Alice David | ||
258 | |||
259 | do | ||
260 | getTransactions = -> | ||
261 | { | ||
262 | {id: "T1", amount: 100} | ||
263 | {id: "T2", amount: 200} | ||
264 | {id: "T3", amount: 300} | ||
265 | } | ||
266 | |||
267 | :id, :amount = getTransactions![#] | ||
268 | assert id == "T3" | ||
269 | assert amount == 300 | ||
270 | |||
271 | do | ||
272 | [ | ||
273 | _ | ||
274 | ...middle | ||
275 | _ | ||
276 | ] = tb | ||
277 | |||
278 | do | ||
279 | {a, :abc, b, :def, ...sub, d, e} = tb | ||
280 | |||
243 | nil | 281 | nil |
244 | 282 | ||