diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-01-06 08:05:48 -0800 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-01-06 08:05:48 -0800 |
| commit | 8d01c157c6a8e293370f20817461f453c3835078 (patch) | |
| tree | 1f47096bd141da17b0c8d2137427892e74a70887 /test | |
| parent | 07e8f800408c412f90f26ddb85b497beec3f1ce6 (diff) | |
| parent | 37475f4577886ad85c87967c94c4bcfc6f6949d5 (diff) | |
| download | mruby-8d01c157c6a8e293370f20817461f453c3835078.tar.gz mruby-8d01c157c6a8e293370f20817461f453c3835078.zip | |
Merge pull request #1645 from iij/pr-case-expression-test
tests for "case" expression.
Diffstat (limited to 'test')
| -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" |
