diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
commit | 95e8c48dd3348503a8c7db5d0498894a1b676395 (patch) | |
tree | 9eef7f720314ebaff56845a74e203770e62284e4 /spec/rubyspec/core/array/pack/c_spec.rb | |
parent | ed7d803500de38186c74bce94d233e85ef51e503 (diff) |
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
These files can therefore be updated like any other file in MRI.
Instructions are provided in spec/README.
[Feature #13156] [ruby-core:79246]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/core/array/pack/c_spec.rb')
-rw-r--r-- | spec/rubyspec/core/array/pack/c_spec.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/rubyspec/core/array/pack/c_spec.rb b/spec/rubyspec/core/array/pack/c_spec.rb new file mode 100644 index 0000000000..74afa72f56 --- /dev/null +++ b/spec/rubyspec/core/array/pack/c_spec.rb @@ -0,0 +1,75 @@ +# -*- encoding: ascii-8bit -*- + +require File.expand_path('../../../../spec_helper', __FILE__) +require File.expand_path('../../fixtures/classes', __FILE__) +require File.expand_path('../shared/basic', __FILE__) +require File.expand_path('../shared/numeric_basic', __FILE__) + +describe :array_pack_8bit, shared: true do + it "encodes the least significant eight bits of a positive number" do + [ [[49], "1"], + [[0b11111111], "\xFF"], + [[0b100000000], "\x00"], + [[0b100000001], "\x01"] + ].should be_computed_by(:pack, pack_format) + end + + it "encodes the least significant eight bits of a negative number" do + [ [[-1], "\xFF"], + [[-0b10000000], "\x80"], + [[-0b11111111], "\x01"], + [[-0b100000000], "\x00"], + [[-0b100000001], "\xFF"] + ].should be_computed_by(:pack, pack_format) + end + + it "encodes a Float truncated as an Integer" do + [ [[5.2], "\x05"], + [[5.8], "\x05"] + ].should be_computed_by(:pack, pack_format) + end + + it "calls #to_int to convert the pack argument to an Integer" do + obj = mock('to_int') + obj.should_receive(:to_int).and_return(5) + [obj].pack(pack_format).should == "\x05" + end + + it "encodes the number of array elements specified by the count modifier" do + [ [[1, 2, 3], pack_format(3), "\x01\x02\x03"], + [[1, 2, 3], pack_format(2) + pack_format(1), "\x01\x02\x03"] + ].should be_computed_by(:pack) + end + + it "encodes all remaining elements when passed the '*' modifier" do + [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" + end + + it "ignores spaces between directives" do + [1, 2, 3].pack(pack_format(' ', 2)).should == "\x01\x02" + end +end + +describe "Array#pack with format 'C'" do + it_behaves_like :array_pack_basic, 'C' + it_behaves_like :array_pack_basic_non_float, 'C' + it_behaves_like :array_pack_8bit, 'C' + it_behaves_like :array_pack_arguments, 'C' + it_behaves_like :array_pack_numeric_basic, 'C' + it_behaves_like :array_pack_integer, 'C' + it_behaves_like :array_pack_no_platform, 'C' +end + +describe "Array#pack with format 'c'" do + it_behaves_like :array_pack_basic, 'c' + it_behaves_like :array_pack_basic_non_float, 'c' + it_behaves_like :array_pack_8bit, 'c' + it_behaves_like :array_pack_arguments, 'c' + it_behaves_like :array_pack_numeric_basic, 'c' + it_behaves_like :array_pack_integer, 'c' + it_behaves_like :array_pack_no_platform, 'c' +end |