diff options
| author | Masaki Muranaka <[email protected]> | 2013-04-02 11:37:58 +0900 |
|---|---|---|
| committer | Masaki Muranaka <[email protected]> | 2013-04-02 11:43:30 +0900 |
| commit | e129a4c8ef5b9bffc696202a73575c8ead187175 (patch) | |
| tree | 62334a1a44281219d40f478ef929de9bdade2709 /test | |
| parent | 6bd49a3d95c836e82382f333a600a368bf0638fc (diff) | |
| download | mruby-e129a4c8ef5b9bffc696202a73575c8ead187175.tar.gz mruby-e129a4c8ef5b9bffc696202a73575c8ead187175.zip | |
Add test cases.
Diffstat (limited to 'test')
| -rw-r--r-- | test/t/array.rb | 16 | ||||
| -rw-r--r-- | test/t/class.rb | 20 | ||||
| -rw-r--r-- | test/t/hash.rb | 13 | ||||
| -rw-r--r-- | 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 |
