summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-01-07 01:06:02 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-01-07 01:06:02 +0900
commit65f6b105e940b315d8b1ce76b54a5e92a4905ac0 (patch)
tree7011e531285b3f52095ea844cf6ff0c8633e3756
parent7d8a3b618a2b082645fe978aca04c9f72c72e070 (diff)
parent8d01c157c6a8e293370f20817461f453c3835078 (diff)
downloadmruby-65f6b105e940b315d8b1ce76b54a5e92a4905ac0.tar.gz
mruby-65f6b105e940b315d8b1ce76b54a5e92a4905ac0.zip
Merge branch 'master' of github.com:mruby/mruby
-rw-r--r--test/t/syntax.rb92
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"