@@ -297,49 +297,63 @@ class PatternMatchTest < PicoRubyTest
297297 p result
298298 RUBY
299299
300- desc "case with splat in array literal predicate"
301- assert_equal ( <<~RUBY , ":match" )
302- arr = [2, 3]
303- result = case [1, *arr, 4]
304- in [1, 2, 3, 4]
300+ desc "deconstruct returns nil"
301+ assert_equal ( <<~RUBY , ":no_match" )
302+ class Foo
303+ def deconstruct
304+ nil
305+ end
306+ end
307+ result = case Foo.new
308+ in [a, b]
305309 :match
306310 else
307311 :no_match
308312 end
309313 p result
310314 RUBY
311315
312- desc "deconstruct returns nil"
316+ desc "deconstruct_keys returns nil"
313317 assert_equal ( <<~RUBY , ":no_match" )
314318 class Foo
315- def deconstruct
319+ def deconstruct_keys(keys)
316320 nil
317321 end
318322 end
319323 result = case Foo.new
320- in [a, b]
324+ in {a: 1}
321325 :match
322326 else
323327 :no_match
324328 end
325329 p result
326330 RUBY
327331
328- desc "hash pattern with nil value matches"
329- assert_equal ( <<~RUBY , ":match" )
330- result = case {a: nil}
331- in {a: nil}
332+ desc "deconstruct returns nil for find pattern"
333+ assert_equal ( <<~RUBY , ":no_match" )
334+ class Foo
335+ def deconstruct
336+ nil
337+ end
338+ end
339+ result = case Foo.new
340+ in [*, 1, 2, *]
332341 :match
333342 else
334343 :no_match
335344 end
336345 p result
337346 RUBY
338347
339- desc "hash pattern with missing key does not match"
340- assert_equal ( <<~RUBY , ":no_match" )
341- result = case {b: 1}
342- in {a: nil}
348+ # TODO
349+ # The rest of the pattern matching features needs merging PR:
350+ # https://github.com/mrubyc/mrubyc/pull/257
351+ pending unless ENV [ 'USE_MRUBY' ]
352+
353+ desc "hash pattern with **nil matches exact keys"
354+ assert_equal ( <<~RUBY , ":match" )
355+ result = case {a: 1}
356+ in {a: 1, **nil}
343357 :match
344358 else
345359 :no_match
@@ -358,54 +372,40 @@ def deconstruct
358372 p result
359373 RUBY
360374
361- desc "hash pattern with **nil matches exact keys "
362- assert_equal ( <<~RUBY , ":match " )
363- result = case {a : 1}
364- in {a: 1, ** nil}
375+ desc "hash pattern with missing key does not match "
376+ assert_equal ( <<~RUBY , ":no_match " )
377+ result = case {b : 1}
378+ in {a: nil}
365379 :match
366380 else
367381 :no_match
368382 end
369383 p result
370384 RUBY
371385
372- desc "deconstruct_keys returns nil"
373- assert_equal ( <<~RUBY , ":no_match" )
374- class Foo
375- def deconstruct_keys(keys)
376- nil
377- end
378- end
379- result = case Foo.new
380- in {a: 1}
386+ desc "hash pattern with nil value matches"
387+ assert_equal ( <<~RUBY , ":match" )
388+ result = case {a: nil}
389+ in {a: nil}
381390 :match
382391 else
383392 :no_match
384393 end
385394 p result
386395 RUBY
387396
388- desc "deconstruct returns nil for find pattern"
389- assert_equal ( <<~RUBY , ":no_match" )
390- class Foo
391- def deconstruct
392- nil
393- end
394- end
395- result = case Foo.new
396- in [*, 1, 2, *]
397+ desc "case with splat in array literal predicate"
398+ assert_equal ( <<~RUBY , ":match" )
399+ arr = [2, 3]
400+ result = case [1, *arr, 4]
401+ in [1, 2, 3, 4]
397402 :match
398403 else
399404 :no_match
400405 end
401406 p result
402407 RUBY
403408
404- # TODO
405- # The rest of the pattern matching features needs merging PR:
406- # https://github.com/mrubyc/mrubyc/pull/257
407- pending unless ENV [ 'USE_MRUBY' ]
408-
409409 desc "array pattern with rest"
410410 assert_equal ( <<~RUBY , "[1, [2, 3, 4], 5]" )
411411 result = case [1, 2, 3, 4, 5]
0 commit comments