Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/zstdruby/skippable_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static VALUE rb_write_skippable_frame(int argc, VALUE *argv, VALUE self)

static VALUE rb_read_skippable_frame(VALUE self, VALUE input_value)
{
StringValue(input_value);
char* input_data = RSTRING_PTR(input_value);
size_t input_size = RSTRING_LEN(input_value);

Expand Down
17 changes: 17 additions & 0 deletions spec/zstd-skippable_frame_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,22 @@
end
end

context 'non-String argument' do
[nil, 123456789, :symbol, [1, 2, 3], Object.new].each do |arg|
it "raises TypeError for #{arg.class}" do
expect { Zstd.read_skippable_frame(arg) }.to raise_error(TypeError)
end
end
end

context 'String-convertible argument' do
it 'accepts objects responding to #to_str' do
compressed_data = Zstd.compress(SecureRandom.hex(150))
frame = Zstd.write_skippable_frame(compressed_data, "sample data")
convertible = Object.new
convertible.define_singleton_method(:to_str) { frame }
expect(Zstd.read_skippable_frame(convertible)).to eq "sample data"
end
end
end
end