|
1 | 1 | package osc
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "bytes" |
5 | 4 | "testing"
|
6 | 5 | "time"
|
7 | 6 |
|
8 | 7 | "github.com/pkg/errors"
|
9 | 8 | )
|
10 | 9 |
|
| 10 | +func TestImmediately(t *testing.T) { |
| 11 | + if !Immediately.Time().IsZero() { |
| 12 | + t.Fatalf("expected Immediately to convert to the zero time") |
| 13 | + } |
| 14 | +} |
| 15 | + |
11 | 16 | func TestFromTime(t *testing.T) {
|
12 | 17 | // Test converting to/from time.Time
|
13 | 18 | for _, testcase := range []struct {
|
14 | 19 | Input Timetag
|
15 | 20 | Expected time.Time
|
16 | 21 | }{
|
17 |
| - { |
18 |
| - Input: FromTime(time.Unix(0, 0)), |
19 |
| - Expected: time.Unix(0, 0), |
20 |
| - }, |
| 22 | + {Input: FromTime(time.Unix(0, 0)), Expected: time.Unix(0, 0)}, |
| 23 | + {Input: FromTime(time.Time{}), Expected: time.Time{}}, |
21 | 24 | } {
|
22 | 25 | if expected, got := testcase.Expected, testcase.Input.Time(); !expected.Equal(got) {
|
23 | 26 | t.Fatalf("expected %s, got %s", expected, got)
|
24 | 27 | }
|
25 | 28 | }
|
26 | 29 | }
|
27 | 30 |
|
28 |
| -func TestTimetagBytes(t *testing.T) { |
29 |
| - for _, testcase := range []struct { |
30 |
| - Input Timetag |
31 |
| - Expected []byte |
32 |
| - }{ |
33 |
| - { |
34 |
| - Input: Timetag(0), |
35 |
| - Expected: []byte{0, 0, 0, 0, 0, 0, 0, 0}, |
36 |
| - }, |
37 |
| - { |
38 |
| - Input: Timetag(10), |
39 |
| - Expected: []byte{0, 0, 0, 0, 0, 0, 0, 0x0A}, |
40 |
| - }, |
41 |
| - } { |
42 |
| - if expected, got := testcase.Expected, testcase.Input.Bytes(); !bytes.Equal(expected, got) { |
43 |
| - t.Fatalf("expected, %q, got %q", expected, got) |
44 |
| - } |
45 |
| - } |
46 |
| -} |
47 |
| - |
48 | 31 | func TestTimetagString(t *testing.T) {
|
49 | 32 | for _, testcase := range []struct {
|
50 | 33 | Input Timetag
|
51 | 34 | Expected string
|
52 | 35 | }{
|
53 |
| - {Input: Timetag(10), Expected: "1900-01-01T00:00:00Z"}, |
| 36 | + // 0s + 0 * 0.233ns |
| 37 | + {Input: Timetag(0), Expected: "1900-01-01T00:00:00Z"}, |
| 38 | + // "immediately" special value |
| 39 | + {Input: Timetag(1), Expected: "0001-01-01T00:00:00Z"}, |
| 40 | + // 0s + 2 * 0.233ns |
| 41 | + {Input: Timetag(2), Expected: "1900-01-01T00:00:00Z"}, |
| 42 | + // 0s + (2^32-1)/(2^32) seconds |
| 43 | + {Input: Timetag(0xFFFFFFFF), Expected: "1900-01-01T00:00:00Z"}, |
| 44 | + // 1s + 0 * 0.233ns |
| 45 | + {Input: Timetag(0x100000000), Expected: "1900-01-01T00:00:01Z"}, |
54 | 46 | } {
|
55 | 47 | if expected, got := testcase.Expected, testcase.Input.String(); expected != got {
|
56 | 48 | t.Fatalf("expected, %s, got %s", expected, got)
|
|
0 commit comments