Commit 124fd73c authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

resolve conflict

parents ef5087bc d8c8893e
......@@ -2,36 +2,36 @@
# Hash ISO Test
assert('Hash', '15.2.13') do
Hash.class == Class
assert_equal Hash.class, Class
end
assert('Hash superclass', '15.2.13.2') do
Hash.superclass == Object
assert_equal Hash.superclass, Object
end
assert('Hash#==', '15.2.13.4.1') do
({ 'abc' => 'abc' } == { 'abc' => 'abc' }) and
not ({ 'abc' => 'abc' } == { 'cba' => 'cba' })
assert_true({ 'abc' => 'abc' } == { 'abc' => 'abc' })
assert_false({ 'abc' => 'abc' } == { 'cba' => 'cba' })
end
assert('Hash#[]', '15.2.13.4.2') do
a = { 'abc' => 'abc' }
a['abc'] == 'abc'
assert_equal a['abc'], 'abc'
end
assert('Hash#[]=', '15.2.13.4.3') do
a = Hash.new
a['abc'] = 'abc'
a['abc'] == 'abc'
assert_equal a['abc'], 'abc'
end
assert('Hash#clear', '15.2.13.4.4') do
a = { 'abc' => 'abc' }
a.clear
a == { }
assert_equal a, { }
end
assert('Hash#default', '15.2.13.4.5') do
......@@ -39,15 +39,18 @@ assert('Hash#default', '15.2.13.4.5') do
b = Hash.new('abc')
c = Hash.new {|s,k| s[k] = k}
a.default == nil and b.default == 'abc' and
c.default == nil and c.default('abc') == 'abc'
assert_nil a.default
assert_equal b.default, 'abc'
assert_nil c.default
assert_equal c.default('abc'), 'abc'
end
assert('Hash#default=', '15.2.13.4.6') do
a = { 'abc' => 'abc' }
a.default = 'cba'
a['abc'] == 'abc' and a['notexist'] == 'cba'
assert_equal a['abc'], 'abc'
assert_equal a['notexist'], 'cba'
end
assert('Hash#default_proc', '15.2.13.4.7') do
......@@ -56,8 +59,10 @@ assert('Hash#default_proc', '15.2.13.4.7') do
c = b[2]
d = b['cat']
a.default_proc == nil and b.default_proc.class == Proc and
c = 4 and d = 'catcat'
assert_nil a.default_proc
assert_equal b.default_proc.class, Proc
assert_equal c, 4
assert_equal d, 'catcat'
end
assert('Hash#delete', '15.2.13.4.8') do
......@@ -74,8 +79,10 @@ assert('Hash#delete', '15.2.13.4.8') do
b_tmp_2 = true
end
a.delete('cba') == nil and not a.has_key?('abc') and
not b_tmp_1 and b_tmp_2
assert_nil a.delete('cba')
assert_false a.has_key?('abc')
assert_false b_tmp_1
assert_true b_tmp_2
end
assert('Hash#each', '15.2.13.4.9') do
......@@ -88,7 +95,8 @@ assert('Hash#each', '15.2.13.4.9') do
value = v
end
key == 'abc_key' and value == 'abc_value'
assert_equal key, 'abc_key'
assert_equal value, 'abc_value'
end
assert('Hash#each_key', '15.2.13.4.10') do
......@@ -99,7 +107,7 @@ assert('Hash#each_key', '15.2.13.4.10') do
key = k
end
key == 'abc_key'
assert_equal key, 'abc_key'
end
assert('Hash#each_value', '15.2.13.4.11') do
......@@ -110,35 +118,39 @@ assert('Hash#each_value', '15.2.13.4.11') do
value = v
end
value == 'abc_value'
assert_equal value, 'abc_value'
end
assert('Hash#empty?', '15.2.13.4.12') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new
not a.empty? and b.empty?
assert_false a.empty?
assert_true b.empty?
end
assert('Hash#has_key?', '15.2.13.4.13') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new
a.has_key?('abc_key') and not b.has_key?('cba')
assert_true a.has_key?('abc_key')
assert_false b.has_key?('cba')
end
assert('Hash#has_value?', '15.2.13.4.14') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new
a.has_value?('abc_value') and not b.has_value?('cba')
assert_true a.has_value?('abc_value')
assert_false b.has_value?('cba')
end
assert('Hash#include?', '15.2.13.4.15') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new
a.include?('abc_key') and not b.include?('cba')
assert_true a.include?('abc_key')
assert_false b.include?('cba')
end
assert('Hash#initialize', '15.2.13.4.16') do
......@@ -146,44 +158,47 @@ assert('Hash#initialize', '15.2.13.4.16') do
h = Hash.new
h2 = Hash.new(:not_found)
h.is_a? Hash and
h == { } and
h["hello"] == nil and
h2["hello"] == :not_found
assert_true h.is_a? Hash
assert_equal h, { }
assert_nil h["hello"]
assert_equal h2["hello"], :not_found
end
assert('Hash#initialize_copy', '15.2.13.4.17') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new.initialize_copy(a)
b == { 'abc_key' => 'abc_value' }
assert_equal b, { 'abc_key' => 'abc_value' }
end
assert('Hash#key?', '15.2.13.4.18') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new
a.key?('abc_key') and not b.key?('cba')
assert_true a.key?('abc_key')
assert_false b.key?('cba')
end
assert('Hash#keys', '15.2.13.4.19') do
a = { 'abc_key' => 'abc_value' }
a.keys == ['abc_key']
assert_equal a.keys, ['abc_key']
end
assert('Hash#length', '15.2.13.4.20') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new
a.length == 1 and b.length == 0
assert_equal a.length, 1
assert_equal b.length, 0
end
assert('Hash#member?', '15.2.13.4.21') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new
a.member?('abc_key') and not b.member?('cba')
assert_true a.member?('abc_key')
assert_false b.member?('cba')
end
assert('Hash#merge', '15.2.13.4.22') do
......@@ -195,9 +210,9 @@ assert('Hash#merge', '15.2.13.4.22') do
original
end
result_1 == {'abc_key' => 'abc_value', 'cba_key' => 'XXX',
'xyz_key' => 'xyz_value' } and
result_2 == {'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
assert_equal result_1, {'abc_key' => 'abc_value', 'cba_key' => 'XXX',
'xyz_key' => 'xyz_value' }
assert_equal result_2, {'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
'xyz_key' => 'xyz_value' }
end
......@@ -205,42 +220,44 @@ assert('Hash#replace', '15.2.13.4.23') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new.replace(a)
b == { 'abc_key' => 'abc_value' }
assert_equal b, { 'abc_key' => 'abc_value' }
end
assert('Hash#shift', '15.2.13.4.24') do
a = { 'abc_key' => 'abc_value', 'cba_key' => 'cba_value' }
b = a.shift
a == { 'abc_key' => 'abc_value' } and
b == [ 'cba_key', 'cba_value' ]
assert_equal a, { 'abc_key' => 'abc_value' }
assert_equal b, [ 'cba_key', 'cba_value' ]
end
assert('Hash#size', '15.2.13.4.25') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new
a.size == 1 and b.size == 0
assert_equal a.size, 1
assert_equal b.size, 0
end
assert('Hash#store', '15.2.13.4.26') do
a = Hash.new
a.store('abc', 'abc')
a['abc'] == 'abc'
assert_equal a['abc'], 'abc'
end
assert('Hash#value?', '15.2.13.4.27') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new
a.value?('abc_value') and not b.value?('cba')
assert_true a.value?('abc_value')
assert_false b.value?('cba')
end
assert('Hash#values', '15.2.13.4.28') do
a = { 'abc_key' => 'abc_value' }
a.values == ['abc_value']
assert_equal a.values, ['abc_value']
end
# Not ISO specified
......@@ -250,8 +267,8 @@ assert('Hash#reject') do
ret = h.reject do |k,v|
v % 2 == 0
end
ret == {:one => 1, :three => 3} and
h == {:one => 1, :two => 2, :three => 3, :four => 4}
assert_equal ret, {:one => 1, :three => 3}
assert_equal h, {:one => 1, :two => 2, :three => 3, :four => 4}
end
assert('Hash#reject!') do
......@@ -259,8 +276,8 @@ assert('Hash#reject!') do
ret = h.reject! do |k,v|
v % 2 == 0
end
ret == {:one => 1, :three => 3} and
h == {:one => 1, :three => 3}
assert_equal ret, {:one => 1, :three => 3}
assert_equal h, {:one => 1, :three => 3}
end
assert('Hash#select') do
......@@ -268,8 +285,8 @@ assert('Hash#select') do
ret = h.select do |k,v|
v % 2 == 0
end
ret == {:two => 2, :four => 4} and
h == {:one => 1, :two => 2, :three => 3, :four => 4}
assert_equal ret, {:two => 2, :four => 4}
assert_equal h, {:one => 1, :two => 2, :three => 3, :four => 4}
end
assert('Hash#select!') do
......@@ -277,8 +294,8 @@ assert('Hash#select!') do
ret = h.select! do |k,v|
v % 2 == 0
end
ret == {:two => 2, :four => 4} and
h == {:two => 2, :four => 4}
assert_equal ret, {:two => 2, :four => 4}
assert_equal h, {:two => 2, :four => 4}
end
# Not ISO specified
......@@ -287,5 +304,7 @@ assert('Hash#inspect') do
h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
ret = h.to_s
ret = "{\"c\"=>300, \"a\"=>100, \"d\"=>400}"
assert_include ret, '"c"=>300'
assert_include ret, '"a"=>100'
assert_include ret, '"d"=>400'
end
......@@ -2,39 +2,43 @@
# Integer ISO Test
assert('Integer', '15.2.8') do
Integer.class == Class
assert_equal Integer.class, Class
end
assert('Integer superclass', '15.2.8.2') do
Integer.superclass == Numeric
assert_equal Integer.superclass, Numeric
end
assert('Integer#+', '15.2.8.3.1') do
a = 1+1
b = 1+1.0
a == 2 and b == 2.0
assert_equal a, 2
assert_equal b, 2.0
end
assert('Integer#-', '15.2.8.3.2') do
a = 2-1
b = 2-1.0
a == 1 and b == 1.0
assert_equal a, 1
assert_equal b, 1.0
end
assert('Integer#*', '15.2.8.3.3') do
a = 1*1
b = 1*1.0
a == 1 and b == 1.0
assert_equal a, 1
assert_equal b, 1.0
end
assert('Integer#/', '15.2.8.3.4') do
a = 2/1
b = 2/1.0
a == 2 and b == 2.0
assert_equal a, 2
assert_equal b, 2.0
end
assert('Integer#%', '15.2.8.3.5') do
......@@ -42,7 +46,9 @@ assert('Integer#%', '15.2.8.3.5') do
b = 1%1.0
c = 2%4
a == 0 and b == 0.0 and c == 2
assert_equal a, 0
assert_equal b, 0.0
assert_equal c, 2
end
assert('Integer#<=>', '15.2.8.3.6') do
......@@ -50,19 +56,23 @@ assert('Integer#<=>', '15.2.8.3.6') do
b = 1<=>1
c = 1<=>2
a == 1 and b == 0 and c == -1
assert_equal a, 1
assert_equal b, 0
assert_equal c, -1
end
assert('Integer#==', '15.2.8.3.7') do
a = 1==0
b = 1==1
a == false and b == true
assert_false a
assert_true b
end
assert('Integer#~', '15.2.8.3.8') do
# Complement
~0 == -1 and ~2 == -3
assert_equal ~0, -1
assert_equal ~2, -3
end
assert('Integer#&', '15.2.8.3.9') do
......@@ -70,7 +80,7 @@ assert('Integer#&', '15.2.8.3.9') do
# 0101 (5)
# & 0011 (3)
# = 0001 (1)
5 & 3 == 1
assert_equal 5 & 3, 1
end
assert('Integer#|', '15.2.8.3.10') do
......@@ -78,7 +88,7 @@ assert('Integer#|', '15.2.8.3.10') do
# 0101 (5)
# | 0011 (3)
# = 0111 (7)
5 | 3 == 7
assert_equal 5 | 3, 7
end
assert('Integer#^', '15.2.8.3.11') do
......@@ -86,25 +96,25 @@ assert('Integer#^', '15.2.8.3.11') do
# 0101 (5)
# ^ 0011 (3)
# = 0110 (6)
5 ^ 3 == 6
assert_equal 5 ^ 3, 6
end
assert('Integer#<<', '15.2.8.3.12') do
# Left Shift by one
# 00010111 (23)
# = 00101110 (46)
23 << 1 == 46
assert_equal 23 << 1, 46
end
assert('Integer#>>', '15.2.8.3.13') do
# Right Shift by one
# 00101110 (46)
# = 00010111 (23)
46 >> 1 == 23
assert_equal 46 >> 1, 23
end
assert('Integer#ceil', '15.2.8.3.14') do
10.ceil == 10
assert_equal 10.ceil, 10
end
assert('Integer#downto', '15.2.8.3.15') do
......@@ -112,7 +122,7 @@ assert('Integer#downto', '15.2.8.3.15') do
3.downto(1) do |i|
a += i
end
a == 6
assert_equal a, 6
end
assert('Integer#eql?', '15.2.8.3.16') do
......@@ -120,25 +130,27 @@ assert('Integer#eql?', '15.2.8.3.16') do
b = 1.eql?(2)
c = 1.eql?(nil)
a == true and b == false and c == false
assert_true a
assert_false b
assert_false c
end
assert('Integer#floor', '15.2.8.3.17') do
a = 1.floor
a == 1
assert_equal a, 1
end
assert('Integer#next', '15.2.8.3.19') do
1.next == 2
assert_equal 1.next, 2
end
assert('Integer#round', '15.2.8.3.20') do
1.round == 1
assert_equal 1.round, 1
end
assert('Integer#succ', '15.2.8.3.21') do
1.succ == 2
assert_equal 1.succ, 2
end
assert('Integer#times', '15.2.8.3.22') do
......@@ -146,23 +158,24 @@ assert('Integer#times', '15.2.8.3.22') do
3.times do
a += 1
end
a == 3
assert_equal a, 3
end
assert('Integer#to_f', '15.2.8.3.23') do
1.to_f == 1.0
assert_equal 1.to_f, 1.0
end
assert('Integer#to_i', '15.2.8.3.24') do
1.to_i == 1
assert_equal 1.to_i, 1
end
assert('Integer#to_s', '15.2.8.3.25') do
1.to_s == '1' and -1.to_s == "-1"
assert_equal 1.to_s, '1'
assert_equal(-1.to_s, "-1")
end
assert('Integer#truncate', '15.2.8.3.26') do
1.truncate == 1
assert_equal 1.truncate, 1
end
assert('Integer#upto', '15.2.8.3.27') do
......@@ -170,7 +183,7 @@ assert('Integer#upto', '15.2.8.3.27') do
1.upto(3) do |i|
a += i
end
a == 6
assert_equal a, 6
end
# Not ISO specified
......@@ -185,6 +198,6 @@ assert('Integer#step') do
b << i
end
a == [1, 2, 3] and
b == [1, 3, 5]
assert_equal a, [1, 2, 3]
assert_equal b, [1, 3, 5]
end
......@@ -2,7 +2,7 @@
# Kernel ISO Test
assert('Kernel', '15.3.1') do
Kernel.class == Module
assert_equal Kernel.class, Module
end
assert('Kernel.block_given?', '15.3.1.2.2') do
......@@ -14,23 +14,29 @@ assert('Kernel.block_given?', '15.3.1.2.2') do
end
end
(Kernel.block_given? == false) and
assert_false Kernel.block_given?
# test without block
(bg_try == "no block") and
assert_equal bg_try, "no block"
# test with block
((bg_try { "block" }) == "block") and
assert_equal "block" do
bg_try { "block" }
end
# test with block
((bg_try do "block" end) == "block")
assert_equal "block" do
bg_try do
"block"
end
end
end
# Kernel.eval is provided by the mruby-gem mrbgem. '15.3.1.2.3'
assert('Kernel.global_variables', '15.3.1.2.4') do
Kernel.global_variables.class == Array
assert_equal Kernel.global_variables.class, Array
end
assert('Kernel.iterator?', '15.3.1.2.5') do
Kernel.iterator? == false
assert_false Kernel.iterator?
end
assert('Kernel.lambda', '15.3.1.2.6') do
......@@ -40,7 +46,10 @@ assert('Kernel.lambda', '15.3.1.2.6') do
m = Kernel.lambda(&l)
l.call and l.class == Proc and m.call and m.class == Proc
assert_true l.call
assert_equal l.class, Proc
assert_true m.call
assert_equal m.class, Proc
end
# Not implemented at the moment
......@@ -56,47 +65,36 @@ assert('Kernel.loop', '15.3.1.2.8') do
break if i == 100
end
i == 100
assert_equal i, 100
end
assert('Kernel.p', '15.3.1.2.9') do
# TODO search for a way to test p to stdio
true
assert_true true
end
assert('Kernel.print', '15.3.1.2.10') do
# TODO search for a way to test print to stdio
true
assert_true true
end
assert('Kernel.puts', '15.3.1.2.11') do
# TODO search for a way to test puts to stdio
true
assert_true true
end
assert('Kernel.raise', '15.3.1.2.12') do
e_list = []
begin
assert_raise RuntimeError do
Kernel.raise
rescue => e
e_list << e
end
begin
assert_raise RuntimeError do
Kernel.raise RuntimeError.new
rescue => e
e_list << e
end
# result without argument
e_list[0].class == RuntimeError and
# result with RuntimeError argument
e_list[1].class == RuntimeError
end
assert('Kernel#__id__', '15.3.1.3.3') do
__id__.class == Fixnum
assert_equal __id__.class, Fixnum
end
assert('Kernel#__send__', '15.3.1.3.4') do
......@@ -105,11 +103,12 @@ assert('Kernel#__send__', '15.3.1.3.4') do
true
end
l.call and l.class == Proc and
assert_true l.call
assert_equal l.class, Proc
# test with argument
__send__(:respond_to?, :nil?) and
assert_true __send__(:respond_to?, :nil?)
# test without argument and without block
__send__(:public_methods).class == Array
assert_equal __send__(:public_methods).class, Array
end
assert('Kernel#block_given?', '15.3.1.3.6') do
......@@ -121,14 +120,20 @@ assert('Kernel#block_given?', '15.3.1.3.6') do
end
end
(block_given? == false) and
(bg_try == "no block") and
((bg_try { "block" }) == "block") and
((bg_try do "block" end) == "block")
assert_false block_given?
assert_equal bg_try, "no block"
assert_equal "block" do
bg_try { "block" }
end
assert_equal "block" do
bg_try do
"block"
end
end
end
assert('Kernel#class', '15.3.1.3.7') do
Kernel.class == Module
assert_equal Kernel.class, Module
end
assert('Kernel#clone', '15.3.1.3.8') do
......@@ -165,10 +170,12 @@ assert('Kernel#clone', '15.3.1.3.8') do
end
end
a.get == 2 and b.get == 1 and c.get == 2 &&
a.respond_to?(:test) == true and
b.respond_to?(:test) == false and
c.respond_to?(:test) == true
assert_equal a.get, 2
assert_equal b.get, 1
assert_equal c.get, 2
assert_true a.respond_to?(:test)
assert_false b.respond_to?(:test)
assert_true c.respond_to?(:test)
end
assert('Kernel#dup', '15.3.1.3.9') do
......@@ -205,11 +212,13 @@ assert('Kernel#dup', '15.3.1.3.9') do
end
end
error_count == immutables.size and
a.get == 2 and b.get == 1 and c.get == 2 and
a.respond_to?(:test) == true and
b.respond_to?(:test) == false and
c.respond_to?(:test) == false
assert_equal error_count, immutables.size
assert_equal a.get, 2
assert_equal b.get, 1
assert_equal c.get, 2
assert_true a.respond_to?(:test)
assert_false b.respond_to?(:test)
assert_false c.respond_to?(:test)
end
# Kernel#eval is provided by mruby-eval mrbgem '15.3.1.3.12'
......@@ -226,7 +235,8 @@ assert('Kernel#extend', '15.3.1.3.13') do
a.extend(Test4ExtendModule)
b = Test4ExtendClass.new
a.respond_to?(:test_method) == true && b.respond_to?(:test_method) == false
assert_true a.respond_to?(:test_method)
assert_false b.respond_to?(:test_method)
end
assert('Kernel#extend works on toplevel', '15.3.1.3.13') do
......@@ -236,20 +246,22 @@ assert('Kernel#extend works on toplevel', '15.3.1.3.13') do
# This would crash...
extend(Test4ExtendModule)
respond_to?(:test_method) == true
assert_true respond_to?(:test_method)
end
assert('Kernel#global_variables', '15.3.1.3.14') do
global_variables.class == Array
assert_equal global_variables.class, Array
end
assert('Kernel#hash', '15.3.1.3.15') do
hash == hash
assert_equal hash, hash
end
assert('Kernel#inspect', '15.3.1.3.17') do
s = inspect
s.class == String and s == "main"
assert_equal s.class, String
assert_equal s, "main"
end
assert('Kernel#instance_variables', '15.3.1.3.23') do
......@@ -259,19 +271,25 @@ assert('Kernel#instance_variables', '15.3.1.3.23') do
@b = 12
end
ivars = o.instance_variables
ivars.class == Array and ivars.size == 2 and ivars.include?(:@a) and ivars.include?(:@b)
assert_equal ivars.class, Array
assert_equal ivars.size, 2
assert_true ivars.include?(:@a)
assert_true ivars.include?(:@b)
end
assert('Kernel#is_a?', '15.3.1.3.24') do
is_a?(Kernel) and not is_a?(Array)
assert_true is_a?(Kernel)
assert_false is_a?(Array)
end
assert('Kernel#iterator?', '15.3.1.3.25') do
iterator? == false
assert_false iterator?
end
assert('Kernel#kind_of?', '15.3.1.3.26') do
kind_of?(Kernel) and not kind_of?(Array)
assert_true kind_of?(Kernel)
assert_false kind_of?(Array)
end
assert('Kernel#lambda', '15.3.1.3.27') do
......@@ -281,7 +299,10 @@ assert('Kernel#lambda', '15.3.1.3.27') do
m = lambda(&l)
l.call and l.class == Proc and m.call and m.class == Proc
assert_true l.call
assert_equal l.class, Proc
assert_true m.call
assert_equal m.class, Proc
end
# Not implemented yet
......@@ -297,19 +318,19 @@ assert('Kernel#loop', '15.3.1.3.29') do
break if i == 100
end
i == 100
assert_equal i, 100
end
assert('Kernel#methods', '15.3.1.3.31') do
methods.class == Array
assert_equal methods.class, Array
end
assert('Kernel#nil?', '15.3.1.3.32') do
nil? == false
assert_false nil?
end
assert('Kernel#object_id', '15.3.1.3.33') do
object_id.class == Fixnum
assert_equal object_id.class, Fixnum
end
# Kernel#p is defined in mruby-print mrbgem. '15.3.1.3.34'
......@@ -317,45 +338,32 @@ end
# Kernel#print is defined in mruby-print mrbgem. '15.3.1.3.35'
assert('Kernel#private_methods', '15.3.1.3.36') do
private_methods.class == Array
assert_equal private_methods.class, Array
end
assert('Kernel#protected_methods', '15.3.1.3.37') do
protected_methods.class == Array
assert_equal protected_methods.class, Array
end
assert('Kernel#public_methods', '15.3.1.3.38') do
public_methods.class == Array
assert_equal public_methods.class, Array
end
# Kernel#puts is defined in mruby-print mrbgem. '15.3.1.3.39'
assert('Kernel#raise', '15.3.1.3.40') do
e_list = []
begin
assert_raise RuntimeError do
raise
rescue => e
e_list << e
end
begin
assert_raise RuntimeError do
raise RuntimeError.new
rescue => e
e_list << e
end
# result without argument
e_list[0].class == RuntimeError and
# result with RuntimeError argument
e_list[1].class == RuntimeError
end
# Kernel#require is defined in mruby-require. '15.3.1.3.42'
assert('Kernel#respond_to?', '15.3.1.3.43') do
e_list = []
class Test4RespondTo
def valid_method; end
......@@ -363,17 +371,14 @@ assert('Kernel#respond_to?', '15.3.1.3.43') do
undef test_method
end
begin
assert_raise TypeError do
Test4RespondTo.new.respond_to?(1)
rescue => e
e_list << e.class
end
e_list[0] == TypeError and
respond_to?(:nil?) and
Test4RespondTo.new.respond_to?(:valid_method) == true and
Test4RespondTo.new.respond_to?('valid_method') == true and
Test4RespondTo.new.respond_to?(:test_method) == false
assert_true respond_to?(:nil?)
assert_true Test4RespondTo.new.respond_to?(:valid_method)
assert_true Test4RespondTo.new.respond_to?('valid_method')
assert_false Test4RespondTo.new.respond_to?(:test_method)
end
assert('Kernel#send', '15.3.1.3.44') do
......@@ -382,19 +387,20 @@ assert('Kernel#send', '15.3.1.3.44') do
true
end
l.call and l.class == Proc and
assert_true l.call
assert_equal l.class, Proc
# test with argument
send(:respond_to?, :nil?) and
assert_true send(:respond_to?, :nil?)
# test without argument and without block
send(:public_methods).class == Array
assert_equal send(:public_methods).class, Array
end
assert('Kernel#singleton_methods', '15.3.1.3.45') do
singleton_methods.class == Array
assert_equal singleton_methods.class, Array
end
assert('Kernel#to_s', '15.3.1.3.46') do
to_s.class == String
assert_equal to_s.class, String
end
assert('Kernel#!=') do
......@@ -402,20 +408,18 @@ assert('Kernel#!=') do
str2 = str1
str3 = "world"
(str1[1] != 'e') == false and
(str1 != str3) == true and
(str2 != str1) == false
assert_false (str1[1] != 'e')
assert_true (str1 != str3)
assert_false (str2 != str1)
end
assert('Kernel#respond_to_missing?') do
class Test4RespondToMissing
def respond_to_missing?(method_name, include_private = false)
method_name == :a_method
end
end
Test4RespondToMissing.new.respond_to?(:a_method) == true and
Test4RespondToMissing.new.respond_to?(:no_method) == false
assert_true Test4RespondToMissing.new.respond_to?(:a_method)
assert_false Test4RespondToMissing.new.respond_to?(:no_method)
end
......@@ -3,34 +3,51 @@
assert('Literals Numerical', '8.7.6.2') do
# signed and unsigned integer
1 == 1 and -1 == -1 and +1 == +1 and
assert_equal 1, 1
assert_equal(-1, -1)
assert_equal(+1, +1)
# signed and unsigned float
1.0 == 1.0 and -1.0 == -1.0 and
assert_equal 1.0, 1.0
assert_equal(-1.0, -1.0)
# binary
0b10000000 == 128 and 0B10000000 == 128
assert_equal 0b10000000, 128
assert_equal 0B10000000, 128
# octal
0o10 == 8 and 0O10 == 8 and 0_10 == 8
assert_equal 0o10, 8
assert_equal 0O10, 8
assert_equal 0_10, 8
# hex
0xff == 255 and 0Xff == 255 and
assert_equal 0xff, 255
assert_equal 0Xff, 255
# decimal
0d999 == 999 and 0D999 == 999 and
# decimal separator
10_000_000 == 10000000 and 1_0 == 10 and
assert_equal 0d999, 999
assert_equal 0D999, 999
# decimal seperator
assert_equal 10_000_000, 10000000
assert_equal 1_0, 10
# integer with exponent
1e1 == 10.0 and 1e-1 == 0.1 and 1e+1 == 10.0
assert_equal 1e1, 10.0
assert_equal 1e-1, 0.1
assert_equal 1e+1, 10.0
# float with exponent
1.0e1 == 10.0 and 1.0e-1 == 0.1 and 1.0e+1 == 10.0
assert_equal 1.0e1, 10.0
assert_equal 1.0e-1, 0.1
assert_equal 1.0e+1, 10.0
end
assert('Literals Strings Single Quoted', '8.7.6.3.2') do
'abc' == 'abc' and '\'' == '\'' and '\\' == '\\'
assert_equal 'abc', 'abc'
assert_equal '\'', '\''
assert_equal '\\', '\\'
end
assert('Literals Strings Double Quoted', '8.7.6.3.3') do
a = "abc"
"abc" == "abc" and "\"" == "\"" and "\\" == "\\" and
"#{a}" == "abc"
assert_equal "abc", "abc"
assert_equal "\"", "\""
assert_equal "\\", "\\"
assert_equal "#{a}", "abc"
end
assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do
......@@ -42,8 +59,13 @@ assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do
f = %q/ab\/c/
g = %q{#{a}}
a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and
e == 'abc' and f == 'ab/c' and g == '#{a}'
assert_equal a, 'abc'
assert_equal b, 'abc'
assert_equal c, 'abc'
assert_equal d, 'abc'
assert_equal e, 'abc'
assert_equal f, 'ab/c'
assert_equal g, '#{a}'
end
assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do
......@@ -55,8 +77,13 @@ assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do
f = %Q/ab\/c/
g = %Q{#{a}}
a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and
e == 'abc' and f == 'ab/c' and g == 'abc'
assert_equal a, 'abc'
assert_equal b, 'abc'
assert_equal c, 'abc'
assert_equal d, 'abc'
assert_equal e, 'abc'
assert_equal f, 'ab/c'
assert_equal g, 'abc'
end
assert('Literals Strings Here documents', '8.7.6.3.6') do
......@@ -114,18 +141,18 @@ KKK
z = <<'ZZZ'
ZZZ
a == "aaa\n" and
b == "bbb\n" and
c == ["c1\n", "c 2\n", "c 3\n"] and
d == "d3DDD\nd\t\nDDD\n\n" and
e == "e\#{1+2}EEE\ne\\t\nEEE\\n\n" and
f == "F\nFFfFFF\nF\n" and
g == " ggg\n" and
h == " hhh\n" and
i == " iii\n" and
j == [" j1j\n", " j2j\n", " j\#{3}j\n"] and
k == 123 and
z == ""
assert_equal a, "aaa\n"
assert_equal b, "bbb\n"
assert_equal c, ["c1\n", "c 2\n", "c 3\n"]
assert_equal d, "d3DDD\nd\t\nDDD\n\n"
assert_equal e, "e\#{1+2}EEE\ne\\t\nEEE\\n\n"
assert_equal f, "F\nFFfFFF\nF\n"
assert_equal g, " ggg\n"
assert_equal h, " hhh\n"
assert_equal i, " iii\n"
assert_equal j, [" j1j\n", " j2j\n", " j\#{3}j\n"]
assert_equal k, 123
assert_equal z, ""
end
assert('Literals Array', '8.7.6.4') do
......@@ -146,15 +173,14 @@ assert('Literals Array', '8.7.6.4') do
d
x\y x\\y x\\\y)
test1 = (a == ['abc3def', '}g'] and
b == ['abc', '5', 'def', '(g'] and
c == ['7'] and
d == ['9'] and
e == [] and
f == ['[ab', 'cd][ef]'] and
g == ['ab', '-11', '22'] and
h == ["a\nb", 'test abc', "c\nd", "xy", "x\\y", "x\\y"]
)
assert_equal a, ['abc3def', '}g']
assert_equal b, ['abc', '5', 'def', '(g']
assert_equal c, ['7']
assert_equal d, ['9']
assert_equal e, []
assert_equal f, ['[ab', 'cd][ef]']
assert_equal g, ['ab', '-11', '22']
assert_equal h, ["a\nb", 'test abc', "c\nd", "xy", "x\\y", "x\\y"]
a = %w{abc#{1+2}def \}g}
b = %w(abc #{2+3} def \(g)
......@@ -173,17 +199,14 @@ d
d
x\y x\\y x\\\y)
test2 = (a == ['abc#{1+2}def', '}g'] and
b == ['abc', '#{2+3}', 'def', '(g'] and
c == ['#{3+4}'] and
d == ['#{4+5}'] and
e == [] and
f == ['[ab', 'cd][ef]'] and
g == ['ab', '#{-1}1', '2#{2}'] and
h == ["a\\nb", "test abc", "c\nd", "x\\y", "x\\y", "x\\\\y"]
)
test1 and test2
assert_equal a, ['abc#{1+2}def', '}g']
assert_equal b, ['abc', '#{2+3}', 'def', '(g']
assert_equal c, ['#{3+4}']
assert_equal d, ['#{4+5}']
assert_equal e, []
assert_equal f, ['[ab', 'cd][ef]']
assert_equal g, ['ab', '#{-1}1', '2#{2}']
assert_equal h, ["a\\nb", "test abc", "c\nd", "x\\y", "x\\y", "x\\\\y"]
end
assert('Literals Array of symbols') do
......@@ -199,14 +222,13 @@ assert('Literals Array of symbols') do
2#{2}
}
test1 = (a == [:'abc3def', :'}g'] and
b == [:'abc', :'5', :'def', :'(g'] and
c == [:'7'] and
d == [:'9'] and
e == [] and
f == [:'[ab', :'cd][ef]'] and
g == [:'ab', :'-11', :'22']
)
assert_equal a, [:'abc3def', :'}g']
assert_equal b, [:'abc', :'5', :'def', :'(g']
assert_equal c, [:'7']
assert_equal d, [:'9']
assert_equal e, []
assert_equal f, [:'[ab', :'cd][ef]']
assert_equal g, [:'ab', :'-11', :'22']
a = %i{abc#{1+2}def \}g}
b = %i(abc #{2+3} def \(g)
......@@ -220,16 +242,13 @@ assert('Literals Array of symbols') do
2#{2}
}
test2 = (a == [:'abc#{1+2}def', :'}g'] and
b == [:'abc', :'#{2+3}', :'def', :'(g'] and
c == [:'#{3+4}'] and
d == [:'#{4+5}'] and
e == [] and
f == [:'[ab', :'cd][ef]'] and
g == [:'ab', :'#{-1}1', :'2#{2}']
)
test1 and test2
assert_equal a, [:'abc#{1+2}def', :'}g']
assert_equal b, [:'abc', :'#{2+3}', :'def', :'(g']
assert_equal c, [:'#{3+4}']
assert_equal d, [:'#{4+5}']
assert_equal e, []
assert_equal f, [:'[ab', :'cd][ef]']
assert_equal g, [:'ab', :'#{-1}1', :'2#{2}']
end
assert('Literals Symbol', '8.7.6.6') do
......@@ -255,10 +274,14 @@ qwe]
g = %s/foo#{1+2}bar/
h = %s{{foo bar}}
a == :'asd qwe' and b == :"foo bar" and c == :a3b and d == :asd and
e == :' foo )' and f == :"asd [\nqwe" and g == :'foo#{1+2}bar' and
h == :'{foo bar}'
assert_equal a, :'asd qwe'
assert_equal b, :"foo bar"
assert_equal c, :a3b
assert_equal d, :asd
assert_equal e, :' foo )'
assert_equal f, :"asd [\nqwe"
assert_equal g, :'foo#{1+2}bar'
assert_equal h, :'{foo bar}'
end
# Not Implemented ATM assert('Literals Regular expression', '8.7.6.5') do
......@@ -2,11 +2,11 @@
# Module ISO Test
assert('Module', '15.2.2') do
Module.class == Class
assert_equal Module.class, Class
end
assert('Module superclass', '15.2.2.2') do
Module.superclass == Object
assert_equal Module.superclass, Object
end
# TODO not implemented ATM assert('Module.constants', '15.2.2.3.1') do
......@@ -18,7 +18,10 @@ assert('Module#ancestors', '15.2.2.4.9') do
end
sc = Test4ModuleAncestors.singleton_class
r = String.ancestors
r.class == Array and r.include?(String) and r.include?(Object)
assert_equal r.class, Array
assert_true r.include?(String)
assert_true r.include?(Object)
end
assert('Module#append_features', '15.2.2.4.10') do
......@@ -31,7 +34,7 @@ assert('Module#append_features', '15.2.2.4.10') do
include Test4AppendFeatures
end
Test4AppendFeatures2.const_get(:Const4AppendFeatures2) == Test4AppendFeatures2
assert_equal Test4AppendFeatures2.const_get(:Const4AppendFeatures2), Test4AppendFeatures2
end
assert('Module#class_eval', '15.2.2.4.15') do
......@@ -44,9 +47,11 @@ assert('Module#class_eval', '15.2.2.4.15') do
end
end
r = Test4ClassEval.instance_methods
Test4ClassEval.class_eval{ @a } == 11 and
Test4ClassEval.class_eval{ @b } == 12 and
r.class == Array and r.include?(:method1)
assert_equal Test4ClassEval.class_eval{ @a }, 11
assert_equal Test4ClassEval.class_eval{ @b }, 12
assert_equal r.class, Array
assert_true r.include?(:method1)
end
assert('Module#class_variable_defined?', '15.2.2.4.16') do
......@@ -54,8 +59,8 @@ assert('Module#class_variable_defined?', '15.2.2.4.16') do
@@cv = 99
end
Test4ClassVariableDefined.class_variable_defined?(:@@cv) and
not Test4ClassVariableDefined.class_variable_defined?(:@@noexisting)
assert_true Test4ClassVariableDefined.class_variable_defined?(:@@cv)
assert_false Test4ClassVariableDefined.class_variable_defined?(:@@noexisting)
end
assert('Module#class_variable_get', '15.2.2.4.17') do
......@@ -63,7 +68,7 @@ assert('Module#class_variable_get', '15.2.2.4.17') do
@@cv = 99
end
Test4ClassVariableGet.class_variable_get(:@@cv) == 99
assert_equal Test4ClassVariableGet.class_variable_get(:@@cv), 99
end
assert('Module#class_variable_set', '15.2.2.4.18') do
......@@ -74,12 +79,11 @@ assert('Module#class_variable_set', '15.2.2.4.18') do
end
end
Test4ClassVariableSet.class_variable_set(:@@cv, 99)
Test4ClassVariableSet.class_variable_set(:@@foo, 101)
Test4ClassVariableSet.class_variables.include? :@@cv and
Test4ClassVariableSet.class_variable_get(:@@cv) == 99 and
Test4ClassVariableSet.new.foo == 101
assert_true Test4ClassVariableSet.class_variable_set(:@@cv, 99)
assert_true Test4ClassVariableSet.class_variable_set(:@@foo, 101)
assert_true Test4ClassVariableSet.class_variables.include? :@@cv
assert_equal Test4ClassVariableSet.class_variable_get(:@@cv), 99
assert_equal Test4ClassVariableSet.new.foo, 101
end
assert('Module#class_variables', '15.2.2.4.19') do
......@@ -90,8 +94,8 @@ assert('Module#class_variables', '15.2.2.4.19') do
@@var2 = 2
end
Test4ClassVariables1.class_variables == [:@@var1] &&
Test4ClassVariables2.class_variables == [:@@var2, :@@var1]
assert_equal Test4ClassVariables1.class_variables, [:@@var1]
assert_equal Test4ClassVariables2.class_variables, [:@@var2, :@@var1]
end
assert('Module#const_defined?', '15.2.2.4.20') do
......@@ -99,8 +103,8 @@ assert('Module#const_defined?', '15.2.2.4.20') do
Const4Test4ConstDefined = true
end
Test4ConstDefined.const_defined?(:Const4Test4ConstDefined) and
not Test4ConstDefined.const_defined?(:NotExisting)
assert_true Test4ConstDefined.const_defined?(:Const4Test4ConstDefined)
assert_false Test4ConstDefined.const_defined?(:NotExisting)
end
assert('Module#const_get', '15.2.2.4.21') do
......@@ -108,7 +112,7 @@ assert('Module#const_get', '15.2.2.4.21') do
Const4Test4ConstGet = 42
end
Test4ConstGet.const_get(:Const4Test4ConstGet) == 42
assert_equal Test4ConstGet.const_get(:Const4Test4ConstGet), 42
end
assert('Module.const_missing', '15.2.2.4.22') do
......@@ -118,7 +122,7 @@ assert('Module.const_missing', '15.2.2.4.22') do
end
end
Test4ConstMissing.const_get(:ConstDoesntExist) == 42
assert_equal Test4ConstMissing.const_get(:ConstDoesntExist), 42
end
assert('Module#const_get', '15.2.2.4.23') do
......@@ -126,8 +130,8 @@ assert('Module#const_get', '15.2.2.4.23') do
Const4Test4ConstSet = 42
end
Test4ConstSet.const_set(:Const4Test4ConstSet, 23)
Test4ConstSet.const_get(:Const4Test4ConstSet) == 23
assert_true Test4ConstSet.const_set(:Const4Test4ConstSet, 23)
assert_equal Test4ConstSet.const_get(:Const4Test4ConstSet), 23
end
assert('Module.constants', '15.2.2.4.24') do
......@@ -141,8 +145,8 @@ assert('Module.constants', '15.2.2.4.24') do
$n = constants.sort
end
TestA.constants == [ :Const ] and
$n == [ :Const, :Const2 ]
assert_equal TestA.constants, [ :Const ]
assert_equal $n, [ :Const, :Const2 ]
end
assert('Module#include', '15.2.2.4.27') do
......@@ -153,7 +157,7 @@ assert('Module#include', '15.2.2.4.27') do
include Test4Include
end
Test4Include2.const_get(:Const4Include) == 42
assert_equal Test4Include2.const_get(:Const4Include), 42
end
assert('Module#include?', '15.2.2.4.28') do
......@@ -165,9 +169,9 @@ assert('Module#include?', '15.2.2.4.28') do
class Test4IncludeP3 < Test4IncludeP2
end
Test4IncludeP2.include?(Test4IncludeP) &&
Test4IncludeP3.include?(Test4IncludeP) &&
! Test4IncludeP.include?(Test4IncludeP)
assert_true Test4IncludeP2.include?(Test4IncludeP)
assert_true Test4IncludeP3.include?(Test4IncludeP)
assert_false Test4IncludeP.include?(Test4IncludeP)
end
assert('Module#included', '15.2.2.4.29') do
......@@ -181,8 +185,8 @@ assert('Module#included', '15.2.2.4.29') do
include Test4Included
end
Test4Included2.const_get(:Const4Included) == 42 and
Test4Included2.const_get(:Const4Included2) == Test4Included2
assert_equal Test4Included2.const_get(:Const4Included), 42
assert_equal Test4Included2.const_get(:Const4Included2), Test4Included2
end
assert('Module#included_modules', '15.2.2.4.30') do
......@@ -191,9 +195,10 @@ assert('Module#included_modules', '15.2.2.4.30') do
module Test4includedModules2
include Test4includedModules
end
r = Test4includedModules2.included_modules
r.class == Array and r.include?(Test4includedModules)
assert_equal r.class, Array
assert_true r.include?(Test4includedModules)
end
assert('Module#instance_methods', '15.2.2.4.33') do
......@@ -209,10 +214,12 @@ assert('Module#instance_methods', '15.2.2.4.33') do
r = Test4InstanceMethodsC.instance_methods(true)
Test4InstanceMethodsA.instance_methods == [:method1] and
Test4InstanceMethodsB.instance_methods(false) == [:method2] and
Test4InstanceMethodsC.instance_methods(false) == [:method3] and
r.class == Array and r.include?(:method3) and r.include?(:method2)
assert_equal Test4InstanceMethodsA.instance_methods, [:method1]
assert_equal Test4InstanceMethodsB.instance_methods(false), [:method2]
assert_equal Test4InstanceMethodsC.instance_methods(false), [:method3]
assert_equal r.class, Array
assert_true r.include?(:method3)
assert_true r.include?(:method2)
end
assert('Module#method_defined?', '15.2.2.4.34') do
......@@ -231,11 +238,11 @@ assert('Module#method_defined?', '15.2.2.4.34') do
end
end
Test4MethodDefined::A.method_defined? :method1 and
Test4MethodDefined::C.method_defined? :method1 and
Test4MethodDefined::C.method_defined? "method2" and
Test4MethodDefined::C.method_defined? "method3" and
not Test4MethodDefined::C.method_defined? "method4"
assert_true Test4MethodDefined::A.method_defined? :method1
assert_true Test4MethodDefined::C.method_defined? :method1
assert_true Test4MethodDefined::C.method_defined? "method2"
assert_true Test4MethodDefined::C.method_defined? "method3"
assert_false Test4MethodDefined::C.method_defined? "method4"
end
......@@ -244,8 +251,9 @@ assert('Module#module_eval', '15.2.2.4.35') do
@a = 11
@b = 12
end
Test4ModuleEval.module_eval{ @a } == 11 and
Test4ModuleEval.module_eval{ @b } == 12
assert_equal Test4ModuleEval.module_eval{ @a }, 11
assert_equal Test4ModuleEval.module_eval{ @b }, 12
end
assert('Module#remove_class_variable', '15.2.2.4.39') do
......@@ -253,8 +261,8 @@ assert('Module#remove_class_variable', '15.2.2.4.39') do
@@cv = 99
end
Test4RemoveClassVariable.remove_class_variable(:@@cv) == 99 and
not Test4RemoveClassVariable.class_variables.include? :@@cv
assert_equal Test4RemoveClassVariable.remove_class_variable(:@@cv), 99
assert_false Test4RemoveClassVariable.class_variables.include? :@@cv
end
assert('Module#remove_const', '15.2.2.4.40') do
......@@ -272,11 +280,11 @@ assert('Module#remove_const', '15.2.2.4.40') do
end
# Constant removed from Module
not Test4RemoveConst.const_defined? :ExistingConst and
assert_false Test4RemoveConst.const_defined? :ExistingConst
# Return value of binding
result == 23 and
assert_equal result, 23
# Name Error raised when Constant doesn't exist
name_error
assert_true name_error
end
assert('Module#remove_method', '15.2.2.4.41') do
......@@ -292,10 +300,9 @@ assert('Module#remove_method', '15.2.2.4.41') do
end
end
Test4RemoveMethod::Child.class_eval{ remove_method :hello }
Test4RemoveMethod::Child.instance_methods.include? :hello and
not Test4RemoveMethod::Child.instance_methods(false).include? :hello
assert_true Test4RemoveMethod::Child.class_eval{ remove_method :hello }
assert_true Test4RemoveMethod::Child.instance_methods.include? :hello
assert_false Test4RemoveMethod::Child.instance_methods(false).include? :hello
end
assert('Module.undef_method', '15.2.2.4.42') do
......@@ -313,27 +320,25 @@ assert('Module.undef_method', '15.2.2.4.42') do
class GrandChild < Child
end
end
Test4UndefMethod::Child.class_eval{ undef_method :hello }
Test4UndefMethod::Parent.new.respond_to?(:hello) and
not Test4UndefMethod::Child.new.respond_to?(:hello) and
not Test4UndefMethod::GrandChild.new.respond_to?(:hello)
assert_true Test4UndefMethod::Parent.new.respond_to?(:hello)
assert_false Test4UndefMethod::Child.new.respond_to?(:hello)
assert_false Test4UndefMethod::GrandChild.new.respond_to?(:hello)
end
# Not ISO specified
assert('Module#to_s') do
module Test4to_sModules
end
Test4to_sModules.to_s == 'Test4to_sModules'
assert_equal Test4to_sModules.to_s, 'Test4to_sModules'
end
assert('Module#inspect') do
module Test4to_sModules
end
Test4to_sModules.inspect == 'Test4to_sModules'
assert_equal Test4to_sModules.inspect, 'Test4to_sModules'
end
......@@ -2,66 +2,73 @@
# Range ISO Test
assert('Range', '15.2.14') do
Range.class == Class
assert_equal Range.class, Class
end
assert('Range superclass', '15.2.14.2') do
Range.superclass == Object
assert_equal Range.superclass, Object
end
assert('Range#==', '15.2.14.4.1') do
(1..10) == (1..10) and not (1..10) == (1..100)
assert_true (1..10) == (1..10)
assert_false (1..10) == (1..100)
end
assert('Range#===', '15.2.14.4.2') do
a = (1..10)
a === 5 and not a === 20
assert_true a === 5
assert_false a === 20
end
assert('Range#begin', '15.2.14.4.3') do
(1..10).begin == 1
assert_equal (1..10).begin, 1
end
assert('Range#each', '15.2.14.4.4') do
a = (1..3)
b = 0
a.each {|i| b += i}
b == 6
assert_equal b, 6
end
assert('Range#end', '15.2.14.4.5') do
(1..10).end == 10
assert_equal (1..10).end, 10
end
assert('Range#exclude_end?', '15.2.14.4.6') do
(1...10).exclude_end? and not (1..10).exclude_end?
assert_true (1...10).exclude_end?
assert_false (1..10).exclude_end?
end
assert('Range#first', '15.2.14.4.7') do
(1..10).first == 1
assert_equal (1..10).first, 1
end
assert('Range#include', '15.2.14.4.8') do
a = (1..10)
a.include?(5) and not a.include?(20)
assert_true a.include?(5)
assert_false a.include?(20)
end
assert('Range#initialize', '15.2.14.4.9') do
a = Range.new(1, 10, true)
b = Range.new(1, 10, false)
a == (1...10) and a.exclude_end? and b == (1..10) and
not b.exclude_end?
assert_equal a, (1...10)
assert_true a.exclude_end?
assert_equal b, (1..10)
assert_false b.exclude_end?
end
assert('Range#last', '15.2.14.4.10') do
(1..10).last == 10
assert_equal (1..10).last, 10
end
assert('Range#member?', '15.2.14.4.11') do
a = (1..10)
a.member?(5) and not a.member?(20)
assert_true a.member?(5)
assert_false a.member?(20)
end
......@@ -2,19 +2,19 @@
# String ISO Test
assert('String', '15.2.10') do
String.class == Class
assert_equal String.class, Class
end
assert('String superclass', '15.2.10.2') do
String.superclass == Object
assert_equal String.superclass, Object
end
assert('String#*', '15.2.10.5.1') do
'a' * 5 == 'aaaaa'
assert_equal 'a' * 5, 'aaaaa'
end
assert('String#+', '15.2.10.5.2') do
'a' + 'b' == 'ab'
assert_equal 'a' + 'b', 'ab'
end
assert('String#<=>', '15.2.10.5.3') do
......@@ -24,12 +24,16 @@ assert('String#<=>', '15.2.10.5.3') do
d = 'abc' <=> 'cba'
e = 'cba' <=> 'abc'
a == 0 and b == -1 and c == 1 and
d == -1 and e == 1
assert_equal a, 0
assert_equal b, -1
assert_equal c, 1
assert_equal d, -1
assert_equal e, 1
end
assert('String#==', '15.2.10.5.4') do
'abc' == 'abc' and not 'abc' == 'cba'
assert_equal 'abc', 'abc'
assert_not_equal 'abc', 'cba'
end
# 'String#=~', '15.2.10.5.5' will be tested in mrbgems.
......@@ -55,10 +59,17 @@ assert('String#[]', '15.2.10.5.6') do
a3 = 'abc'['bc']
b3 = 'abc'['XX']
a == 'a' and b == 'c' and c == nil and d == nil and
a1 == nil and b1 == nil and c1 == nil and d1 == '' and
e1 == 'bc' and
a3 == 'bc' and b3 == nil
assert_equal a, 'a'
assert_equal b, 'c'
assert_nil c
assert_nil d
assert_nil a1
assert_nil b1
assert_nil c1
assert_equal d1, ''
assert_equal e1, 'bc'
assert_equal a3, 'bc'
assert_nil b3
end
assert('String#[] with Range') do
......@@ -81,24 +92,39 @@ assert('String#[] with Range') do
h2 = 'abc'[3...4]
i2 = 'abc'[4...5]
a1 == '' and b1 == 'b' and c1 == 'bc' and d1 == 'bc' and e1 == 'bc' and
f1 == 'ab' and g1 == 'bc' and h1 == '' and i2 == nil and
a2 == '' and b2 == '' and c2 == 'b' and d2 == 'bc' and e2 == 'bc' and
f2 == 'a' and g2 == 'bc' and h2 == '' and i2 == nil
assert_equal a1, ''
assert_equal b1, 'b'
assert_equal c1, 'bc'
assert_equal d1, 'bc'
assert_equal e1, 'bc'
assert_equal f1, 'ab'
assert_equal g1, 'bc'
assert_equal h1, ''
assert_nil i2
assert_equal a2, ''
assert_equal b2, ''
assert_equal c2, 'b'
assert_equal d2, 'bc'
assert_equal e2, 'bc'
assert_equal f2, 'a'
assert_equal g2, 'bc'
assert_equal h2, ''
assert_nil i2
end
assert('String#capitalize', '15.2.10.5.7') do
a = 'abc'
a.capitalize
a == 'abc' and 'abc'.capitalize == 'Abc'
assert_equal a, 'abc'
assert_equal 'abc'.capitalize, 'Abc'
end
assert('String#capitalize!', '15.2.10.5.8') do
a = 'abc'
a.capitalize!
a == 'Abc'
assert_equal a, 'Abc'
end
assert('String#chomp', '15.2.10.5.9') do
......@@ -111,8 +137,12 @@ assert('String#chomp', '15.2.10.5.9') do
f.chomp
a == 'abc' and b == '' and c == 'abc' and
d == "abc\n" and e == 'abc' and f == "abc\n"
assert_equal a, 'abc'
assert_equal b, ''
assert_equal c, 'abc'
assert_equal d, "abc\n"
assert_equal e, 'abc'
assert_equal f, "abc\n"
end
assert('String#chomp!', '15.2.10.5.10') do
......@@ -128,8 +158,11 @@ assert('String#chomp!', '15.2.10.5.10') do
d.chomp!
e.chomp!("\t")
a == 'abc' and b == '' and c == 'abc' and
d == "abc\n" and e == 'abc'
assert_equal a, 'abc'
assert_equal b, ''
assert_equal c, 'abc'
assert_equal d, "abc\n"
assert_equal e, 'abc'
end
assert('String#chop', '15.2.10.5.11') do
......@@ -139,7 +172,9 @@ assert('String#chop', '15.2.10.5.11') do
c.chop
a == '' and b == 'ab' and c == 'abc'
assert_equal a, ''
assert_equal b, 'ab'
assert_equal c, 'abc'
end
assert('String#chop!', '15.2.10.5.12') do
......@@ -149,7 +184,8 @@ assert('String#chop!', '15.2.10.5.12') do
a.chop!
b.chop!
a == '' and b == 'ab'
assert_equal a, ''
assert_equal b, 'ab'
end
assert('String#downcase', '15.2.10.5.13') do
......@@ -158,7 +194,8 @@ assert('String#downcase', '15.2.10.5.13') do
b.downcase
a == 'abc' and b == 'ABC'
assert_equal a, 'abc'
assert_equal b, 'ABC'
end
assert('String#downcase!', '15.2.10.5.14') do
......@@ -166,7 +203,7 @@ assert('String#downcase!', '15.2.10.5.14') do
a.downcase!
a == 'abc'
assert_equal a, 'abc'
end
assert('String#each_line', '15.2.10.5.15') do
......@@ -178,18 +215,20 @@ assert('String#each_line', '15.2.10.5.15') do
n_list << line
end
list == n_list
assert_equal list, n_list
end
assert('String#empty?', '15.2.10.5.16') do
a = ''
b = 'not empty'
a.empty? and not b.empty?
assert_true a.empty?
assert_false b.empty?
end
assert('String#eql?', '15.2.10.5.17') do
'abc'.eql?('abc') and not 'abc'.eql?('cba')
assert_true 'abc'.eql?('abc')
assert_false 'abc'.eql?('cba')
end
assert('String#gsub', '15.2.10.5.18') do
......@@ -210,45 +249,49 @@ assert('String#gsub!', '15.2.10.5.19') do
b = 'abcabc'
b.gsub!('b') { |w| w.capitalize }
a == 'aBcaBc' && b == 'aBcaBc'
assert_equal a, 'aBcaBc'
assert_equal b, 'aBcaBc'
end
assert('String#hash', '15.2.10.5.20') do
a = 'abc'
a.hash == 'abc'.hash
assert_equal a.hash, 'abc'.hash
end
assert('String#include?', '15.2.10.5.21') do
'abc'.include?(97) and not 'abc'.include?(100) and
'abc'.include?('a') and not 'abc'.include?('d')
assert_true 'abc'.include?(97)
assert_false 'abc'.include?(100)
assert_true 'abc'.include?('a')
assert_false 'abc'.include?('d')
end
assert('String#index', '15.2.10.5.22') do
'abc'.index('a') == 0 and 'abc'.index('d') == nil and
'abcabc'.index('a', 1) == 3
assert_equal 'abc'.index('a'), 0
assert_nil 'abc'.index('d')
assert_equal 'abcabc'.index('a', 1), 3
end
assert('String#initialize', '15.2.10.5.23') do
a = ''
a.initialize('abc')
a == 'abc'
assert_equal a, 'abc'
end
assert('String#initialize_copy', '15.2.10.5.24') do
a = ''
a.initialize_copy('abc')
a == 'abc'
assert_equal a, 'abc'
end
assert('String#intern', '15.2.10.5.25') do
'abc'.intern == :abc
assert_equal 'abc'.intern, :abc
end
assert('String#length', '15.2.10.5.26') do
'abc'.length == 3
assert_equal 'abc'.length, 3
end
# 'String#match', '15.2.10.5.27' will be tested in mrbgems.
......@@ -257,32 +300,36 @@ assert('String#replace', '15.2.10.5.28') do
a = ''
a.replace('abc')
a == 'abc'
assert_equal a, 'abc'
end
assert('String#reverse', '15.2.10.5.29') do
a = 'abc'
a.reverse
a == 'abc' and 'abc'.reverse == 'cba'
assert_equal a, 'abc'
assert_equal 'abc'.reverse, 'cba'
end
assert('String#reverse!', '15.2.10.5.30') do
a = 'abc'
a.reverse!
a == 'cba' and 'abc'.reverse! == 'cba'
assert_equal a, 'cba'
assert_equal 'abc'.reverse!, 'cba'
end
assert('String#rindex', '15.2.10.5.31') do
'abc'.rindex('a') == 0 and 'abc'.rindex('d') == nil and
'abcabc'.rindex('a', 1) == 0 and 'abcabc'.rindex('a', 4) == 3
assert_equal 'abc'.rindex('a'), 0
assert_nil 'abc'.rindex('d')
assert_equal 'abcabc'.rindex('a', 1), 0
assert_equal 'abcabc'.rindex('a', 4), 3
end
# 'String#scan', '15.2.10.5.32' will be tested in mrbgems.
assert('String#size', '15.2.10.5.33') do
'abc'.size == 3
assert_equal 'abc'.size, 3
end
assert('String#slice', '15.2.10.5.34') do
......@@ -309,25 +356,33 @@ assert('String#slice', '15.2.10.5.34') do
a3 = 'abc'.slice('bc')
b3 = 'abc'.slice('XX')
a == 'a' and b == 'c' and c == nil and d == nil and
a1 == nil and b1 == nil and c1 == nil and d1 == '' and
e1 == 'bc' and e11 == 'b' and
a3 == 'bc' and b3 == nil
assert_equal a, 'a'
assert_equal b, 'c'
assert_nil c
assert_nil d
assert_nil a1
assert_nil b1
assert_nil c1
assert_equal d1, ''
assert_equal e1, 'bc'
assert_equal e11, 'b'
assert_equal a3, 'bc'
assert_nil b3
end
# TODO Broken ATM
assert('String#split', '15.2.10.5.35') do
# without RegExp behavior is actually unspecified
'abc abc abc'.split == ['abc', 'abc', 'abc'] and
'a,b,c,,d'.split(',') == ["a", "b", "c", "", "d"] and
'abc abc abc'.split(nil) == ['abc', 'abc', 'abc'] and
'abc'.split("") == ['a', 'b', 'c']
assert_equal 'abc abc abc'.split, ['abc', 'abc', 'abc']
assert_equal 'a,b,c,,d'.split(','), ["a", "b", "c", "", "d"]
assert_equal 'abc abc abc'.split(nil), ['abc', 'abc', 'abc']
assert_equal 'abc'.split(""), ['a', 'b', 'c']
end
assert('String#sub', '15.2.10.5.36') do
'abcabc'.sub('b', 'B') == 'aBcabc' and
'abcabc'.sub('b') { |w| w.capitalize } == 'aBcabc' and
'aa#'.sub('#', '$') == 'aa$'
assert_equal 'abcabc'.sub('b', 'B'), 'aBcabc'
assert_equal 'abcabc'.sub('b') { |w| w.capitalize }, 'aBcabc'
assert_equal 'aa#'.sub('#', '$'), 'aa$'
end
assert('String#sub!', '15.2.10.5.37') do
......@@ -337,7 +392,8 @@ assert('String#sub!', '15.2.10.5.37') do
b = 'abcabc'
b.sub!('b') { |w| w.capitalize }
a == 'aBcabc' && b == 'aBcabc'
assert_equal a, 'aBcabc'
assert_equal b, 'aBcabc'
end
......@@ -347,7 +403,10 @@ assert('String#to_i', '15.2.10.5.38') do
c = 'a'.to_i(16)
d = '100'.to_i(2)
a == 0 and b == 123456789 and c == 10 and d == 4
assert_equal a, 0
assert_equal b, 123456789
assert_equal c, 10
assert_equal d, 4
end
assert('String#to_f', '15.2.10.5.39') do
......@@ -355,16 +414,17 @@ assert('String#to_f', '15.2.10.5.39') do
b = '123456789'.to_f
c = '12345.6789'.to_f
check_float(a, 0.0) and check_float(b, 123456789.0) and
check_float(c, 12345.6789)
assert_float(a, 0.0)
assert_float(b, 123456789.0)
assert_float(c, 12345.6789)
end
assert('String#to_s', '15.2.10.5.40') do
'abc'.to_s == 'abc'
assert_equal 'abc'.to_s, 'abc'
end
assert('String#to_sym', '15.2.10.5.41') do
'abc'.to_sym == :abc
assert_equal 'abc'.to_sym, :abc
end
assert('String#upcase', '15.2.10.5.42') do
......@@ -373,7 +433,8 @@ assert('String#upcase', '15.2.10.5.42') do
b.upcase
a == 'ABC' and b == 'abc'
assert_equal a, 'ABC'
assert_equal b, 'abc'
end
assert('String#upcase!', '15.2.10.5.43') do
......@@ -381,14 +442,14 @@ assert('String#upcase!', '15.2.10.5.43') do
a.upcase!
a == 'ABC'
assert_equal a, 'ABC'
end
# Not ISO specified
assert('String interpolation (mrb_str_concat for shared strings)') do
a = "A" * 32
"#{a}:" == "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:"
assert_equal "#{a}:", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:"
end
assert('Check the usage of a NUL character') do
......@@ -402,7 +463,8 @@ assert('String#bytes') do
str2 = "\xFF"
bytes2 = [0xFF]
str1.bytes == bytes1 and str2.bytes == bytes2
assert_equal str1.bytes, bytes1
assert_equal str2.bytes, bytes2
end
assert('String#each_byte') do
......@@ -412,10 +474,10 @@ assert('String#each_byte') do
str1.each_byte {|b| bytes2 << b }
bytes1 == bytes2
assert_equal bytes1, bytes2
end
assert('String#inspect') do
("\1" * 100).inspect # should not raise an exception - regress #1210
"\0".inspect == "\"\\000\""
assert_equal "\0".inspect, "\"\\000\""
end
assert('super', '11.3.4') do
test = false
begin
assert_raise NoMethodError do
super
rescue NoMethodError
test = true
end
class SuperFoo
......@@ -23,18 +20,14 @@ assert('super', '11.3.4') do
end
end
bar = SuperBar.new
test &&= bar.foo
test &&= (bar.bar(1,2,3) == [1,2,3])
test
assert_true bar.foo
assert_equal bar.bar(1,2,3), [1,2,3]
end
assert('yield', '11.3.5') do
begin
assert_raise LocalJumpError do
yield
rescue LocalJumpError
true
else
false
end
end
......@@ -43,7 +36,10 @@ assert('Abbreviated variable assignment', '11.4.2.3.2') do
b &&= 1
c = 1
c += 2
a == 1 and b == nil and c == 3
assert_equal a, 1
assert_nil b
assert_equal c, 3
end
assert('Nested const reference') do
......@@ -55,8 +51,8 @@ assert('Nested const reference') do
end
end
end
Syntax4Const::CONST1 == "hello world" and
Syntax4Const::Const2.new.const1 == "hello world"
assert_equal Syntax4Const::CONST1, "hello world"
assert_equal Syntax4Const::Const2.new.const1, "hello world"
end
assert('Abbreviated variable assignment as returns') do
......@@ -67,5 +63,5 @@ assert('Abbreviated variable assignment as returns') do
end
end
end
Syntax4AbbrVarAsgnAsReturns::A.new.b == 1
assert_equal Syntax4AbbrVarAsgnAsReturns::A.new.b, 1
end
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