Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 5, 2023
1 parent 9aba0af commit 9d69b95
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 70 deletions.
14 changes: 12 additions & 2 deletions core/array/pack/c_spec.rb
Expand Up @@ -45,8 +45,18 @@
[1, 2, 3, 4, 5].pack(pack_format('*')).should == "\x01\x02\x03\x04\x05"
end

it "ignores NULL bytes between directives" do
[1, 2, 3].pack(pack_format("\000", 2)).should == "\x01\x02"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
[1, 2, 3].pack(pack_format("\000", 2)).should == "\x01\x02"
end
end

ruby_version_is "3.3" do
it "raise ArgumentError for NULL bytes between directives" do
-> {
[1, 2, 3].pack(pack_format("\000", 2))
}.should raise_error(ArgumentError, /unknown pack directive/)
end
end

it "ignores spaces between directives" do
Expand Down
56 changes: 48 additions & 8 deletions core/array/pack/shared/float.rb
Expand Up @@ -25,8 +25,18 @@
[2.9, 1.4, 8.2].pack(pack_format("*")).should == "\x9a\x999@33\xb3?33\x03A"
end

it "ignores NULL bytes between directives" do
[5.3, 9.2].pack(pack_format("\000", 2)).should == "\x9a\x99\xa9@33\x13A"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
[5.3, 9.2].pack(pack_format("\000", 2)).should == "\x9a\x99\xa9@33\x13A"
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
end

it "ignores spaces between directives" do
Expand Down Expand Up @@ -93,8 +103,18 @@
[2.9, 1.4, 8.2].pack(pack_format("*")).should == "@9\x99\x9a?\xb333A\x0333"
end

it "ignores NULL bytes between directives" do
[5.3, 9.2].pack(pack_format("\000", 2)).should == "@\xa9\x99\x9aA\x1333"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
[5.3, 9.2].pack(pack_format("\000", 2)).should == "@\xa9\x99\x9aA\x1333"
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
end

it "ignores spaces between directives" do
Expand Down Expand Up @@ -153,8 +173,18 @@
[2.9, 1.4, 8.2].pack(pack_format("*")).should == "333333\x07@ffffff\xf6?ffffff\x20@"
end

it "ignores NULL bytes between directives" do
[5.3, 9.2].pack(pack_format("\000", 2)).should == "333333\x15@ffffff\x22@"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
[5.3, 9.2].pack(pack_format("\000", 2)).should == "333333\x15@ffffff\x22@"
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
end

it "ignores spaces between directives" do
Expand Down Expand Up @@ -212,8 +242,18 @@
[2.9, 1.4, 8.2].pack(pack_format("*")).should == "@\x07333333?\xf6ffffff@\x20ffffff"
end

it "ignores NULL bytes between directives" do
[5.3, 9.2].pack(pack_format("\000", 2)).should == "@\x15333333@\x22ffffff"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
[5.3, 9.2].pack(pack_format("\000", 2)).should == "@\x15333333@\x22ffffff"
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
end

it "ignores spaces between directives" do
Expand Down
96 changes: 78 additions & 18 deletions core/array/pack/shared/integer.rb
Expand Up @@ -41,9 +41,19 @@
str.should == "\x78\x65\xcd\xab\x21\x43"
end

it "ignores NULL bytes between directives" do
str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
str.should == "\x78\x65\xcd\xab"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
str.should == "\x78\x65\xcd\xab"
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
end

it "ignores spaces between directives" do
Expand Down Expand Up @@ -93,9 +103,19 @@
str.should == "\x65\x78\xab\xcd\x43\x21"
end

it "ignores NULL bytes between directives" do
str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
str.should == "\x65\x78\xab\xcd"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
str.should == "\x65\x78\xab\xcd"
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
end

it "ignores spaces between directives" do
Expand Down Expand Up @@ -145,9 +165,19 @@
str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde\x21\x43\x65\x78"
end

it "ignores NULL bytes between directives" do
str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde"
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
end

it "ignores spaces between directives" do
Expand Down Expand Up @@ -197,9 +227,19 @@
str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd\x78\x65\x43\x21"
end

it "ignores NULL bytes between directives" do
str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd"
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
end

it "ignores spaces between directives" do
Expand Down Expand Up @@ -309,9 +349,19 @@
str.should == "\x56\x78\x12\x34\xcd\xab\xf0\xde\xf0\xde\xba\xdc\x21\x43\x65\x78"
end

it "ignores NULL bytes between directives" 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"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" 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

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
end

it "ignores spaces between directives" do
Expand Down Expand Up @@ -369,9 +419,19 @@
str.should == "\xde\xf0\xab\xcd\x34\x12\x78\x56\x78\x65\x43\x21\xdc\xba\xde\xf0"
end

