From e129a4c8ef5b9bffc696202a73575c8ead187175 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 2 Apr 2013 11:37:58 +0900 Subject: Add test cases. --- test/t/array.rb | 16 +++++++++++++++- test/t/class.rb | 20 ++++++++++++++++++++ test/t/hash.rb | 13 ++++++++++++- test/t/module.rb | 15 +++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/test/t/array.rb b/test/t/array.rb index 90fa85c7f..47259c268 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -272,7 +272,7 @@ assert('Array#unshift', '15.2.12.5.30') do a == [1,2,3] and b == [1,2,3] and c == [0,1,2,3] and d == [0,1,2,3] end -assert('Array#to_s', '15.2.12.5.31') do +assert('Array#to_s', '15.2.12.5.31 / 15.2.12.5.32') do a = [2, 3, 4, 5] r1 = a.to_s r2 = a.inspect @@ -288,6 +288,20 @@ assert('Array#==', '15.2.12.5.33') do r1 == false and r2 == true and r3 == false end +assert('Array#eql?', '15.2.12.5.34') do + a1 = [ 1, 2, 3 ] + a2 = [ 1, 2, 3 ] + a3 = [ 1.0, 2.0, 3.0 ] + + (a1.eql? a2) and (not a1.eql? a3) +end + +assert('Array#hash', '15.2.12.5.35') do + a = [ 1, 2, 3 ] + + a.hash.is_a? Integer +end + assert('Array#<=>', '15.2.12.5.36') do r1 = [ "a", "a", "c" ] <=> [ "a", "b", "c" ] #=> -1 r2 = [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1 diff --git a/test/t/class.rb b/test/t/class.rb index 1c50853dc..72214a2fc 100644 --- a/test/t/class.rb +++ b/test/t/class.rb @@ -9,6 +9,26 @@ assert('Class superclass', '15.2.3.2') do Class.superclass == Module end +# Class#initialize '15.2.3.3.1' is tested in Class#new + +assert('Class#initialize_copy', '15.2.3.3.2') do + class TestClass + attr_accessor :n + def initialize(n) + @n = n + end + def initialize_copy(obj) + @n = n + end + end + + c1 = TestClass.new('Foo') + c2 = c1.dup + c3 = TestClass.new('Bar') + + c1.n == c2.n and c1.n != c3.n +end + assert('Class#new', '15.2.3.3.3') do # at the moment no exception on singleton class #e1 = nil diff --git a/test/t/hash.rb b/test/t/hash.rb index 04a9a1c24..5ba476e40 100644 --- a/test/t/hash.rb +++ b/test/t/hash.rb @@ -138,7 +138,18 @@ assert('Hash#include?', '15.2.13.4.15') do a.include?('abc_key') and not b.include?('cba') end -assert('Hash#initialize copy', '15.2.13.4.17') do +assert('Hash#initialize', '15.2.13.4.16') do + # Testing initialize by new. + h = Hash.new + h2 = Hash.new(:not_found) + + h.is_a? Hash and + h == { } and + h["hello"] == nil and + 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) diff --git a/test/t/module.rb b/test/t/module.rb index 6c1c1acda..1ff9d3aea 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -129,6 +129,21 @@ assert('Module#const_get', '15.2.2.4.23') do Test4ConstSet.const_get(:Const4Test4ConstSet) == 23 end +assert('Module.constants', '15.2.2.4.24') do + $n = [] + module TestA + Const = 1 + end + class TestB + include TestA + Const2 = 1 + $n = constants.sort + end + + TestA.constants == [ :Const ] and + $n == [ :Const, :Const2 ] +end + assert('Module#include', '15.2.2.4.27') do module Test4Include Const4Include = 42 -- cgit v1.2.3 From 39bf29411a7b0f6e30bf1e166c961b8175fd71b2 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 2 Apr 2013 11:38:36 +0900 Subject: Add "Comparable" to labels. --- test/t/comparable.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/t/comparable.rb b/test/t/comparable.rb index f3c03a9b5..c95134246 100644 --- a/test/t/comparable.rb +++ b/test/t/comparable.rb @@ -1,5 +1,5 @@ -assert('<', '15.3.3.2.1') do +assert('Comparable#<', '15.3.3.2.1') do class Foo include Comparable def <=>(x) @@ -10,7 +10,7 @@ assert('<', '15.3.3.2.1') do (Foo.new < Foo.new) == false end -assert('<=', '15.3.3.2.2') do +assert('Comparable#<=', '15.3.3.2.2') do class Foo include Comparable def <=>(x) @@ -21,7 +21,7 @@ assert('<=', '15.3.3.2.2') do (Foo.new <= Foo.new) == true end -assert('==', '15.3.3.2.3') do +assert('Comparable#==', '15.3.3.2.3') do class Foo include Comparable def <=>(x) @@ -32,7 +32,7 @@ assert('==', '15.3.3.2.3') do (Foo.new == Foo.new) == true end -assert('>', '15.3.3.2.4') do +assert('Comparable#>', '15.3.3.2.4') do class Foo include Comparable def <=>(x) @@ -43,7 +43,7 @@ assert('>', '15.3.3.2.4') do (Foo.new > Foo.new) == false end -assert('>=', '15.3.3.2.5') do +assert('Comparable#>=', '15.3.3.2.5') do class Foo include Comparable def <=>(x) -- cgit v1.2.3 From c9e19913cffd9191321948fa7035da49a3276aca Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 2 Apr 2013 11:39:35 +0900 Subject: Add comments: eval method is defined in mrbgems. --- test/t/kernel.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/t/kernel.rb b/test/t/kernel.rb index aea687646..57705d61b 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -23,6 +23,8 @@ assert('Kernel.block_given?', '15.3.1.2.2') do ((bg_try do "block" end) == "block") 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 end @@ -189,6 +191,8 @@ assert('Kernel#dup', '15.3.1.3.9') do c.respond_to?(:test) == false end +# Kernel#eval is provided by mruby-eval mrbgem '15.3.1.3.12' + assert('Kernel#extend', '15.3.1.3.13') do class Test4ExtendClass end -- cgit v1.2.3 From 4bb7243c2b9ad9d5e1e84f519ac676300a85428e Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Tue, 2 Apr 2013 11:40:45 +0900 Subject: Add comments: some methods is defined in mrbgems. --- test/t/kernel.rb | 6 ++++++ test/t/string.rb | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 57705d61b..835834359 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -291,6 +291,10 @@ assert('Kernel#object_id', '15.3.1.3.33') do object_id.class == Fixnum end +# Kernel#p is defined in mruby-print mrbgem. '15.3.1.3.34' + +# 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 end @@ -303,6 +307,8 @@ assert('Kernel#public_methods', '15.3.1.3.38') do 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 = [] diff --git a/test/t/string.rb b/test/t/string.rb index ef6b6fae0..5f5f664cf 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -32,7 +32,7 @@ assert('String#==', '15.2.10.5.4') do 'abc' == 'abc' and not 'abc' == 'cba' end -# TODO: SEGFAULT ATM assert('String#=~', '15.2.10.5.5') +# 'String#=~', '15.2.10.5.5' will be tested in mrbgems. assert('String#[]', '15.2.10.5.6') do # length of args is 1 @@ -49,7 +49,7 @@ assert('String#[]', '15.2.10.5.6') do e1 = 'abc'[1, 2] # args is RegExp - # TODO SEGFAULT ATM + # It will be tested in mrbgems. # args is String a3 = 'abc'['bc'] @@ -251,7 +251,7 @@ assert('String#length', '15.2.10.5.26') do 'abc'.length == 3 end -# TODO Broken ATM assert('String#match', '15.2.10.5.27') do +# 'String#match', '15.2.10.5.27' will be tested in mrbgems. assert('String#replace', '15.2.10.5.28') do a = '' @@ -279,7 +279,7 @@ assert('String#rindex', '15.2.10.5.31') do 'abcabc'.rindex('a', 1) == 0 and 'abcabc'.rindex('a', 4) == 3 end -# TODO Broken ATM assert('String#scan', '15.2.10.5.32') do +# 'String#scan', '15.2.10.5.32' will be tested in mrbgems. assert('String#size', '15.2.10.5.33') do 'abc'.size == 3 @@ -303,7 +303,7 @@ assert('String#slice', '15.2.10.5.34') do e11 = e1.slice(0) # args is RegExp - # TODO SEGFAULT ATM + # It will be tested in mrbgems. # args is String a3 = 'abc'.slice('bc') -- cgit v1.2.3