summaryrefslogtreecommitdiff
path: root/spec/ruby/core/array
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-27 10:48:40 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-27 10:48:40 +0000
commit3e6337b88b5255aba07b8f44de72cd5885f59465 (patch)
tree6146781aa381404b88ea4bfa2a44e75e8bc90d14 /spec/ruby/core/array
parentecc707e233a5577ea2048b3199d4baaf96c6b0f8 (diff)
Update to ruby/spec@8b743a3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/array')
-rw-r--r--spec/ruby/core/array/eql_spec.rb6
-rw-r--r--spec/ruby/core/array/fixtures/classes.rb5
-rw-r--r--spec/ruby/core/array/pack/a_spec.rb3
-rw-r--r--spec/ruby/core/array/pack/b_spec.rb3
-rw-r--r--spec/ruby/core/array/pack/h_spec.rb3
-rw-r--r--spec/ruby/core/array/pack/m_spec.rb3
-rw-r--r--spec/ruby/core/array/pack/p_spec.rb47
-rw-r--r--spec/ruby/core/array/pack/shared/string.rb32
-rw-r--r--spec/ruby/core/array/pack/shared/taint.rb33
-rw-r--r--spec/ruby/core/array/pack/u_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/z_spec.rb2
11 files changed, 102 insertions, 37 deletions
diff --git a/spec/ruby/core/array/eql_spec.rb b/spec/ruby/core/array/eql_spec.rb
index d4707eb518..8565b94c60 100644
--- a/spec/ruby/core/array/eql_spec.rb
+++ b/spec/ruby/core/array/eql_spec.rb
@@ -6,14 +6,14 @@ describe "Array#eql?" do
it_behaves_like :array_eql, :eql?
it "returns false if any corresponding elements are not #eql?" do
- [1, 2, 3, 4].send(@method, [1, 2, 3, 4.0]).should be_false
+ [1, 2, 3, 4].should_not eql([1, 2, 3, 4.0])
end
it "returns false if other is not a kind of Array" do
obj = mock("array eql?")
obj.should_not_receive(:to_ary)
- obj.should_not_receive(@method)
+ obj.should_not_receive(:eql?)
- [1, 2, 3].send(@method, obj).should be_false
+ [1, 2, 3].should_not eql(obj)
end
end
diff --git a/spec/ruby/core/array/fixtures/classes.rb b/spec/ruby/core/array/fixtures/classes.rb
index 2f8671b29a..7ca9067328 100644
--- a/spec/ruby/core/array/fixtures/classes.rb
+++ b/spec/ruby/core/array/fixtures/classes.rb
@@ -2,9 +2,10 @@ class Object
# This helper is defined here rather than in MSpec because
# it is only used in #pack specs.
def pack_format(count=nil, repeat=nil)
- format = "#{instance_variable_get(:@method)}#{count}"
+ format = instance_variable_get(:@method)
+ format += count.to_s unless format == 'P' || format == 'p'
format *= repeat if repeat
- format
+ format.dup # because it may then become tainted
end
end
diff --git a/spec/ruby/core/array/pack/a_spec.rb b/spec/ruby/core/array/pack/a_spec.rb
index 223e99cefe..1cee3858ff 100644
--- a/spec/ruby/core/array/pack/a_spec.rb
+++ b/spec/ruby/core/array/pack/a_spec.rb
@@ -3,12 +3,14 @@ require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/string'
+require_relative 'shared/taint'
describe "Array#pack with format 'A'" do
it_behaves_like :array_pack_basic, 'A'
it_behaves_like :array_pack_basic_non_float, 'A'
it_behaves_like :array_pack_no_platform, 'A'
it_behaves_like :array_pack_string, 'A'
+ it_behaves_like :array_pack_taint, 'A'
it "adds all the bytes to the output when passed the '*' modifier" do
["abc"].pack("A*").should == "abc"
@@ -36,6 +38,7 @@ describe "Array#pack with format 'a'" do
it_behaves_like :array_pack_basic_non_float, 'a'
it_behaves_like :array_pack_no_platform, 'a'
it_behaves_like :array_pack_string, 'a'
+ it_behaves_like :array_pack_taint, 'a'
it "adds all the bytes to the output when passed the '*' modifier" do
["abc"].pack("a*").should == "abc"
diff --git a/spec/ruby/core/array/pack/b_spec.rb b/spec/ruby/core/array/pack/b_spec.rb
index 2756a6bfb1..8a75825e3e 100644
--- a/spec/ruby/core/array/pack/b_spec.rb
+++ b/spec/ruby/core/array/pack/b_spec.rb
@@ -3,12 +3,14 @@ require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/encodings'
+require_relative 'shared/taint'
describe "Array#pack with format 'B'" do
it_behaves_like :array_pack_basic, 'B'
it_behaves_like :array_pack_basic_non_float, 'B'
it_behaves_like :array_pack_arguments, 'B'
it_behaves_like :array_pack_hex, 'B'
+ it_behaves_like :array_pack_taint, 'B'
it "calls #to_str to convert an Object to a String" do
obj = mock("pack H string")
@@ -59,6 +61,7 @@ describe "Array#pack with format 'b'" do
it_behaves_like :array_pack_basic_non_float, 'b'
it_behaves_like :array_pack_arguments, 'b'
it_behaves_like :array_pack_hex, 'b'
+ it_behaves_like :array_pack_taint, 'b'
it "calls #to_str to convert an Object to a String" do
obj = mock("pack H string")
diff --git a/spec/ruby/core/array/pack/h_spec.rb b/spec/ruby/core/array/pack/h_spec.rb
index fee2d1efec..51bf551ba3 100644
--- a/spec/ruby/core/array/pack/h_spec.rb
+++ b/spec/ruby/core/array/pack/h_spec.rb
@@ -3,12 +3,14 @@ require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/encodings'
+require_relative 'shared/taint'
describe "Array#pack with format 'H'" do
it_behaves_like :array_pack_basic, 'H'
it_behaves_like :array_pack_basic_non_float, 'H'
it_behaves_like :array_pack_arguments, 'H'
it_behaves_like :array_pack_hex, 'H'
+ it_behaves_like :array_pack_taint, 'H'
it "calls #to_str to convert an Object to a String" do
obj = mock("pack H string")
@@ -105,6 +107,7 @@ describe "Array#pack with format 'h'" do
it_behaves_like :array_pack_basic_non_float, 'h'
it_behaves_like :array_pack_arguments, 'h'
it_behaves_like :array_pack_hex, 'h'
+ it_behaves_like :array_pack_taint, 'h'
it "calls #to_str to convert an Object to a String" do
obj = mock("pack H string")
diff --git a/spec/ruby/core/array/pack/m_spec.rb b/spec/ruby/core/array/pack/m_spec.rb
index a29f1937e8..24acf2cef2 100644
--- a/spec/ruby/core/array/pack/m_spec.rb
+++ b/spec/ruby/core/array/pack/m_spec.rb
@@ -2,11 +2,13 @@
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "Array#pack with format 'M'" do
it_behaves_like :array_pack_basic, 'M'
it_behaves_like :array_pack_basic_non_float, 'M'
it_behaves_like :array_pack_arguments, 'M'
+ it_behaves_like :array_pack_taint, 'M'
it "encodes an empty string as an empty string" do
[""].pack("M").should == ""
@@ -192,6 +194,7 @@ describe "Array#pack with format 'm'" do
it_behaves_like :array_pack_basic, 'm'
it_behaves_like :array_pack_basic_non_float, 'm'
it_behaves_like :array_pack_arguments, 'm'
+ it_behaves_like :array_pack_taint, 'm'
it "encodes an empty string as an empty string" do
[""].pack("m").should == ""
diff --git a/spec/ruby/core/array/pack/p_spec.rb b/spec/ruby/core/array/pack/p_spec.rb
index d562108967..857d403313 100644
--- a/spec/ruby/core/array/pack/p_spec.rb
+++ b/spec/ruby/core/array/pack/p_spec.rb
@@ -1,11 +1,58 @@
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "Array#pack with format 'P'" do
it_behaves_like :array_pack_basic_non_float, 'P'
+ it_behaves_like :array_pack_taint, 'P'
+
+ it "produces as many bytes as there are in a pointer" do
+ ["hello"].pack("P").size.should == [0].pack("J").size
+ end
+
+ it "round-trips a string through pack and unpack" do
+ ["hello"].pack("P").unpack("P5").should == ["hello"]
+ end
+
+ it "taints the input string" do
+ input_string = "hello"
+ [input_string].pack("P")
+ input_string.tainted?.should be_true
+ end
+
+ it "does not taint the output string in normal cases" do
+ ["hello"].pack("P").tainted?.should be_false
+ end
+
+ it "with nil gives a null pointer" do
+ [nil].pack("P").unpack("J").should == [0]
+ end
end
describe "Array#pack with format 'p'" do
it_behaves_like :array_pack_basic_non_float, 'p'
+ it_behaves_like :array_pack_taint, 'p'
+
+ it "produces as many bytes as there are in a pointer" do
+ ["hello"].pack("p").size.should == [0].pack("J").size
+ end
+
+ it "round-trips a string through pack and unpack" do
+ ["hello"].pack("p").unpack("p").should == ["hello"]
+ end
+
+ it "taints the input string" do
+ input_string = "hello"
+ [input_string].pack("p")
+ input_string.tainted?.should be_true
+ end
+
+ it "does not taint the output string in normal cases" do
+ ["hello"].pack("p").tainted?.should be_false
+ end
+
+ it "with nil gives a null pointer" do
+ [nil].pack("p").unpack("J").should == [0]
+ end
end
diff --git a/spec/ruby/core/array/pack/shared/string.rb b/spec/ruby/core/array/pack/shared/string.rb
index cedb0886e2..256c1c08e8 100644
--- a/spec/ruby/core/array/pack/shared/string.rb
+++ b/spec/ruby/core/array/pack/shared/string.rb
@@ -36,38 +36,6 @@ describe :array_pack_string, shared: true do
lambda { [obj].pack(pack_format) }.should raise_error(TypeError)
end
- it "returns a tainted string when a pack argument is tainted" do
- ["abcd".taint, 0x20].pack(pack_format("3C")).tainted?.should be_true
- end
-
- it "does not return a tainted string when the array is tainted" do
- ["abcd", 0x20].taint.pack(pack_format("3C")).tainted?.should be_false
- end
-
- it "returns a tainted string when the format is tainted" do
- ["abcd", 0x20].pack(pack_format("3C").taint).tainted?.should be_true
- end
-
- it "returns a tainted string when an empty format is tainted" do
- ["abcd", 0x20].pack("".taint).tainted?.should be_true
- end
-
- it "returns a untrusted string when the format is untrusted" do
- ["abcd", 0x20].pack(pack_format("3C").untrust).untrusted?.should be_true
- end
-
- it "returns a untrusted string when the empty format is untrusted" do
- ["abcd", 0x20].pack("".untrust).untrusted?.should be_true
- end
-
- it "returns a untrusted string when a pack argument is untrusted" do
- ["abcd".untrust, 0x20].pack(pack_format("3C")).untrusted?.should be_true
- end
-
- it "returns a trusted string when the array is untrusted" do
- ["abcd", 0x20].untrust.pack(pack_format("3C")).untrusted?.should be_false
- end
-
it "returns a string in encoding of common to the concatenated results" do
f = pack_format("*")
[ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::ASCII_8BIT],
diff --git a/spec/ruby/core/array/pack/shared/taint.rb b/spec/ruby/core/array/pack/shared/taint.rb
new file mode 100644
index 0000000000..88f349cb24
--- /dev/null
+++ b/spec/ruby/core/array/pack/shared/taint.rb
@@ -0,0 +1,33 @@
+describe :array_pack_taint, shared: true do
+ it "returns a tainted string when a pack argument is tainted" do
+ ["abcd".taint, 0x20].pack(pack_format("3C")).tainted?.should be_true
+ end
+
+ it "does not return a tainted string when the array is tainted" do
+ ["abcd", 0x20].taint.pack(pack_format("3C")).tainted?.should be_false
+ end
+
+ it "returns a tainted string when the format is tainted" do
+ ["abcd", 0x20].pack(pack_format("3C").taint).tainted?.should be_true
+ end
+
+ it "returns a tainted string when an empty format is tainted" do
+ ["abcd", 0x20].pack("".taint).tainted?.should be_true
+ end
+
+ it "returns a untrusted string when the format is untrusted" do
+ ["abcd", 0x20].pack(pack_format("3C").untrust).untrusted?.should be_true
+ end
+
+ it "returns a untrusted string when the empty format is untrusted" do
+ ["abcd", 0x20].pack("".untrust).untrusted?.should be_true
+ end
+
+ it "returns a untrusted string when a pack argument is untrusted" do
+ ["abcd".untrust, 0x20].pack(pack_format("3C")).untrusted?.should be_true
+ end
+
+ it "returns a trusted string when the array is untrusted" do
+ ["abcd", 0x20].untrust.pack(pack_format("3C")).untrusted?.should be_false
+ end
+end
diff --git a/spec/ruby/core/array/pack/u_spec.rb b/spec/ruby/core/array/pack/u_spec.rb
index 9c248165b3..d708518c16 100644
--- a/spec/ruby/core/array/pack/u_spec.rb
+++ b/spec/ruby/core/array/pack/u_spec.rb
@@ -3,6 +3,7 @@ require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/unicode'
+require_relative 'shared/taint'
describe "Array#pack with format 'U'" do
it_behaves_like :array_pack_basic, 'U'
@@ -15,6 +16,7 @@ describe "Array#pack with format 'u'" do
it_behaves_like :array_pack_basic, 'u'
it_behaves_like :array_pack_basic_non_float, 'u'
it_behaves_like :array_pack_arguments, 'u'
+ it_behaves_like :array_pack_taint, 'u'
it "encodes an empty string as an empty string" do
[""].pack("u").should == ""
diff --git a/spec/ruby/core/array/pack/z_spec.rb b/spec/ruby/core/array/pack/z_spec.rb
index 8c89aa9d2a..d0600f0c26 100644
--- a/spec/ruby/core/array/pack/z_spec.rb
+++ b/spec/ruby/core/array/pack/z_spec.rb
@@ -3,12 +3,14 @@ require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/string'
+require_relative 'shared/taint'
describe "Array#pack with format 'Z'" do
it_behaves_like :array_pack_basic, 'Z'
it_behaves_like :array_pack_basic_non_float, 'Z'
it_behaves_like :array_pack_no_platform, 'Z'
it_behaves_like :array_pack_string, 'Z'
+ it_behaves_like :array_pack_taint, 'Z'
it "adds all the bytes and appends a NULL byte when passed the '*' modifier" do
["abc"].pack("Z*").should == "abc\x00"