Skip to content

Commit c6aadbb

Browse files
committed
Add tests with unknown directives for Array#pack, String#unpack
1 parent 8bb046b commit c6aadbb

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

core/array/pack/unknown_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require_relative '../../../spec_helper'
2+
3+
describe "Array#pack with unknown directive" do
4+
ruby_version_is ""..."3.3" do
5+
it "ignores unknown directive with a warning" do
6+
-> { [1, 2, 3].pack("nkv").should == "\x00\x01\x02\x00".b }.should complain(/unknown pack directive 'k' in 'nkv'/)
7+
end
8+
end
9+
10+
ruby_version_is "3.3" do
11+
it "raises ArgumentError" do
12+
-> { [1, 2, 3].pack("nkv") }.should raise_error(ArgumentError, "unknown pack directive 'k' in 'nkv'")
13+
end
14+
end
15+
end

core/string/unpack_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,16 @@
2929
it "raises an ArgumentError when the offset is larger than the string" do
3030
-> { "a".unpack("C", offset: 2) }.should raise_error(ArgumentError, "offset outside of string")
3131
end
32+
33+
ruby_version_is ""..."3.3" do
34+
it "ignores unknown directive with a warning" do
35+
-> { "\x00\x01\x02\x00".b.unpack("nkv").should == [1, 2] }.should complain(/unknown unpack directive 'k' in 'nkv'/)
36+
end
37+
end
38+
39+
ruby_version_is "3.3" do
40+
it "raises an ArgumentError if a directive is unknown" do
41+
-> { "\x00\x01\x02\x00".b.unpack("nkv") }.should raise_error(ArgumentError, "unknown unpack directive 'k' in 'nkv'")
42+
end
43+
end
3244
end

0 commit comments

Comments
 (0)