File: _load_spec.rb

package info (click to toggle)
jruby 1.7.26-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,572 kB
  • sloc: ruby: 669,910; java: 253,056; xml: 35,152; ansic: 9,187; yacc: 7,267; cpp: 5,244; sh: 1,036; makefile: 345; jsp: 48; tcl: 40
file content (66 lines) | stat: -rw-r--r-- 1,771 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/methods', __FILE__)

describe "Time#_load" do
  ruby_bug("http://redmine.ruby-lang.org/issues/show/627", "1.8.7") do
    it "loads a time object in the new format" do
      t = Time.local(2000, 1, 15, 20, 1, 1)
      t = t.gmtime

      high =               1 << 31 |
            (t.gmt? ? 1 : 0) << 30 |
             (t.year - 1900) << 14 |
                (t.mon  - 1) << 10 |
                       t.mday << 5 |
                            t.hour

      low =  t.min  << 26 |
             t.sec  << 20 |
                   t.usec

      Time.send(:_load, [high, low].pack("VV")).should == t
    end
  end

  it "loads a time object in the old UNIX timestamp based format" do
    t = Time.local(2000, 1, 15, 20, 1, 1, 203)
    timestamp = t.to_i

    high = timestamp & ((1 << 31) - 1)

    low =  t.usec

    Time.send(:_load, [high, low].pack("VV")).should == t
  end

  ruby_version_is ''...'1.9' do
    it "loads MRI's marshaled time format" do
      t = Marshal.load("\004\bu:\tTime\r\320\246\e\200\320\001\r\347")
      t.utc

      t.to_s.should == "Fri Oct 22 16:57:48 UTC 2010"
    end
  end

  ruby_version_is '1.9' do
    it "loads MRI's marshaled time format" do
      t = Marshal.load("\004\bu:\tTime\r\320\246\e\200\320\001\r\347")
      t.utc

      t.to_s.should == "2010-10-22 16:57:48 UTC"
    end
  end

  with_feature :encoding do
    it "treats the data as binary data" do
      data = "\x04\bu:\tTime\r\fM\x1C\xC0\x00\x00\xD0\xBE"
      data.force_encoding Encoding::UTF_8
      t = Marshal.load(data)
      t.to_s.should == "2013-04-08 12:47:45 UTC"
    end
  end
end

describe "Time._load" do
  it "needs to be reviewed for spec completeness"
end