diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/core/time/_dump_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) | |
download | ruby-1d15d5f08032acf1b7bceacbb450d617ff6e0931.tar.gz |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/time/_dump_spec.rb')
-rw-r--r-- | spec/ruby/core/time/_dump_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/ruby/core/time/_dump_spec.rb b/spec/ruby/core/time/_dump_spec.rb new file mode 100644 index 0000000000..bec16dab69 --- /dev/null +++ b/spec/ruby/core/time/_dump_spec.rb @@ -0,0 +1,56 @@ +# -*- encoding: binary -*- +require File.expand_path('../../../spec_helper', __FILE__) + +describe "Time#_dump" do + before :each do + @local = Time.at(946812800) + @t = Time.at(946812800) + @t = @t.gmtime + @s = @t.send(:_dump) + end + + it "is a private method" do + Time.should have_private_instance_method(:_dump, false) + end + + # http://redmine.ruby-lang.org/issues/show/627 + it "preserves the GMT flag" do + @t.gmt?.should == true + dump = @t.send(:_dump).unpack("VV").first + ((dump >> 30) & 0x1).should == 1 + + @local.gmt?.should == false + dump = @local.send(:_dump).unpack("VV").first + ((dump >> 30) & 0x1).should == 0 + end + + it "dumps a Time object to a bytestring" do + @s.should be_an_instance_of(String) + @s.should == [3222863947, 2235564032].pack("VV") + end + + it "dumps an array with a date as first element" do + high = 1 << 31 | + (@t.gmt? ? 1 : 0) << 30 | + (@t.year - 1900) << 14 | + (@t.mon - 1) << 10 | + @t.mday << 5 | + @t.hour + + high.should == @s.unpack("VV").first + end + + it "dumps an array with a time as second element" do + low = @t.min << 26 | + @t.sec << 20 | + @t.usec + low.should == @s.unpack("VV").last + end + + it "dumps like MRI's marshaled time format" do + t = Time.utc(2000, 1, 15, 20, 1, 1, 203).localtime + + t.send(:_dump).should == "\364\001\031\200\313\000\020\004" + end +end + |