summaryrefslogtreecommitdiffhomepage
path: root/test/t
diff options
context:
space:
mode:
Diffstat (limited to 'test/t')
-rw-r--r--test/t/array.rb21
-rw-r--r--test/t/class.rb10
-rw-r--r--test/t/exception.rb12
-rw-r--r--test/t/float.rb7
-rw-r--r--test/t/kernel.rb31
-rw-r--r--test/t/localjumperror.rb8
-rw-r--r--test/t/module.rb14
-rw-r--r--test/t/string.rb4
-rw-r--r--test/t/syntax.rb115
9 files changed, 212 insertions, 10 deletions
diff --git a/test/t/array.rb b/test/t/array.rb
index 8ef1eee3f..1398bdc6e 100644
--- a/test/t/array.rb
+++ b/test/t/array.rb
@@ -49,6 +49,11 @@ assert('Array#[]', '15.2.12.5.4') do
assert_equal(nil, [1,2,3].[](4))
assert_equal(3, [1,2,3].[](-1))
assert_equal(nil, [1,2,3].[](-4))
+
+ a = [ "a", "b", "c", "d", "e" ]
+ a[1.1] == "b" and
+ a[1,2] == ["b", "c"] and
+ a[1..-2] == ["b", "c", "d"]
end
assert('Array#[]=', '15.2.12.5.5') do
@@ -64,6 +69,18 @@ assert('Array#[]=', '15.2.12.5.5') do
assert_equal(4, [1,2,3].[]=(1,4))
assert_equal(3, [1,2,3].[]=(1,2,3))
+
+ a = [1,2,3,4,5]
+ a[3..-1] = 6
+ assert_equal([1,2,3,6], a)
+
+ a = [1,2,3,4,5]
+ a[3..-1] = []
+ assert_equal([1,2,3], a)
+
+ a = [1,2,3,4,5]
+ a[2...4] = 6
+ assert_equal([1,2,6,5], a)
end
assert('Array#clear', '15.2.12.5.6') do
@@ -301,6 +318,7 @@ assert('Array#hash', '15.2.12.5.35') do
a = [ 1, 2, 3 ]
assert_true(a.hash.is_a? Integer)
+ assert_equal([1,2].hash, [1,2].hash)
end
assert('Array#<=>', '15.2.12.5.36') do
@@ -328,6 +346,3 @@ assert("Array (Longish inline array)") do
ary.each {|p| h[p.class] += 1}
assert_equal({Array=>200}, h)
end
-
-
-
diff --git a/test/t/class.rb b/test/t/class.rb
index a6ba336e3..bea20ee24 100644
--- a/test/t/class.rb
+++ b/test/t/class.rb
@@ -359,3 +359,13 @@ assert('singleton tests') do
end
end
end
+
+assert('clone Class') do
+ class Foo
+ def func
+ true
+ end
+ end
+
+ Foo.clone.new.func
+end
diff --git a/test/t/exception.rb b/test/t/exception.rb
index 4239cba8b..8099e911f 100644
--- a/test/t/exception.rb
+++ b/test/t/exception.rb
@@ -345,3 +345,15 @@ assert('Exception#backtrace') do
true
end
+
+assert('Raise in ensure') do
+
+ assert_raise(RuntimeError) do
+ begin
+ raise ""
+ ensure
+ raise ""
+ end
+ end
+
+end
diff --git a/test/t/float.rb b/test/t/float.rb
index f70bf2d66..0c67f510a 100644
--- a/test/t/float.rb
+++ b/test/t/float.rb
@@ -143,3 +143,10 @@ assert('Float#truncate', '15.2.9.3.15') do
assert_equal( 3, 3.123456789.truncate)
assert_equal(-3, -3.1.truncate)
end
+
+assert('Float#nan?') do
+ assert_true (0.0/0.0).nan?
+ assert_false 0.0.nan?
+ assert_false (1.0/0.0).nan?
+ assert_false (-1.0/0.0).nan?
+end
diff --git a/test/t/kernel.rb b/test/t/kernel.rb
index a78bfe35f..e7c9c2635 100644
--- a/test/t/kernel.rb
+++ b/test/t/kernel.rb
@@ -388,7 +388,15 @@ assert('Kernel#object_id', '15.3.1.3.33') do
a = ""
b = ""
assert_not_equal a.object_id, b.object_id
- assert_not_equal 1.object_id, 1.2.object_id
+
+ assert_kind_of Numeric, object_id
+ assert_kind_of Numeric, "".object_id
+ assert_kind_of Numeric, true.object_id
+ assert_kind_of Numeric, false.object_id
+ assert_kind_of Numeric, nil.object_id
+ assert_kind_of Numeric, :no.object_id
+ assert_kind_of Numeric, 1.object_id
+ assert_kind_of Numeric, 1.0.object_id
end
# Kernel#p is defined in mruby-print mrbgem. '15.3.1.3.34'
@@ -471,6 +479,27 @@ assert('Kernel#!=') do
assert_false (str2 != str1)
end
+# operator "!~" is defined in ISO Ruby 11.4.4.
+assert('Kernel#!~') do
+ x = "x"
+ def x.=~(other)
+ other == "x"
+ end
+ assert_false x !~ "x"
+ assert_true x !~ "z"
+
+ y = "y"
+ def y.=~(other)
+ other == "y"
+ end
+ def y.!~(other)
+ other == "not y"
+ end
+ assert_false y !~ "y"
+ assert_false y !~ "z"
+ assert_true y !~ "not y"
+end
+
assert('Kernel#respond_to_missing?') do
class Test4RespondToMissing
def respond_to_missing?(method_name, include_private = false)
diff --git a/test/t/localjumperror.rb b/test/t/localjumperror.rb
index a7d18b3b1..1780cb518 100644
--- a/test/t/localjumperror.rb
+++ b/test/t/localjumperror.rb
@@ -3,10 +3,10 @@
assert('LocalJumpError', '15.2.25') do
assert_equal Class, LocalJumpError.class
- assert_raise LocalJumpError do
- # this will cause an exception due to the wrong location
- retry
- end
+# assert_raise LocalJumpError do
+# # this will cause an exception due to the wrong location
+# retry
+# end
end
# TODO 15.2.25.2.1 LocalJumpError#exit_value
diff --git a/test/t/module.rb b/test/t/module.rb
index 170eb925a..48a09f720 100644
--- a/test/t/module.rb
+++ b/test/t/module.rb
@@ -503,3 +503,17 @@ assert('Issue 1467') do
C1.new
C2.new
end
+
+assert('clone Module') do
+ module M1
+ def foo
+ true
+ end
+ end
+
+ class B
+ include M1.clone
+ end
+
+ B.new.foo
+end
diff --git a/test/t/string.rb b/test/t/string.rb
index 4c3689b3a..c42fa006f 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -28,6 +28,8 @@ assert('String#==', '15.2.10.5.2') do
assert_not_equal 'abc', 'cba'
end
+# 'String#=~', '15.2.10.5.3' will be tested in mrbgems.
+
assert('String#+', '15.2.10.5.4') do
assert_equal 'ab', 'a' + 'b'
end
@@ -36,8 +38,6 @@ assert('String#*', '15.2.10.5.5') do
assert_equal 'aaaaa', 'a' * 5
end
-# 'String#=~', '15.2.10.5.5' will be tested in mrbgems.
-
assert('String#[]', '15.2.10.5.6') do
# length of args is 1
a = 'abc'[0]
diff --git a/test/t/syntax.rb b/test/t/syntax.rb
index 4ddbefea3..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"
@@ -102,3 +194,26 @@ assert('Return values of case statements') do
assert_equal [nil], b
assert_equal 1, fb.call
end
+
+assert('splat in case statement') do
+ values = [3,5,1,7,8]
+ testa = [1,2,7]
+ testb = [5,6]
+ resulta = []
+ resultb = []
+ resultc = []
+ values.each do |value|
+ case value
+ when *testa
+ resulta << value
+ when *testb
+ resultb << value
+ else
+ resultc << value
+ end
+ end
+
+ assert_equal [1,7], resulta
+ assert_equal [5], resultb
+ assert_equal [3,8], resultc
+end