Commit 65f6b105 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge branch 'master' of github.com:mruby/mruby

parents 7d8a3b61 8d01c157
...@@ -42,6 +42,98 @@ assert('Abbreviated variable assignment', '11.4.2.3.2') do ...@@ -42,6 +42,98 @@ assert('Abbreviated variable assignment', '11.4.2.3.2') do
assert_equal 3, c assert_equal 3, c
end 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 assert('Nested const reference') do
module Syntax4Const module Syntax4Const
CONST1 = "hello world" CONST1 = "hello world"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment