diff options
| -rw-r--r-- | test/t/syntax.rb | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/test/t/syntax.rb b/test/t/syntax.rb index f1fc80216..13cd1198e 100644 --- a/test/t/syntax.rb +++ b/test/t/syntax.rb @@ -42,6 +42,98 @@ assert('Abbreviated variable assignment', '11.4.2.3.2') do assert_equal 3, c end +assert('case expression', '11.5.2.2.4') do + # case-expression-with-expression, one when-clause + x = 0 + case "a" + when "a" + x = 1 + end + assert_equal 1, x + + # case-expression-with-expression, multiple when-clauses + x = 0 + case "b" + when "a" + x = 1 + when "b" + x = 2 + end + assert_equal 2, x + + # no matching when-clause + x = 0 + case "c" + when "a" + x = 1 + when "b" + x = 2 + end + assert_equal 0, x + + # case-expression-with-expression, one when-clause and one else-clause + a = 0 + case "c" + when "a" + x = 1 + else + x = 3 + end + assert_equal 3, x + + # case-expression-without-expression, one when-clause + x = 0 + case + when true + x = 1 + end + assert_equal 1, x + + # case-expression-without-expression, multiple when-clauses + x = 0 + case + when 0 == 1 + x = 1 + when 1 == 1 + x = 2 + end + assert_equal 2, x + + # case-expression-without-expression, one when-clause and one else-clause + x = 0 + case + when 0 == 1 + x = 1 + else + x = 3 + end + assert_equal 3, x + + # multiple when-arguments + x = 0 + case 4 + when 1, 3, 5 + x = 1 + when 2, 4, 6 + x = 2 + end + assert_equal 2, x + + # when-argument with splatting argument + x = :integer + odds = [ 1, 3, 5, 7, 9 ] + evens = [ 2, 4, 6, 8 ] + case 5 + when *odds + x = :odd + when *evens + x = :even + end + assert_equal :odd, x + + true +end + assert('Nested const reference') do module Syntax4Const CONST1 = "hello world" |
