summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-01 07:38:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-01 07:38:12 +0000
commitf57d515d69b7a35477b9ba5d08fe117df1f1e275 (patch)
tree0c8a46fb21bdbde40221d189aedfe13e5a481142 /test/ruby
parentc527fa1341b3855de37257d3089024eee55e97d4 (diff)
array.c: Array#append and Array#prepend
* array.c (Init_Array): Add alias "append" to Array#push, and "prepend" to Array#unshift. [Feature #12746] [Fix GH-1574] Author: pascbjumper2 <stowers.joshua@live.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_array.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 9c0e4431dd..3cfd3d764d 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -443,6 +443,17 @@ class TestArray < Test::Unit::TestCase
assert_equal([1, 2], a)
end
+ def test_append
+ a = @cls[1, 2, 3]
+ assert_equal(@cls[1, 2, 3, 4, 5], a.append(4, 5))
+ assert_equal(@cls[1, 2, 3, 4, 5, nil], a.append(nil))
+
+ a.append
+ assert_equal @cls[1, 2, 3, 4, 5, nil], a
+ a.append 6, 7
+ assert_equal @cls[1, 2, 3, 4, 5, nil, 6, 7], a
+ end
+
def test_assoc
a1 = @cls[*%w( cat feline )]
a2 = @cls[*%w( dog canine )]
@@ -1204,6 +1215,14 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[], a)
end
+ def test_prepend
+ a = @cls[]
+ assert_equal(@cls['cat'], a.prepend('cat'))
+ assert_equal(@cls['dog', 'cat'], a.prepend('dog'))
+ assert_equal(@cls[nil, 'dog', 'cat'], a.prepend(nil))
+ assert_equal(@cls[@cls[1,2], nil, 'dog', 'cat'], a.prepend(@cls[1, 2]))
+ end
+
def test_push
a = @cls[1, 2, 3]
assert_equal(@cls[1, 2, 3, 4, 5], a.push(4, 5))