From ca2823d33efb711162bb53e5d49172a3b07897b0 Mon Sep 17 00:00:00 2001 From: Adam Shelly Date: Fri, 29 Feb 2008 03:49:28 -0500 Subject: [PATCH] Updated specs for Array#pack * catch use of to_i where MRI does to_int * specs for 'Q' --- spec/ruby/1.8/core/array/pack_spec.rb | 45 +++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-) diff --git a/spec/ruby/1.8/core/array/pack_spec.rb b/spec/ruby/1.8/core/array/pack_spec.rb index 35cbe66..d79d511 100644 --- a/spec/ruby/1.8/core/array/pack_spec.rb +++ b/spec/ruby/1.8/core/array/pack_spec.rb @@ -43,6 +43,20 @@ describe "Array#pack" do lambda { [].pack(pat) }.should raise_error(ArgumentError) } end + + it "raises a TypeError when passed strings with /iIlLqQUsS/" do + "iIlLqQUs".split('').each{|pat| + lambda { ['0'].pack(pat) }.should raise_error(TypeError) + } + end + + not_compliant_on :rubinius do + it "raises a TypeError when passed strings with /nNVvw/" do + "LnNVvw".split('').each{|pat| + lambda { ['0'].pack(pat) }.should raise_error(TypeError) + } + end + end it "skips everything till the end of schema string with ('#')" do ["abc", "def"].pack("A*#A10%").should == "abc" @@ -558,6 +572,31 @@ describe "Array#pack" do ["ABC", "DEF", "GHI"].pack('m*').should == ["ABC"].pack('m') end + it "returns 8 characters with ('q') or ('Q')" do + [0].pack('Q').should == "\000\000\000\000\000\000\000\000" + [8319671809572238706].pack('q').should == "rubinius" + [123456789].pack('Q').should == [123456789].pack('q') + end + + it "converts 1,N,or all items with ('q) or ('Q')" do + [82<<56, 85<<42].pack('Q').should == "\000\000\000\000\000\000\000R" + [?a,?b,?c].pack('q2').should == "a\000\000\000\000\000\000\000b\000\000\000\000\000\000\000" + [1,2,3].pack('Q*').should == "\001\000\000\000\000\000\000\000"+ + "\002\000\000\000\000\000\000\000\003\000\000\000\000\000\000\000" + end + + it "raises a TypeError for non-Integer types with ('q') or ('Q')" do + lambda { ["Hello"].pack('q') }.should raise_error(TypeError) + lambda { [{:quad=>64}].pack('Q') }.should raise_error(TypeError) + lambda { [Object.new].pack('Q') }.should raise_error(TypeError) + end + + it "raises a Range error if integer is too large with 'q' or 'Q'" do + lambda { [1<<64].pack('q') }.should raise_error(RangeError) + lambda { [2.0**64].pack('Q') }.should raise_error(RangeError) + end + + it "encodes a positive integer with ('s')" do [0].pack('s').should == "\000\000" [2**32-1].pack('s').should == "\377\377" @@ -621,6 +660,12 @@ describe "Array#pack" do [?a,?b,?c].pack('U2').should == "ab" end + it "raises a TypeError for non-Integer types with ('U')" do + lambda { ["Hello"].pack('U') }.should raise_error(TypeError) + lambda { [{:quad=>64}].pack('U') }.should raise_error(TypeError) + lambda { [Object.new].pack('U') }.should raise_error(TypeError) + end + it "converts big integers into UTF-8 encoded byte sequences with ('U')" do #these are actually failing on String#unpack # they are not passing the 'utf8_regex_strict' test -- 1.5.2.5