summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-array-ext/test
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-04-24 22:28:27 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-04-24 22:28:27 +0900
commit39c036ab037b13d62149f4736ae7808e411d0029 (patch)
tree0b124068ad8eaa6e9d8b3cc14776dfc68464bb87 /mrbgems/mruby-array-ext/test
parentfdcea862ee622e3e25eddef5b0d83335bf24906a (diff)
parent4652c7caa04721d1c0b4231fd142e57183bd5d4e (diff)
downloadmruby-39c036ab037b13d62149f4736ae7808e411d0029.tar.gz
mruby-39c036ab037b13d62149f4736ae7808e411d0029.zip
Merge pull request #2115 from ksss/ary-fill
Fix Array#fill bug and behavior
Diffstat (limited to 'mrbgems/mruby-array-ext/test')
-rw-r--r--mrbgems/mruby-array-ext/test/array.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb
index d15ea2a64..a82fb08b3 100644
--- a/mrbgems/mruby-array-ext/test/array.rb
+++ b/mrbgems/mruby-array-ext/test/array.rb
@@ -125,14 +125,31 @@ end
assert("Array#fill") do
a = [ "a", "b", "c", "d" ]
assert_equal ["x", "x", "x", "x"], a.fill("x")
- assert_equal ["x", "x", "x", "w"], a.fill("w", -1)
+ assert_equal ["x", "x", "x", "w"], a.fill("w", -1)
assert_equal ["x", "x", "z", "z"], a.fill("z", 2, 2)
assert_equal ["y", "y", "z", "z"], a.fill("y", 0..1)
- assert_equal [0, 1, 4, 9], a.fill { |i| i*i }
+ assert_equal [0, 1, 4, 9], a.fill { |i| i*i }
assert_equal [0, 1, 8, 27], a.fill(-2) { |i| i*i*i }
assert_equal [0, 2, 3, 27], a.fill(1, 2) { |i| i+1 }
assert_equal [1, 2, 3, 27], a.fill(0..1) { |i| i+1 }
assert_raise(ArgumentError) { a.fill }
+
+ assert_equal([0, 1, 2, 3, -1, 5], [0, 1, 2, 3, 4, 5].fill(-1, -2, 1))
+ assert_equal([0, 1, 2, 3, -1, -1, -1], [0, 1, 2, 3, 4, 5].fill(-1, -2, 3))
+ assert_equal([0, 1, 2, -1, -1, 5], [0, 1, 2, 3, 4, 5].fill(-1, 3..4))
+ assert_equal([0, 1, 2, -1, 4, 5], [0, 1, 2, 3, 4, 5].fill(-1, 3...4))
+ assert_equal([0, 1, -1, -1, -1, 5], [0, 1, 2, 3, 4, 5].fill(-1, 2..-2))
+ assert_equal([0, 1, -1, -1, 4, 5], [0, 1, 2, 3, 4, 5].fill(-1, 2...-2))
+ assert_equal([0, 1, 2, 13, 14, 5], [0, 1, 2, 3, 4, 5].fill(3..4){|i| i+10})
+ assert_equal([0, 1, 2, 13, 4, 5], [0, 1, 2, 3, 4, 5].fill(3...4){|i| i+10})
+ assert_equal([0, 1, 12, 13, 14, 5], [0, 1, 2, 3, 4, 5].fill(2..-2){|i| i+10})
+ assert_equal([0, 1, 12, 13, 4, 5], [0, 1, 2, 3, 4, 5].fill(2...-2){|i| i+10})
+
+ assert_equal [1, 2, 3, 4, 'x', 'x'], [1, 2, 3, 4, 5, 6].fill('x', -2..-1)
+ assert_equal [1, 2, 3, 4, 'x', 6], [1, 2, 3, 4, 5, 6].fill('x', -2...-1)
+ assert_equal [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6].fill('x', -2...-2)
+ assert_equal [1, 2, 3, 4, 'x', 6], [1, 2, 3, 4, 5, 6].fill('x', -2..-2)
+ assert_equal [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6].fill('x', -2..0)
end
assert("Array#reverse_each") do