diff options
| author | Paolo Bosetti <[email protected]> | 2012-08-06 15:02:03 +0200 |
|---|---|---|
| committer | Paolo Bosetti <[email protected]> | 2012-08-06 15:02:56 +0200 |
| commit | aa0d2f91447c49363059f2e95cb9023f65a6fbef (patch) | |
| tree | 2cfa325956e62648f2161564adfdf6dddc45b737 /test/t/array.rb | |
| parent | fd097b8aff7b91bd105fc1daec5a4050a947b763 (diff) | |
| parent | 193c98ae540d43d082795fd77ea81a4f6f7fd0f6 (diff) | |
| download | mruby-aa0d2f91447c49363059f2e95cb9023f65a6fbef.tar.gz mruby-aa0d2f91447c49363059f2e95cb9023f65a6fbef.zip | |
Updated Xcode project build settings in conformity with 10.8/Xcode 4.4
Diffstat (limited to 'test/t/array.rb')
| -rw-r--r-- | test/t/array.rb | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/test/t/array.rb b/test/t/array.rb index dba1b035d..cb99cea6a 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -5,6 +5,10 @@ assert('Array', '15.2.12') do Array.class == Class end +assert('Array superclass', '15.2.12.2') do + Array.superclass == Object +end + assert('Array.[]', '15.2.12.4.1') do Array.[](1,2,3) == [1, 2, 3] end @@ -61,6 +65,7 @@ assert('Array#[]=', '15.2.12.5.5') do end [1,2,3].[]=(1,4) == [1, 4, 3] and + [1,2,3].[]=(1,2,3) == [1, 3] and e2.class == ArgumentError and e3.class == ArgumentError end @@ -113,7 +118,24 @@ assert('Array#first', '15.2.12.5.13') do a = [] b = [1,2,3] - a.first == nil and b.first == 1 + e2 = nil + e3 = nil + begin + # this will cause an exception due to the wrong argument + [1,2,3].first(-1) + rescue => e1 + e2 = e1 + end + begin + # 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 end assert('Array#index', '15.2.12.5.14') do @@ -148,7 +170,15 @@ end assert('Array#last', '15.2.12.5.18') do a = [1,2,3] - a.last == 3 and [].last == nil + e2 = nil + begin + # 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 end assert('Array#length', '15.2.12.5.19') do @@ -218,7 +248,9 @@ assert('Array#size', '15.2.12.5.28') do end assert('Array#slice', '15.2.12.5.29') do - [1,2,3].[](1) == 2 + a = "12345".slice(1, 3) + b = a.slice(0) + "#{b}:" == "2:" and [1,2,3].[](1) == 2 end assert('Array#unshift', '15.2.12.5.30') do @@ -228,4 +260,35 @@ assert('Array#unshift', '15.2.12.5.30') do a == [1,2,3] and b == [1,2,3] end +assert('Array#to_s', '15.2.12.5.31') do + a = [2, 3, 4, 5] + r1 = a.to_s + r2 = a.inspect + + r1 == r2 and 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 +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 + + r1 == -1 and r2 == +1 +end + # Not ISO specified + +assert("Array (Shared Array Corruption)") do + a = [ "a", "b", "c", "d", "e", "f" ] + b = a.slice(1, 3) + a.clear + b.clear +end + |
