diff options
Diffstat (limited to 'spec/ruby/core/string/unpack/shared')
| -rw-r--r-- | spec/ruby/core/string/unpack/shared/basic.rb | 16 | ||||
| -rw-r--r-- | spec/ruby/core/string/unpack/shared/float.rb | 22 | ||||
| -rw-r--r-- | spec/ruby/core/string/unpack/shared/integer.rb | 30 | ||||
| -rw-r--r-- | spec/ruby/core/string/unpack/shared/unicode.rb | 4 |
4 files changed, 55 insertions, 17 deletions
diff --git a/spec/ruby/core/string/unpack/shared/basic.rb b/spec/ruby/core/string/unpack/shared/basic.rb index bb5302edc5..734630bda0 100644 --- a/spec/ruby/core/string/unpack/shared/basic.rb +++ b/spec/ruby/core/string/unpack/shared/basic.rb @@ -8,6 +8,22 @@ describe :string_unpack_basic, shared: true do d.should_receive(:to_str).and_return("a"+unpack_format) "abc".unpack(d).should be_an_instance_of(Array) end + + ruby_version_is ""..."3.3" do + it "warns about using an unknown directive" do + -> { "abcdefgh".unpack("a R" + unpack_format) }.should complain(/unknown unpack directive 'R' in 'a R#{unpack_format}'/) + -> { "abcdefgh".unpack("a 0" + unpack_format) }.should complain(/unknown unpack directive '0' in 'a 0#{unpack_format}'/) + -> { "abcdefgh".unpack("a :" + unpack_format) }.should complain(/unknown unpack directive ':' in 'a :#{unpack_format}'/) + end + end + + ruby_version_is "3.3" do + it "raises ArgumentError when a directive is unknown" do + -> { "abcdefgh".unpack("a K" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive 'K' in 'a K#{unpack_format}'") + -> { "abcdefgh".unpack("a 0" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive '0' in 'a 0#{unpack_format}'") + -> { "abcdefgh".unpack("a :" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive ':' in 'a :#{unpack_format}'") + end + end end describe :string_unpack_no_platform, shared: true do diff --git a/spec/ruby/core/string/unpack/shared/float.rb b/spec/ruby/core/string/unpack/shared/float.rb index ccddf94f99..b31c2c8bdc 100644 --- a/spec/ruby/core/string/unpack/shared/float.rb +++ b/spec/ruby/core/string/unpack/shared/float.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary describe :string_unpack_float_le, shared: true do it "decodes one float for a single format character" do @@ -58,8 +58,10 @@ describe :string_unpack_float_le, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - array = "\x9a\x999@33\xb3?".unpack(unpack_format("\000", 2)) - array.should == [2.9000000953674316, 1.399999976158142] + suppress_warning do + array = "\x9a\x999@33\xb3?".unpack(unpack_format("\000", 2)) + array.should == [2.9000000953674316, 1.399999976158142] + end end end @@ -135,8 +137,10 @@ describe :string_unpack_float_be, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - array = "@9\x99\x9a?\xb333".unpack(unpack_format("\000", 2)) - array.should == [2.9000000953674316, 1.399999976158142] + suppress_warning do + array = "@9\x99\x9a?\xb333".unpack(unpack_format("\000", 2)) + array.should == [2.9000000953674316, 1.399999976158142] + end end end @@ -215,7 +219,9 @@ describe :string_unpack_double_le, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - "333333\x07@ffffff\xf6?".unpack(unpack_format("\000", 2)).should == [2.9, 1.4] + suppress_warning do + "333333\x07@ffffff\xf6?".unpack(unpack_format("\000", 2)).should == [2.9, 1.4] + end end end @@ -293,7 +299,9 @@ describe :string_unpack_double_be, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - "@\x07333333?\xf6ffffff".unpack(unpack_format("\000", 2)).should == [2.9, 1.4] + suppress_warning do + "@\x07333333?\xf6ffffff".unpack(unpack_format("\000", 2)).should == [2.9, 1.4] + end end end diff --git a/spec/ruby/core/string/unpack/shared/integer.rb b/spec/ruby/core/string/unpack/shared/integer.rb index ba4f149dad..d3934753ba 100644 --- a/spec/ruby/core/string/unpack/shared/integer.rb +++ b/spec/ruby/core/string/unpack/shared/integer.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary describe :string_unpack_16bit_le, shared: true do it "decodes one short for a single format character" do @@ -34,7 +34,9 @@ describe :string_unpack_16bit_le, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - "abcd".unpack(unpack_format("\000", 2)).should == [25185, 25699] + suppress_warning do + "abcd".unpack(unpack_format("\000", 2)).should == [25185, 25699] + end end end @@ -97,7 +99,9 @@ describe :string_unpack_16bit_be, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - "badc".unpack(unpack_format("\000", 2)).should == [25185, 25699] + suppress_warning do + "badc".unpack(unpack_format("\000", 2)).should == [25185, 25699] + end end end @@ -161,7 +165,9 @@ describe :string_unpack_32bit_le, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - "abcdefgh".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885] + suppress_warning do + "abcdefgh".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885] + end end end @@ -225,7 +231,9 @@ describe :string_unpack_32bit_be, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - "dcbahgfe".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885] + suppress_warning do + "dcbahgfe".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885] + end end end @@ -285,8 +293,10 @@ describe :string_unpack_64bit_le, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - array = "abcdefghabghefcd".unpack(unpack_format("\000", 2)) - array.should == [7523094288207667809, 7233738012216484449] + suppress_warning do + array = "abcdefghabghefcd".unpack(unpack_format("\000", 2)) + array.should == [7523094288207667809, 7233738012216484449] + end end end @@ -357,8 +367,10 @@ describe :string_unpack_64bit_be, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - array = "hgfedcbadcfehgba".unpack(unpack_format("\000", 2)) - array.should == [7523094288207667809, 7233738012216484449] + suppress_warning do + array = "hgfedcbadcfehgba".unpack(unpack_format("\000", 2)) + array.should == [7523094288207667809, 7233738012216484449] + end end end diff --git a/spec/ruby/core/string/unpack/shared/unicode.rb b/spec/ruby/core/string/unpack/shared/unicode.rb index ce1f29fe87..9fe07f53ae 100644 --- a/spec/ruby/core/string/unpack/shared/unicode.rb +++ b/spec/ruby/core/string/unpack/shared/unicode.rb @@ -52,7 +52,9 @@ describe :string_unpack_unicode, shared: true do ruby_version_is ""..."3.3" do it "ignores NULL bytes between directives" do - "\x01\x02".unpack("U\x00U").should == [1, 2] + suppress_warning do + "\x01\x02".unpack("U\x00U").should == [1, 2] + end end end |
