diff options
Diffstat (limited to 'spec/ruby/core/array/pack/shared')
| -rw-r--r-- | spec/ruby/core/array/pack/shared/basic.rb | 56 | ||||
| -rw-r--r-- | spec/ruby/core/array/pack/shared/encodings.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/array/pack/shared/float.rb | 90 | ||||
| -rw-r--r-- | spec/ruby/core/array/pack/shared/integer.rb | 116 | ||||
| -rw-r--r-- | spec/ruby/core/array/pack/shared/numeric_basic.rb | 16 | ||||
| -rw-r--r-- | spec/ruby/core/array/pack/shared/string.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/core/array/pack/shared/unicode.rb | 26 |
7 files changed, 88 insertions, 228 deletions
diff --git a/spec/ruby/core/array/pack/shared/basic.rb b/spec/ruby/core/array/pack/shared/basic.rb index 4b28de7ed0..2894369c71 100644 --- a/spec/ruby/core/array/pack/shared/basic.rb +++ b/spec/ruby/core/array/pack/shared/basic.rb @@ -1,6 +1,6 @@ describe :array_pack_arguments, shared: true do it "raises an ArgumentError if there are fewer elements than the format requires" do - -> { [].pack(pack_format(1)) }.should raise_error(ArgumentError) + -> { [].pack(pack_format(1)) }.should.raise(ArgumentError) end end @@ -10,11 +10,11 @@ describe :array_pack_basic, shared: true do end it "raises a TypeError when passed nil" do - -> { [@obj].pack(nil) }.should raise_error(TypeError) + -> { [@obj].pack(nil) }.should.raise(TypeError) end it "raises a TypeError when passed an Integer" do - -> { [@obj].pack(1) }.should raise_error(TypeError) + -> { [@obj].pack(1) }.should.raise(TypeError) end end @@ -24,74 +24,50 @@ describe :array_pack_basic_non_float, shared: true do end it "ignores whitespace in the format string" do - [@obj, @obj].pack("a \t\n\v\f\r"+pack_format).should be_an_instance_of(String) + [@obj, @obj].pack("a \t\n\v\f\r"+pack_format).should.instance_of?(String) end it "ignores comments in the format string" do # 2 additional directives ('a') are required for the X directive - [@obj, @obj, @obj, @obj].pack("aa #{pack_format} # some comment \n#{pack_format}").should be_an_instance_of(String) + [@obj, @obj, @obj, @obj].pack("aa #{pack_format} # some comment \n#{pack_format}").should.instance_of?(String) end - ruby_version_is ""..."3.2" do - it "warns in verbose mode that a directive is unknown" do - # additional directive ('a') is required for the X directive - -> { [@obj, @obj].pack("a R" + pack_format) }.should complain(/unknown pack directive 'R'/, verbose: true) - -> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0'/, verbose: true) - -> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':'/, verbose: true) - end - end - - ruby_version_is "3.2"..."3.3" do - # https://bugs.ruby-lang.org/issues/19150 - # NOTE: it's just a plan of the Ruby core team - it "warns that a directive is unknown" do - # additional directive ('a') is required for the X directive - -> { [@obj, @obj].pack("a R" + pack_format) }.should complain(/unknown pack directive 'R'/) - -> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0'/) - -> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':'/) - end - end - - ruby_version_is "3.3" do - # https://bugs.ruby-lang.org/issues/19150 - # NOTE: Added this case just to not forget about the decision in the ticket - it "raise ArgumentError when a directive is unknown" do - # additional directive ('a') is required for the X directive - -> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/) - -> { [@obj, @obj].pack("a 0" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive '0'/) - -> { [@obj, @obj].pack("a :" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive ':'/) - end + it "raise ArgumentError when a directive is unknown" do + # additional directive ('a') is required for the X directive + -> { [@obj, @obj].pack("a K" + pack_format) }.should.raise(ArgumentError, /unknown pack directive 'K'/) + -> { [@obj, @obj].pack("a 0" + pack_format) }.should.raise(ArgumentError, /unknown pack directive '0'/) + -> { [@obj, @obj].pack("a :" + pack_format) }.should.raise(ArgumentError, /unknown pack directive ':'/) end it "calls #to_str to coerce the directives string" do d = mock("pack directive") d.should_receive(:to_str).and_return("x"+pack_format) - [@obj, @obj].pack(d).should be_an_instance_of(String) + [@obj, @obj].pack(d).should.instance_of?(String) end end describe :array_pack_basic_float, shared: true do it "ignores whitespace in the format string" do - [9.3, 4.7].pack(" \t\n\v\f\r"+pack_format).should be_an_instance_of(String) + [9.3, 4.7].pack(" \t\n\v\f\r"+pack_format).should.instance_of?(String) end it "ignores comments in the format string" do - [9.3, 4.7].pack(pack_format + "# some comment \n" + pack_format).should be_an_instance_of(String) + [9.3, 4.7].pack(pack_format + "# some comment \n" + pack_format).should.instance_of?(String) end it "calls #to_str to coerce the directives string" do d = mock("pack directive") d.should_receive(:to_str).and_return("x"+pack_format) - [1.2, 4.7].pack(d).should be_an_instance_of(String) + [1.2, 4.7].pack(d).should.instance_of?(String) end end describe :array_pack_no_platform, shared: true do it "raises ArgumentError when the format modifier is '_'" do - ->{ [1].pack(pack_format("_")) }.should raise_error(ArgumentError) + ->{ [1].pack(pack_format("_")) }.should.raise(ArgumentError) end it "raises ArgumentError when the format modifier is '!'" do - ->{ [1].pack(pack_format("!")) }.should raise_error(ArgumentError) + ->{ [1].pack(pack_format("!")) }.should.raise(ArgumentError) end end diff --git a/spec/ruby/core/array/pack/shared/encodings.rb b/spec/ruby/core/array/pack/shared/encodings.rb index 6b7ffac764..0b5a5cc8a0 100644 --- a/spec/ruby/core/array/pack/shared/encodings.rb +++ b/spec/ruby/core/array/pack/shared/encodings.rb @@ -5,12 +5,12 @@ describe :array_pack_hex, shared: true do it "raises a TypeError if the object does not respond to #to_str" do obj = mock("pack hex non-string") - -> { [obj].pack(pack_format) }.should raise_error(TypeError) + -> { [obj].pack(pack_format) }.should.raise(TypeError) end it "raises a TypeError if #to_str does not return a String" do obj = mock("pack hex non-string") obj.should_receive(:to_str).and_return(1) - -> { [obj].pack(pack_format) }.should raise_error(TypeError) + -> { [obj].pack(pack_format) }.should.raise(TypeError) end end diff --git a/spec/ruby/core/array/pack/shared/float.rb b/spec/ruby/core/array/pack/shared/float.rb index 1780d7635e..c1efcd7677 100644 --- a/spec/ruby/core/array/pack/shared/float.rb +++ b/spec/ruby/core/array/pack/shared/float.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary describe :array_pack_float_le, shared: true do it "encodes a positive Float" do @@ -14,7 +14,7 @@ describe :array_pack_float_le, shared: true do end it "raises a TypeError if passed a String representation of a floating point number" do - -> { ["13"].pack(pack_format) }.should raise_error(TypeError) + -> { ["13"].pack(pack_format) }.should.raise(TypeError) end it "encodes the number of array elements specified by the count modifier" do @@ -25,20 +25,10 @@ describe :array_pack_float_le, shared: true do [2.9, 1.4, 8.2].pack(pack_format("*")).should == "\x9a\x999@33\xb3?33\x03A" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "\x9a\x99\xa9@33\x13A" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [5.3, 9.2].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [5.3, 9.2].pack(pack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -55,7 +45,7 @@ describe :array_pack_float_le, shared: true do it "encodes NaN" do nans = ["\x00\x00\xc0\xff", "\x00\x00\xc0\x7f", "\xFF\xFF\xFF\x7F"] - nans.should include([nan_value].pack(pack_format)) + nans.should.include?([nan_value].pack(pack_format)) end it "encodes a positive Float outside the range of a single precision float" do @@ -94,7 +84,7 @@ describe :array_pack_float_be, shared: true do end it "raises a TypeError if passed a String representation of a floating point number" do - -> { ["13"].pack(pack_format) }.should raise_error(TypeError) + -> { ["13"].pack(pack_format) }.should.raise(TypeError) end it "encodes the number of array elements specified by the count modifier" do @@ -105,20 +95,10 @@ describe :array_pack_float_be, shared: true do [2.9, 1.4, 8.2].pack(pack_format("*")).should == "@9\x99\x9a?\xb333A\x0333" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "@\xa9\x99\x9aA\x1333" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [5.3, 9.2].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [5.3, 9.2].pack(pack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -135,7 +115,7 @@ describe :array_pack_float_be, shared: true do it "encodes NaN" do nans = ["\xff\xc0\x00\x00", "\x7f\xc0\x00\x00", "\x7F\xFF\xFF\xFF"] - nans.should include([nan_value].pack(pack_format)) + nans.should.include?([nan_value].pack(pack_format)) end it "encodes a positive Float outside the range of a single precision float" do @@ -166,7 +146,7 @@ describe :array_pack_double_le, shared: true do end it "raises a TypeError if passed a String representation of a floating point number" do - -> { ["13"].pack(pack_format) }.should raise_error(TypeError) + -> { ["13"].pack(pack_format) }.should.raise(TypeError) end it "encodes the number of array elements specified by the count modifier" do @@ -177,20 +157,10 @@ describe :array_pack_double_le, shared: true do [2.9, 1.4, 8.2].pack(pack_format("*")).should == "333333\x07@ffffff\xf6?ffffff\x20@" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "333333\x15@ffffff\x22@" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [5.3, 9.2].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [5.3, 9.2].pack(pack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -211,7 +181,7 @@ describe :array_pack_double_le, shared: true do "\x00\x00\x00\x00\x00\x00\xf8\x7f", "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7F" ] - nans.should include([nan_value].pack(pack_format)) + nans.should.include?([nan_value].pack(pack_format)) end it "encodes a positive Float outside the range of a single precision float" do @@ -237,7 +207,7 @@ describe :array_pack_double_be, shared: true do end it "raises a TypeError if passed a String representation of a floating point number" do - -> { ["13"].pack(pack_format) }.should raise_error(TypeError) + -> { ["13"].pack(pack_format) }.should.raise(TypeError) end it "encodes the number of array elements specified by the count modifier" do @@ -248,20 +218,10 @@ describe :array_pack_double_be, shared: true do [2.9, 1.4, 8.2].pack(pack_format("*")).should == "@\x07333333?\xf6ffffff@\x20ffffff" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [5.3, 9.2].pack(pack_format("\000", 2)).should == "@\x15333333@\x22ffffff" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [5.3, 9.2].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [5.3, 9.2].pack(pack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -282,7 +242,7 @@ describe :array_pack_double_be, shared: true do "\x7f\xf8\x00\x00\x00\x00\x00\x00", "\x7F\xFF\xFF\xFF\xFF\xFF\xFF\xFF" ] - nans.should include([nan_value].pack(pack_format)) + nans.should.include?([nan_value].pack(pack_format)) end it "encodes a positive Float outside the range of a single precision float" do diff --git a/spec/ruby/core/array/pack/shared/integer.rb b/spec/ruby/core/array/pack/shared/integer.rb index a89b5b733b..1cdd386cc1 100644 --- a/spec/ruby/core/array/pack/shared/integer.rb +++ b/spec/ruby/core/array/pack/shared/integer.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary describe :array_pack_16bit_le, shared: true do it "encodes the least significant 16 bits of a positive number" do @@ -41,21 +41,10 @@ describe :array_pack_16bit_le, shared: true do str.should == "\x78\x65\xcd\xab\x21\x43" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x78\x65\xcd\xab" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -105,21 +94,10 @@ describe :array_pack_16bit_be, shared: true do str.should == "\x65\x78\xab\xcd\x43\x21" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x65\x78\xab\xcd" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -169,21 +147,10 @@ describe :array_pack_32bit_le, shared: true do str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde\x21\x43\x65\x78" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -233,21 +200,10 @@ describe :array_pack_32bit_be, shared: true do str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd\x78\x65\x43\x21" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -357,21 +313,10 @@ describe :array_pack_64bit_le, shared: true do str.should == "\x56\x78\x12\x34\xcd\xab\xf0\xde\xf0\xde\xba\xdc\x21\x43\x65\x78" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) - str.should == "\x56\x78\x12\x34\xcd\xab\xf0\xde\xf0\xde\xba\xdc\x21\x43\x65\x78" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -429,21 +374,10 @@ describe :array_pack_64bit_be, shared: true do str.should == "\xde\xf0\xab\xcd\x34\x12\x78\x56\x78\x65\x43\x21\xdc\xba\xde\xf0" end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - str = [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) - str.should == "\xde\xf0\xab\xcd\x34\x12\x78\x56\x78\x65\x43\x21\xdc\xba\xde\xf0" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2)) + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do diff --git a/spec/ruby/core/array/pack/shared/numeric_basic.rb b/spec/ruby/core/array/pack/shared/numeric_basic.rb index 545e215e64..6594914933 100644 --- a/spec/ruby/core/array/pack/shared/numeric_basic.rb +++ b/spec/ruby/core/array/pack/shared/numeric_basic.rb @@ -4,15 +4,15 @@ describe :array_pack_numeric_basic, shared: true do end it "raises a TypeError when passed nil" do - -> { [nil].pack(pack_format) }.should raise_error(TypeError) + -> { [nil].pack(pack_format) }.should.raise(TypeError) end it "raises a TypeError when passed true" do - -> { [true].pack(pack_format) }.should raise_error(TypeError) + -> { [true].pack(pack_format) }.should.raise(TypeError) end it "raises a TypeError when passed false" do - -> { [false].pack(pack_format) }.should raise_error(TypeError) + -> { [false].pack(pack_format) }.should.raise(TypeError) end it "returns a binary string" do @@ -24,27 +24,27 @@ end describe :array_pack_integer, shared: true do it "raises a TypeError when the object does not respond to #to_int" do obj = mock('not an integer') - -> { [obj].pack(pack_format) }.should raise_error(TypeError) + -> { [obj].pack(pack_format) }.should.raise(TypeError) end it "raises a TypeError when passed a String" do - -> { ["5"].pack(pack_format) }.should raise_error(TypeError) + -> { ["5"].pack(pack_format) }.should.raise(TypeError) end end describe :array_pack_float, shared: true do it "raises a TypeError if a String does not represent a floating point number" do - -> { ["a"].pack(pack_format) }.should raise_error(TypeError) + -> { ["a"].pack(pack_format) }.should.raise(TypeError) end it "raises a TypeError when the object is not Numeric" do obj = Object.new - -> { [obj].pack(pack_format) }.should raise_error(TypeError, /can't convert Object into Float/) + -> { [obj].pack(pack_format) }.should.raise(TypeError, /can't convert Object into Float/) end it "raises a TypeError when the Numeric object does not respond to #to_f" do klass = Class.new(Numeric) obj = klass.new - -> { [obj].pack(pack_format) }.should raise_error(TypeError) + -> { [obj].pack(pack_format) }.should.raise(TypeError) end end diff --git a/spec/ruby/core/array/pack/shared/string.rb b/spec/ruby/core/array/pack/shared/string.rb index 2f70dc3951..b02257059f 100644 --- a/spec/ruby/core/array/pack/shared/string.rb +++ b/spec/ruby/core/array/pack/shared/string.rb @@ -1,4 +1,4 @@ -# -*- encoding: binary -*- +# encoding: binary describe :array_pack_string, shared: true do it "adds count bytes of a String to the output" do ["abc"].pack(pack_format(2)).should == "ab" @@ -17,11 +17,11 @@ describe :array_pack_string, shared: true do end it "raises an ArgumentError when the Array is empty" do - -> { [].pack(pack_format) }.should raise_error(ArgumentError) + -> { [].pack(pack_format) }.should.raise(ArgumentError) end it "raises an ArgumentError when the Array has too few elements" do - -> { ["a"].pack(pack_format(nil, 2)) }.should raise_error(ArgumentError) + -> { ["a"].pack(pack_format(nil, 2)) }.should.raise(ArgumentError) end it "calls #to_str to convert the element to a String" do @@ -33,7 +33,7 @@ describe :array_pack_string, shared: true do it "raises a TypeError when the object does not respond to #to_str" do obj = mock("not a string") - -> { [obj].pack(pack_format) }.should raise_error(TypeError) + -> { [obj].pack(pack_format) }.should.raise(TypeError) end it "returns a string in encoding of common to the concatenated results" do diff --git a/spec/ruby/core/array/pack/shared/unicode.rb b/spec/ruby/core/array/pack/shared/unicode.rb index 4d8eaef323..58ba8a8b23 100644 --- a/spec/ruby/core/array/pack/shared/unicode.rb +++ b/spec/ruby/core/array/pack/shared/unicode.rb @@ -26,7 +26,7 @@ describe :array_pack_unicode, shared: true do it "constructs strings with valid encodings" do str = [0x85].pack("U*") str.should == "\xc2\x85" - str.valid_encoding?.should be_true + str.valid_encoding?.should == true end it "encodes values larger than UTF-8 max codepoints" do @@ -64,23 +64,13 @@ describe :array_pack_unicode, shared: true do it "raises a TypeError if #to_int does not return an Integer" do obj = mock('to_int') obj.should_receive(:to_int).and_return("5") - -> { [obj].pack("U") }.should raise_error(TypeError) + -> { [obj].pack("U") }.should.raise(TypeError) end - ruby_version_is ""..."3.3" do - it "ignores NULL bytes between directives" do - suppress_warning do - [1, 2, 3].pack("U\x00U").should == "\x01\x02" - end - end - end - - ruby_version_is "3.3" do - it "raise ArgumentError for NULL bytes between directives" do - -> { - [1, 2, 3].pack("U\x00U") - }.should raise_error(ArgumentError, /unknown pack directive/) - end + it "raise ArgumentError for NULL bytes between directives" do + -> { + [1, 2, 3].pack("U\x00U") + }.should.raise(ArgumentError, /unknown pack directive/) end it "ignores spaces between directives" do @@ -88,11 +78,11 @@ describe :array_pack_unicode, shared: true do end it "raises a RangeError if passed a negative number" do - -> { [-1].pack("U") }.should raise_error(RangeError) + -> { [-1].pack("U") }.should.raise(RangeError) end it "raises a RangeError if passed a number larger than an unsigned 32-bit integer" do - -> { [2**32].pack("U") }.should raise_error(RangeError) + -> { [2**32].pack("U") }.should.raise(RangeError) end it "sets the output string to UTF-8 encoding" do |