it "ignores NULL bytes between directives" 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"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" 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

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
end

it "ignores spaces between directives" do
Expand Down
14 changes: 12 additions & 2 deletions core/array/pack/shared/unicode.rb
Expand Up @@ -67,8 +67,18 @@
-> { [obj].pack("U") }.should raise_error(TypeError)
end

it "ignores NULL bytes between directives" do
[1, 2, 3].pack("U\x00U").should == "\x01\x02"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
[1, 2, 3].pack("U\x00U").should == "\x01\x02"
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
end

it "ignores spaces between directives" do
Expand Down
14 changes: 12 additions & 2 deletions core/array/pack/w_spec.rb
Expand Up @@ -24,8 +24,18 @@
[obj].pack("w").should == "\x05"
end

it "ignores NULL bytes between directives" do
[1, 2, 3].pack("w\x00w").should == "\x01\x02"
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
[1, 2, 3].pack("w\x00w").should == "\x01\x02"
end
end

ruby_version_is "3.3" do
it "raise ArgumentError for NULL bytes between directives" do
-> {
[1, 2, 3].pack("w\x00w")
}.should raise_error(ArgumentError, /unknown pack directive/)
end
end

it "ignores spaces between directives" do
Expand Down
28 changes: 24 additions & 4 deletions core/string/unpack/b_spec.rb
Expand Up @@ -86,8 +86,18 @@
].should be_computed_by(:unpack, "BBB")
end

it "ignores NULL bytes between directives" do
"\x80\x00".unpack("B\x00B").should == ["1", "0"]
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
"\x80\x00".unpack("B\x00B").should == ["1", "0"]
end
end

ruby_version_is "3.3" do
it "raise ArgumentError for NULL bytes between directives" do
-> {
"\x80\x00".unpack("B\x00B")
}.should raise_error(ArgumentError, /unknown unpack directive/)
end
end

it "ignores spaces between directives" do
Expand Down Expand Up @@ -182,8 +192,18 @@
].should be_computed_by(:unpack, "bbb")
end

it "ignores NULL bytes between directives" do
"\x01\x00".unpack("b\x00b").should == ["1", "0"]
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
"\x01\x00".unpack("b\x00b").should == ["1", "0"]
end
end

ruby_version_is "3.3" do
it "raise ArgumentError for NULL bytes between directives" do
-> {
"\x01\x00".unpack("b\x00b")
}.should raise_error(ArgumentError, /unknown unpack directive/)
end
end

it "ignores spaces between directives" do
Expand Down
14 changes: 12 additions & 2 deletions core/string/unpack/c_spec.rb
Expand Up @@ -35,8 +35,18 @@
].should be_computed_by(:unpack, unpack_format(3))
end

it "ignores NULL bytes between directives" do
"abc".unpack(unpack_format("\000", 2)).should == [97, 98]
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
"abc".unpack(unpack_format("\000", 2)).should == [97, 98]
end
end

ruby_version_is "3.3" do
it "raise ArgumentError for NULL bytes between directives" do
-> {
"abc".unpack(unpack_format("\000", 2))
}.should raise_error(ArgumentError, /unknown unpack directive/)
end
end

it "ignores spaces between directives" do
Expand Down
28 changes: 24 additions & 4 deletions core/string/unpack/h_spec.rb
Expand Up @@ -56,8 +56,18 @@
].should be_computed_by(:unpack, "HHH")
end

it "ignores NULL bytes between directives" do
"\x01\x10".unpack("H\x00H").should == ["0", "1"]
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
"\x01\x10".unpack("H\x00H").should == ["0", "1"]
end
end

ruby_version_is "3.3" do
it "raise ArgumentError for NULL bytes between directives" do
-> {
"\x01\x10".unpack("H\x00H")
}.should raise_error(ArgumentError, /unknown unpack directive/)
end
end

it "ignores spaces between directives" do
Expand Down Expand Up @@ -121,8 +131,18 @@
].should be_computed_by(:unpack, "hhh")
end

it "ignores NULL bytes between directives" do
"\x01\x10".unpack("h\x00h").should == ["1", "0"]
ruby_version_is ""..."3.3" do
it "ignores NULL bytes between directives" do
"\x01\x10".unpack("h\x00h").should == ["1", "0"]
end
end

ruby_version_is "3.3" do
it "raise ArgumentError for NULL bytes between directives" do
-> {
"\x01\x10".unpack("h\x00h")
}.should raise_error(ArgumentError, /unknown unpack directive/)
end
end

it "ignores spaces between directives" do
Expand Down

0 comments on commit 9d69b95

Please sign in to comment.