summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-06-14 04:30:52 -0700
committerYukihiro "Matz" Matsumoto <[email protected]>2013-06-14 04:30:52 -0700
commit34cd70b1c5fabc3e3a4f6a705c2bcb3a78fd7ab9 (patch)
tree90d117b0192dadc30bf038369266836355449fe6 /test
parentdbc93621c94b9b2d2b437cde40d8efec7337a64d (diff)
parentf6975ea789d3fe04b9fe58472e9d4ed4ebd6ea67 (diff)
downloadmruby-34cd70b1c5fabc3e3a4f6a705c2bcb3a78fd7ab9.tar.gz
mruby-34cd70b1c5fabc3e3a4f6a705c2bcb3a78fd7ab9.zip
Merge pull request #1279 from Bovi-Li/improve-tests
Improve Test Infrastructure (Part 1)
Diffstat (limited to 'test')
-rw-r--r--test/assert.rb13
-rw-r--r--test/t/argumenterror.rb5
-rw-r--r--test/t/array.rb170
-rw-r--r--test/t/basicobject.rb4
-rw-r--r--test/t/class.rb162
-rw-r--r--test/t/comparable.rb21
-rw-r--r--test/t/enumerable.rb55
-rw-r--r--test/t/exception.rb54
-rw-r--r--test/t/false.rb17
-rw-r--r--test/t/methods.rb109
10 files changed, 315 insertions, 295 deletions
diff --git a/test/assert.rb b/test/assert.rb
index cb2e28b89..6d727e889 100644
--- a/test/assert.rb
+++ b/test/assert.rb
@@ -105,6 +105,12 @@ def assert_equal(exp, act, msg = nil)
assert_true(exp == act, msg, diff)
end
+def assert_not_equal(exp, act, msg = nil)
+ msg = "Expected to be not equal" unless msg
+ diff = assertion_diff(exp, act)
+ assert_false(exp == act, msg, diff)
+end
+
def assert_nil(obj, msg = nil)
msg = "Expected #{obj.inspect} to be nil" unless msg
diff = assertion_diff(nil, obj)
@@ -118,6 +124,13 @@ def assert_include(collection, obj, msg = nil)
assert_true(collection.include?(obj), msg, diff)
end
+def assert_not_include(collection, obj, msg = nil)
+ msg = "Expected #{collection.inspect} to not include #{obj.inspect}" unless msg
+ diff = " Collection: #{collection.inspect}\n" +
+ " Object: #{obj.inspect}"
+ assert_false(collection.include?(obj), msg, diff)
+end
+
def assert_raise(*exp)
ret = true
if $mrbtest_assert
diff --git a/test/t/argumenterror.rb b/test/t/argumenterror.rb
index 71cf38e26..ac254afcd 100644
--- a/test/t/argumenterror.rb
+++ b/test/t/argumenterror.rb
@@ -11,10 +11,11 @@ assert('ArgumentError', '15.2.24') do
e2 = e1
end
- ArgumentError.class == Class and e2.class == ArgumentError
+ assert_equal(ArgumentError.class, Class)
+ assert_equal(e2.class, ArgumentError)
end
assert('ArgumentError superclass', '15.2.24.2') do
- ArgumentError.superclass == StandardError
+ assert_equal(ArgumentError.superclass, StandardError)
end
diff --git a/test/t/array.rb b/test/t/array.rb
index 47259c268..9878e2cbf 100644
--- a/test/t/array.rb
+++ b/test/t/array.rb
@@ -2,156 +2,129 @@
# Array ISO Test
assert('Array', '15.2.12') do
- Array.class == Class
+ assert_equal(Array.class, Class)
end
assert('Array superclass', '15.2.12.2') do
- Array.superclass == Object
+ assert_equal(Array.superclass, Object)
end
assert('Array.[]', '15.2.12.4.1') do
- Array.[](1,2,3) == [1, 2, 3]
+ assert_equal(Array.[](1,2,3), [1, 2, 3])
end
assert('Array#*', '15.2.12.5.1') do
- e2 = nil
- begin
+ assert_raise(ArgumentError) do
# this will cause an exception due to the wrong argument
[1].*(-1)
- rescue => e1
- e2 = e1
end
- a = [1].*(3)
- b = [1].*(0)
- a == [1, 1, 1] and b == [] and
- e2.class == ArgumentError
+ assert_equal([1].*(3), [1, 1, 1])
+ assert_equal([1].*(0), [])
end
assert('Array#+', '15.2.12.5.2') do
- [1].+([1]) == [1, 1]
+ assert_equal([1].+([1]), [1, 1])
end
assert('Array#<<', '15.2.12.5.3') do
- [1].<<(1) == [1, 1]
+ assert_equal([1].<<(1), [1, 1])
end
assert('Array#[]', '15.2.12.5.4') do
- e2 = nil
- e3 = nil
a = Array.new
- begin
+ assert_raise(ArgumentError) do
# this will cause an exception due to the wrong arguments
a.[]()
- rescue => e1
- e2 = e1
end
- begin
+ assert_raise(ArgumentError) do
# this will cause an exception due to the wrong arguments
a.[](1,2,3)
- rescue => e1
- e3 = e1
end
- [1,2,3].[](1) == 2 and
- e2.class == ArgumentError and
- e3.class == ArgumentError
+ assert_equal([1,2,3].[](1), 2)
end
assert('Array#[]=', '15.2.12.5.5') do
- e2 = nil
- e3 = nil
a = Array.new
- begin
+ assert_raise(ArgumentError) do
# this will cause an exception due to the wrong arguments
a.[]=()
- rescue => e1
- e2 = e1
end
- begin
+ assert_raise(ArgumentError) do
# this will cause an exception due to the wrong arguments
a.[]=(1,2,3,4)
- rescue => e1
- e3 = e1
end
- [1,2,3].[]=(1,4) == 4 and
- [1,2,3].[]=(1,2,3) == 3 and
- e2.class == ArgumentError and
- e3.class == ArgumentError
+ assert_equal([1,2,3].[]=(1,4), 4)
+ assert_equal([1,2,3].[]=(1,2,3), 3)
end
assert('Array#clear', '15.2.12.5.6') do
a = [1]
a.clear
- a == []
+ assert_equal(a, [])
end
assert('Array#collect!', '15.2.12.5.7') do
a = [1,2,3]
a.collect! { |i| i + i }
- a == [2,4,6]
+ assert_equal(a, [2,4,6])
end
assert('Array#concat', '15.2.12.5.8') do
- a = [1,2]
- b = [3,4]
- a.concat(b) == [1,2,3,4]
+ assert_equal([1, 2].concat([3, 4]), [1,2,3,4])
end
assert('Array#delete_at', '15.2.12.5.9') do
a = [1,2,3]
a.delete_at(1)
- a == [1,3]
+ assert_equal(a, [1,3])
end
assert('Array#each', '15.2.12.5.10') do
a = [1,2,3]
b = 0
a.each {|i| b += i}
- b == 6
+ assert_equal(b, 6)
end
assert('Array#each_index', '15.2.12.5.11') do
a = [1]
b = nil
a.each_index {|i| b = i}
- b == 0
+ assert_equal(b, 0)
end
assert('Array#empty?', '15.2.12.5.12') do
a = []
b = [b]
- a.empty? and not b.empty?
+ assert_true([].empty?)
+ assert_false([1].empty?)
end
assert('Array#first', '15.2.12.5.13') do
- a = []
- b = [1,2,3]
-
- e2 = nil
- e3 = nil
- begin
+ assert_raise(ArgumentError) do
# this will cause an exception due to the wrong argument
[1,2,3].first(-1)
- rescue => e1
- e2 = e1
end
- begin
+ assert_raise(ArgumentError) do
# this will cause an exception due to the wrong argument
[1,2,3].first(1,2)
- rescue => e1
- e3 = e1
end
- a.first == nil and b.first == 1 and b.first(0) == [] and
- b.first(1) == [1] and b.first(4) == [1,2,3] and
- e2.class == ArgumentError and e3.class == ArgumentError
+ assert_nil([].first)
+
+ b = [1,2,3]
+ assert_equal(b.first, 1)
+ assert_equal(b.first(0), [])
+ assert_equal(b.first(1), [1])
+ assert_equal(b.first(4), [1,2,3])
end
assert('Array#index', '15.2.12.5.14') do
a = [1,2,3]
- a.index(2) == 1
+ assert_equal(a.index(2), 1)
end
assert('Array#initialize', '15.2.12.5.15') do
@@ -160,107 +133,117 @@ assert('Array#initialize', '15.2.12.5.15') do
c = [].initialize(2, 1)
d = [].initialize(2) {|i| i}
- a == [nil] and b == [nil,nil] and c == [1,1] and d == [0,1]
+ assert_equal(a, [nil])
+ assert_equal(b, [nil,nil])
+ assert_equal(c, [1,1])
+ assert_equal(d, [0,1])
end
assert('Array#initialize_copy', '15.2.12.5.16') do
a = [1,2,3]
b = [].initialize_copy(a)
- b == [1,2,3]
+ assert_equal(b, [1,2,3])
end
assert('Array#join', '15.2.12.5.17') do
a = [1,2,3].join
b = [1,2,3].join(',')
- a == '123' and b == '1,2,3'
+ assert_equal(a, '123')
+ assert_equal(b, '1,2,3')
end
assert('Array#last', '15.2.12.5.18') do
- a = [1,2,3]
-
- e2 = nil
- begin
+ assert_raise(ArgumentError) do
# this will cause an exception due to the wrong argument
[1,2,3].last(-1)
- rescue => e1
- e2 = e1
end
- a.last == 3 and [].last == nil and e2.class == ArgumentError
+ a = [1,2,3]
+ assert_equal(a.last, 3)
+ assert_nil([].last)
end
assert('Array#length', '15.2.12.5.19') do
a = [1,2,3]
- a.length == 3
+ assert_equal(a.length, 3)
end
assert('Array#map!', '15.2.12.5.20') do
a = [1,2,3]
a.map! { |i| i + i }
- a == [2,4,6]
+ assert_equal(a, [2,4,6])
end
assert('Array#pop', '15.2.12.5.21') do
a = [1,2,3]
b = a.pop
- [].pop == nil and a == [1,2] and b = 3
+ assert_nil([].pop)
+ assert_equal(a, [1,2])
+ assert_equal(b, 3)
end
assert('Array#push', '15.2.12.5.22') do
a = [1,2,3]
b = a.push(4)
- a == [1,2,3,4] and b = [1,2,3,4]
+ assert_equal(a, [1,2,3,4])
+ assert_equal(b, [1,2,3,4])
end
assert('Array#replace', '15.2.12.5.23') do
a = [1,2,3]
b = [].replace(a)
- b == [1,2,3]
+ assert_equal(b, [1,2,3])
end
assert('Array#reverse', '15.2.12.5.24') do
a = [1,2,3]
b = a.reverse
- a == [1,2,3] and b == [3,2,1]
+ assert_equal(a, [1,2,3])
+ assert_equal(b, [3,2,1])
end
assert('Array#reverse!', '15.2.12.5.25') do
a = [1,2,3]
b = a.reverse!
- a == [3,2,1] and b == [3,2,1]
+ assert_equal(a, [3,2,1])
+ assert_equal(b, [3,2,1])
end
assert('Array#rindex', '15.2.12.5.26') do
a = [1,2,3]
- a.rindex(2) == 1
+ assert_equal(a.rindex(2), 1)
end
assert('Array#shift', '15.2.12.5.27') do
a = [1,2,3]
b = a.shift
- [].shift == nil and a == [2,3] and b == 1
+ assert_nil([].shift)
+ assert_equal(a, [2,3])
+ assert_equal(b, 1)
end
assert('Array#size', '15.2.12.5.28') do
a = [1,2,3]
- a.size == 3
+ assert_equal(a.size, 3)
end
assert('Array#slice', '15.2.12.5.29') do
a = "12345".slice(1, 3)
b = a.slice(0)
- "#{b}:" == "2:" and [1,2,3].[](1) == 2
+
+ assert_equal("#{b}:", "2:")
+ assert_equal([1,2,3].[](1), 2)
end
assert('Array#unshift', '15.2.12.5.30') do
@@ -269,7 +252,10 @@ assert('Array#unshift', '15.2.12.5.30') do
c = [2,3]
d = c.unshift(0, 1)
- a == [1,2,3] and b == [1,2,3] and c == [0,1,2,3] and d == [0,1,2,3]
+ assert_equal(a, [1,2,3])
+ assert_equal(b, [1,2,3])
+ assert_equal(c, [0,1,2,3])
+ assert_equal(d, [0,1,2,3])
end
assert('Array#to_s', '15.2.12.5.31 / 15.2.12.5.32') do
@@ -277,15 +263,14 @@ assert('Array#to_s', '15.2.12.5.31 / 15.2.12.5.32') do
r1 = a.to_s
r2 = a.inspect
- r1 == r2 and r1 == "[2, 3, 4, 5]"
+ assert_equal(r1, r2)
+ assert_equal(r1, "[2, 3, 4, 5]")
end
assert('Array#==', '15.2.12.5.33') do
- r1 = [ "a", "c" ] == [ "a", "c", 7 ] #=> false
- r2 = [ "a", "c", 7 ] == [ "a", "c", 7 ] #=> true
- r3 = [ "a", "c", 7 ] == [ "a", "d", "f" ] #=> false
-
- r1 == false and r2 == true and r3 == false
+ assert_false(["a", "c"] == ["a", "c", 7])
+ assert_true(["a", "c", 7] == ["a", "c", 7])
+ assert_false(["a", "c", 7] == ["a", "d", "f"])
end
assert('Array#eql?', '15.2.12.5.34') do
@@ -293,13 +278,14 @@ assert('Array#eql?', '15.2.12.5.34') do
a2 = [ 1, 2, 3 ]
a3 = [ 1.0, 2.0, 3.0 ]
- (a1.eql? a2) and (not a1.eql? a3)
+ assert_true(a1.eql? a2)
+ assert_false(a1.eql? a3)
end
assert('Array#hash', '15.2.12.5.35') do
a = [ 1, 2, 3 ]
- a.hash.is_a? Integer
+ assert_true(a.hash.is_a? Integer)
end
assert('Array#<=>', '15.2.12.5.36') do
@@ -307,7 +293,9 @@ assert('Array#<=>', '15.2.12.5.36') do
r2 = [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1
r3 = [ "a", "b", "c" ] <=> [ "a", "b", "c" ] #=> 0
- r1 == -1 and r2 == +1 and r3 == 0
+ assert_equal(r1, -1)
+ assert_equal(r2, +1)
+ assert_equal(r3, 0)
end
# Not ISO specified
diff --git a/test/t/basicobject.rb b/test/t/basicobject.rb
index f7e95af89..d4c344ca9 100644
--- a/test/t/basicobject.rb
+++ b/test/t/basicobject.rb
@@ -2,10 +2,10 @@
# BasicObject
assert('BasicObject') do
- BasicObject.class == Class
+ assert_equal(BasicObject.class, Class)
end
assert('BasicObject superclass') do
- BasicObject.superclass == nil
+ assert_nil(BasicObject.superclass)
end
diff --git a/test/t/class.rb b/test/t/class.rb
index c558c6437..9ba490d93 100644
--- a/test/t/class.rb
+++ b/test/t/class.rb
@@ -2,11 +2,11 @@
# Class ISO Test
assert('Class', '15.2.3') do
- Class.class == Class
+ assert_equal(Class.class, Class)
end
assert('Class superclass', '15.2.3.2') do
- Class.superclass == Module
+ assert_equal(Class.superclass, Module)
end
# Class#initialize '15.2.3.3.1' is tested in Class#new
@@ -26,7 +26,8 @@ assert('Class#initialize_copy', '15.2.3.3.2') do
c2 = c1.dup
c3 = TestClass.new('Bar')
- c1.n == c2.n and c1.n != c3.n
+ assert_equal(c1.n, c2.n)
+ assert_not_equal(c1.n, c3.n)
end
assert('Class#new', '15.2.3.3.3') do
@@ -51,48 +52,48 @@ assert('Class#new', '15.2.3.3.3') do
def result; @result; end
end
- TestClass.new(:arg).result == :only_args
+ assert_equal(TestClass.new(:arg).result, :only_args)
# with block doesn't work yet
end
assert('Class#superclass', '15.2.3.3.4') do
class SubClass < String; end
- SubClass.superclass == String
+ assert_equal(SubClass.superclass, String)
end
# Not ISO specified
assert('Class 1') do
class C1; end
- C1.class == Class
+ assert_equal(C1.class, Class)
end
assert('Class 2') do
class C2; end
- C2.new.class == C2
+ assert_equal(C2.new.class, C2)
end
assert('Class 3') do
class C3; end
- C3.new.class.class == Class
+ assert_equal(C3.new.class.class, Class)
end
assert('Class 4') do
class C4_A; end
class C4 < C4_A; end
- C4.class == Class
+ assert_equal(C4.class, Class)
end
assert('Class 5') do
class C5_A; end
class C5 < C5_A; end
- C5.new.class == C5
+ assert_equal(C5.new.class, C5)
end
assert('Class 6') do
class C6_A; end
class C6 < C6_A; end
- C6.new.class.class == Class
+ assert_equal(C6.new.class.class, Class)
end
assert('Class 7') do
@@ -101,15 +102,10 @@ assert('Class 7') do
class C7 < C7_A; end
- error = false
- begin
+ assert_raise(TypeError) do
# Different superclass.
class C7 < C7_B; end
- rescue TypeError
- error = true
end
-
- error
end
assert('Class 8') do
@@ -117,193 +113,107 @@ assert('Class 8') do
class C8; end # superclass is Object
- error = false
- begin
+ assert_raise(TypeError) do
# Different superclass.
class C8 < C8_A; end
- rescue TypeError
- error = true
end
-
- error
end
assert('Class 9') do
Class9Const = "a"
- error = false
- begin
+ assert_raise(TypeError) do
class Class9Const; end
- rescue TypeError
- error = true
end
-
- error
end
assert('Class Module 1') do
module M; end
- M.class == Module
+ assert_equal(M.class, Module)
end
assert('Class Module 2') do
module M; end
class C; include M; end
- C.new.class == C
+ assert_equal(C.new.class, C)
end
# nested class
assert('Class Nested 1') do
class A; end
class A::B; end
- A::B == A::B
+ assert_equal(A::B, A::B)
end
assert('Class Nested 2') do
class A; end
class A::B; end
- A::B.new.class == A::B
+ assert_equal(A::B.new.class, A::B)
end
assert('Class Nested 3') do
class A; end
class A::B; end
- A::B.new.class.class == Class
+ assert_equal(A::B.new.class.class, Class)
end
assert('Class Nested 4') do
class A; end
class A::B; end
class A::B::C; end
- A::B::C == A::B::C
+ assert_equal(A::B::C, A::B::C)
end
assert('Class Nested 5') do
class A; end
class A::B; end
class A::B::C; end
- A::B::C.class == Class
+ assert_equal(A::B::C.class, Class)
end
assert('Class Nested 6') do
class A; end
class A::B; end
class A::B::C; end
- A::B::C.new.class == A::B::C
+ assert_equal(A::B::C.new.class, A::B::C)
end
assert('Class Nested 7') do
class A; end
class A::B; end
class A::B2 < A::B; end
- A::B2 == A::B2
+ assert_equal(A::B2, A::B2)
end
assert('Class Nested 8') do
class A; end
class A::B; end
class A::B2 < A::B; end
- A::B2.class == Class
+ assert_equal(A::B2.class, Class)
end
assert('Class Colon 1') do
- class A; end; A::C = 1; A::C == 1
+ class A; end
+ A::C = 1
+ assert_equal(A::C, 1)
end
assert('Class Colon 2') do
- class A; class ::C; end end; C == C
+ class A; class ::C; end end
+ assert_equal(C, C)
end
assert('Class Colon 3') do
- class A; class ::C; end end; C.class == Class
+ class A; class ::C; end end
+ assert_equal(C.class, Class)
end
assert('Class Dup 1') do
- class C; end; C.dup.class == Class
+ class C; end
+ assert_equal(C.dup.class, Class)
end
assert('Class Dup 2') do
- module M; end; M.dup.class == Module
-end
-
-assert('Class Alias 1') do
- class A
- def test; 1; end
-
- alias test2 test
- alias :test3 :test
- end
-
- A.new.test2 == 1 and A.new.test3 == 1
-end
-
-assert('Class Alias 2') do
- class A
- def test; 1; end
-
- alias test2 test
-
- def test; 2; end
- end
-
- A.new.test == 2 and A.new.test2 == 1
-end
-
-assert('Class Undef 1') do
- class A
- def test1; 1; end
- def test2; 2; end
-
- undef test1
- undef :test2
- end
-
- result1 = false
- begin
- A.new.test1
- rescue NoMethodError
- result1 = true
- end
-
- result2 = false
- begin
- A.new.test2
- rescue NoMethodError
- result2 = true
- end
-
- result1 == true and result2 == true
-end
-
-assert('Class Undef 2') do
- class A
- def test1; 1; end
- def test2; 2; end
-
- undef test1, test2
- end
-
- result1 = false
- begin
- A.new.test1
- rescue NoMethodError
- result1 = true
- end
-
- result2 = false
- begin
- A.new.test2
- rescue NoMethodError
- result2 = true
- end
-
- result1 == true and result2 == true
-end
-
-assert('Var undef') do
- assert_raise(NameError) do
- a=1
- undef a
- end
+ module M; end
+ assert_equal(M.dup.class, Module)
end
-
diff --git a/test/t/comparable.rb b/test/t/comparable.rb
index ab81fa3ed..b5718d2d2 100644
--- a/test/t/comparable.rb
+++ b/test/t/comparable.rb
@@ -7,7 +7,7 @@ assert('Comparable#<', '15.3.3.2.1') do
end
end
- (Foo.new < Foo.new) == false
+ assert_false(Foo.new < Foo.new)
end
assert('Comparable#<=', '15.3.3.2.2') do
@@ -18,7 +18,7 @@ assert('Comparable#<=', '15.3.3.2.2') do
end
end
- (Foo.new <= Foo.new) == true
+ assert_true(Foo.new <= Foo.new)
end
assert('Comparable#==', '15.3.3.2.3') do
@@ -29,7 +29,7 @@ assert('Comparable#==', '15.3.3.2.3') do
end
end
- (Foo.new == Foo.new) == true
+ assert_true(Foo.new == Foo.new)
end
assert('Comparable#>', '15.3.3.2.4') do
@@ -40,7 +40,7 @@ assert('Comparable#>', '15.3.3.2.4') do
end
end
- (Foo.new > Foo.new) == false
+ assert_false(Foo.new > Foo.new)
end
assert('Comparable#>=', '15.3.3.2.5') do
@@ -51,7 +51,7 @@ assert('Comparable#>=', '15.3.3.2.5') do
end
end
- (Foo.new >= Foo.new) == true
+ assert_true(Foo.new >= Foo.new)
end
assert('Comparable#between?', '15.3.3.2.6') do
@@ -63,9 +63,10 @@ assert('Comparable#between?', '15.3.3.2.6') do
end
c = Foo.new
- c.between?(-1, 1) == false &&
- c.between?(-1, -1) == false &&
- c.between?( 1, 1) == false &&
- c.between?( 1, -1) == true &&
- c.between?(0, 0) == true
+
+ assert_false(c.between?(-1, 1))
+ assert_false(c.between?(-1, -1))
+ assert_false(c.between?( 1, 1))
+ assert_true(c.between?( 1, -1))
+ assert_true(c.between?(0, 0))
end
diff --git a/test/t/enumerable.rb b/test/t/enumerable.rb
index de0bb5a34..494490a9f 100644
--- a/test/t/enumerable.rb
+++ b/test/t/enumerable.rb
@@ -2,23 +2,26 @@
# Enumerable ISO Test
assert('Enumerable', '15.3.2') do
- Enumerable.class == Module
+ assert_equal(Enumerable.class, Module)
end
assert('Enumerable#all?', '15.3.2.2.1') do
- [1,2,3].all? and not [1,false,3].all?
+ assert_true([1,2,3].all?)
+ assert_false([1,false,3].all?)
end
assert('Enumerable#any?', '15.3.2.2.2') do
- [false,true,false].any? and not [false,false,false].any?
+ assert_true([false,true,false].any?)
+ assert_false([false,false,false].any?)
end
assert('Enumerable#collect', '15.3.2.2.3') do
- [1,2,3].collect { |i| i + i } == [2,4,6]
+ assert_true [1,2,3].collect { |i| i + i } == [2,4,6]
end
assert('Enumerable#detect', '15.3.2.2.4') do
- [1,2,3].detect() { true } and [1,2,3].detect("a") { false } == 'a'
+ assert_true [1,2,3].detect() { true }
+ assert_equal [1,2,3].detect("a") { false }, 'a'
end
assert('Array#each_with_index', '15.3.2.2.5') do
@@ -27,54 +30,56 @@ assert('Array#each_with_index', '15.3.2.2.5') do
[1].each_with_index {|e,i| a = e; b = i}
- a == 1 and b == 0
+ assert_equal(a, 1)
+ assert_equal(b, 0)
end
assert('Enumerable#entries', '15.3.2.2.6') do
- [1].entries == [1]
+ assert_equal([1].entries, [1])
end
assert('Enumerable#find', '15.3.2.2.7') do
- [1,2,3].find() { true } and [1,2,3].find("a") { false } == 'a'
+ assert_true [1,2,3].find() { true }
+ assert_equal [1,2,3].find("a") { false }, 'a'
end
assert('Enumerable#find_all', '15.3.2.2.8') do
- [1,2,3,4,5,6,7,8,9].find_all() {|i| i%2 == 0} == [2,4,6,8]
+ assert_true [1,2,3,4,5,6,7,8,9].find_all() {|i| i%2 == 0}, [2,4,6,8]
end
assert('Enumerable#grep', '15.3.2.2.9') do
- [1,2,3,4,5,6,7,8,9].grep(4..6) == [4,5,6]
+ assert_equal [1,2,3,4,5,6,7,8,9].grep(4..6), [4,5,6]
end
assert('Enumerable#include?', '15.3.2.2.10') do
- [1,2,3,4,5,6,7,8,9].include?(5) and
- not [1,2,3,4,5,6,7,8,9].include?(0)
+ assert_true [1,2,3,4,5,6,7,8,9].include?(5)
+ assert_false [1,2,3,4,5,6,7,8,9].include?(0)
end
assert('Enumerable#inject', '15.3.2.2.11') do
- [1,2,3,4,5,6].inject() {|s, n| s + n} == 21 and
- [1,2,3,4,5,6].inject(1) {|s, n| s + n} == 22
+ assert_equal [1,2,3,4,5,6].inject() {|s, n| s + n}, 21
+ assert_equal [1,2,3,4,5,6].inject(1) {|s, n| s + n}, 22
end
assert('Enumerable#map', '15.3.2.2.12') do
- [1,2,3].map { |i| i + i } == [2,4,6]
+ assert_equal [1,2,3].map { |i| i + i }, [2,4,6]
end
assert('Enumerable#max', '15.3.2.2.13') do
a = ['aaa', 'bb', 'c']
- a.max == 'c' and
- a.max {|i1,i2| i1.length <=> i2.length} == 'aaa'
+ assert_equal a.max, 'c'
+ assert_equal a.max {|i1,i2| i1.length <=> i2.length}, 'aaa'
end
assert('Enumerable#min', '15.3.2.2.14') do
a = ['aaa', 'bb', 'c']
- a.min == 'aaa' and
- a.min {|i1,i2| i1.length <=> i2.length} == 'c'
+ assert_equal a.min, 'aaa'
+ assert_equal a.min {|i1,i2| i1.length <=> i2.length}, 'c'
end
assert('Enumerable#member?', '15.3.2.2.15') do
- [1,2,3,4,5,6,7,8,9].member?(5) and
- not [1,2,3,4,5,6,7,8,9].member?(0)
+ assert_true [1,2,3,4,5,6,7,8,9].member?(5)
+ assert_false [1,2,3,4,5,6,7,8,9].member?(0)
end
assert('Enumerable#partion', '15.3.2.2.16') do
@@ -90,14 +95,14 @@ assert('Enumerable#reject', '15.3.2.2.17') do
end
assert('Enumerable#select', '15.3.2.2.18') do
- [1,2,3,4,5,6,7,8,9].select() {|i| i%2 == 0} == [2,4,6,8]
+ assert_equal [1,2,3,4,5,6,7,8,9].select() {|i| i%2 == 0}, [2,4,6,8]
end
assert('Enumerable#sort', '15.3.2.2.19') do
- [7,3,1,2,6,4].sort == [1,2,3,4,6,7] and
- [7,3,1,2,6,4].sort {|e1,e2| e2<=>e1} == [7,6,4,3,2,1]
+ assert_equal [7,3,1,2,6,4].sort, [1,2,3,4,6,7]
+ assert_equal [7,3,1,2,6,4].sort {|e1,e2|e2<=>e1}, [7,6,4,3,2,1]
end
assert('Enumerable#to_a', '15.3.2.2.20') do
- [1].to_a == [1]
+ assert_equal [1].to_a, [1]
end
diff --git a/test/t/exception.rb b/test/t/exception.rb
index 5d46d4632..4b4a7c31d 100644
--- a/test/t/exception.rb
+++ b/test/t/exception.rb
@@ -2,62 +2,55 @@
# Exception ISO Test
assert('Exception', '15.2.22') do
- Exception.class == Class
+ assert_equal Exception.class, Class
end
assert('Exception superclass', '15.2.22.2') do
- Exception.superclass == Object
+ assert_equal Exception.superclass, Object
end
assert('Exception.exception', '15.2.22.4.1') do
e = Exception.exception('a')
- e.class == Exception
+ assert_equal e.class, Exception
end
assert('Exception#exception', '15.2.22.5.1') do
e1 = Exception.exception()
e2 = Exception.exception('b')
- e1.class == Exception and e2.class == Exception
+ assert_equal e1.class, Exception
+ assert_equal e2.class, Exception
end
assert('Exception#message', '15.2.22.5.2') do
e = Exception.exception('a')
- e.message == 'a'
+ assert_equal e.message, 'a'
end
assert('Exception#to_s', '15.2.22.5.3') do
e = Exception.exception('a')
- e.to_s == 'a'
+ assert_equal e.to_s, 'a'
end
assert('Exception.exception', '15.2.22.4.1') do
e = Exception.exception()
e.initialize('a')
- e.message == 'a'
+ assert_equal e.message, 'a'
end
assert('ScriptError', '15.2.37') do
- begin
+ assert_raise(ScriptError) do
raise ScriptError.new
- rescue ScriptError
- true
- else
- false
end
end
assert('SyntaxError', '15.2.38') do
- begin
+ assert_raise(SyntaxError) do
raise SyntaxError.new
- rescue SyntaxError
- true
- else
- false
end
end
@@ -110,7 +103,7 @@ assert('Exception 4') do
end
a = err.class
}
- a == NilClass
+ assert_equal a, NilClass
end
assert('Exception 5') do
@@ -128,7 +121,7 @@ assert('Exception 5') do
}
end
m2
- $ans == [nil]
+ assert_equal $ans, [nil]
end
assert('Exception 6') do
@@ -154,7 +147,7 @@ assert('Exception 6') do
yield
end
m
- $i == 7
+ assert_equal $i, 7
end
assert('Exception 7') do
@@ -174,7 +167,7 @@ assert('Exception 7') do
p :end
end
m
- $i == 10
+ assert_equal $i, 10
end
assert('Exception 8') do
@@ -228,7 +221,7 @@ assert('Exception 11') do
end
rescue Exception
end
- a == :ok
+ assert_equal a, :ok
end
assert('Exception 12') do
@@ -237,7 +230,7 @@ assert('Exception 12') do
raise Exception rescue a = :ng
rescue Exception
end
- a == :ok
+ assert_equal a, :ok
end
assert('Exception 13') do
@@ -251,14 +244,11 @@ assert('Exception 13') do
else
a = :ng
end
- a == :ok
-end
-
-def exception_test14
- UnknownConstant
+ assert_equal a, :ok
end
assert('Exception 14') do
+ def exception_test14; UnknownConstant; end
a = :ng
begin
send(:exception_test14)
@@ -266,16 +256,16 @@ assert('Exception 14') do
a = :ok
end
- a == :ok
+ assert_equal a, :ok
end
assert('Exception 15') do
a = begin
:ok
rescue
- :ng
+ :ko
end
- a == :ok
+ assert_equal a, :ok
end
assert('Exception 16') do
@@ -339,7 +329,7 @@ assert('Exception 19') do
true
end
end
- Class4Exception19.new.a == [true, true]
+ assert_equal Class4Exception19.new.a, [true, true]
end
assert('Exception#inspect without message') do
diff --git a/test/t/false.rb b/test/t/false.rb
index 50ba5623a..97a3b8780 100644
--- a/test/t/false.rb
+++ b/test/t/false.rb
@@ -2,29 +2,32 @@
# FalseClass ISO Test
assert('FalseClass', '15.2.6') do
- FalseClass.class == Class
+ assert_equal FalseClass.class, Class
end
assert('FalseClass superclass', '15.2.6.2') do
- FalseClass.superclass == Object
+ assert_equal FalseClass.superclass, Object
end
assert('FalseClass false', '15.2.6.1') do
- not false
+ assert_false false
end
assert('FalseClass#&', '15.2.6.3.1') do
- not false.&(true) and not false.&(false)
+ assert_false false.&(true)
+ assert_false false.&(false)
end
assert('FalseClass#^', '15.2.6.3.2') do
- false.^(true) and not false.^(false)
+ assert_true false.^(true)
+ assert_false false.^(false)
end
assert('FalseClass#to_s', '15.2.6.3.3') do
- false.to_s == 'false'
+ assert_equal false.to_s, 'false'
end
assert('FalseClass#|', '15.2.6.3.4') do
- false.|(true) and not false.|(false)
+ assert_true false.|(true)
+ assert_false false.|(false)
end
diff --git a/test/t/methods.rb b/test/t/methods.rb
new file mode 100644
index 000000000..bbd8ee09d
--- /dev/null
+++ b/test/t/methods.rb
@@ -0,0 +1,109 @@
+##
+# Chapter 13.3 "Methods" ISO Test
+
+assert('The alias statement', '13.3.6 a) 4)') do
+ # check aliasing in all possible ways
+
+ def alias_test_method_original; true; end
+
+ alias alias_test_method_a alias_test_method_original
+ alias :alias_test_method_b :alias_test_method_original
+
+ assert_true(alias_test_method_original)
+ assert_true(alias_test_method_a)
+ assert_true(alias_test_method_b)
+end
+
+assert('The alias statement (overwrite original)', '13.3.6 a) 4)') do
+ # check that an aliased method can be overwritten
+ # without side effect
+
+ def alias_test_method_original; true; end
+
+ alias alias_test_method_a alias_test_method_original
+ alias :alias_test_method_b :alias_test_method_original
+
+ assert_true(alias_test_method_original)
+
+ def alias_test_method_original; false; end
+
+ assert_false(alias_test_method_original)
+ assert_true(alias_test_method_a)
+ assert_true(alias_test_method_b)
+end
+
+assert('The alias statement', '13.3.6 a) 5)') do
+ # check that alias is raising NameError if
+ # non-existing method should be undefined
+
+ assert_raise(NameError) do
+ alias new_name_a non_existing_method
+ end
+
+ assert_raise(NameError) do
+ alias :new_name_b :non_existing_method
+ end
+end
+
+assert('The undef statement', '13.3.7 a) 4)') do
+ # check that undef is undefining method
+ # based on the method name
+
+ def existing_method_a; true; end
+ def existing_method_b; true; end
+ def existing_method_c; true; end
+ def existing_method_d; true; end
+ def existing_method_e; true; end
+ def existing_method_f; true; end
+
+ # check that methods are defined
+
+ assert_true(existing_method_a, 'Method should be defined')
+ assert_true(existing_method_b, 'Method should be defined')
+ assert_true(existing_method_c, 'Method should be defined')
+ assert_true(existing_method_d, 'Method should be defined')
+ assert_true(existing_method_e, 'Method should be defined')
+ assert_true(existing_method_f, 'Method should be defined')
+
+ # undefine in all possible ways and check that method
+ # is undefined
+
+ undef existing_method_a
+ assert_raise(NoMethodError) do
+ existing_method_a
+ end
+
+ undef :existing_method_b
+ assert_raise(NoMethodError) do
+ existing_method_b
+ end
+
+ undef existing_method_c, existing_method_d
+ assert_raise(NoMethodError) do
+ existing_method_c
+ end
+ assert_raise(NoMethodError) do
+ existing_method_d
+ end
+
+ undef :existing_method_e, :existing_method_f
+ assert_raise(NoMethodError) do
+ existing_method_e
+ end
+ assert_raise(NoMethodError) do
+ existing_method_f
+ end
+end
+
+assert('The undef statement (method undefined)', '13.3.7 a) 5)') do
+ # check that undef is raising NameError if
+ # non-existing method should be undefined
+
+ assert_raise(NameError) do
+ undef non_existing_method
+ end
+
+ assert_raise(NameError) do
+ undef :non_existing_method
+ end
+end