forked from teepark/pqinterval
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinterval_test.go
62 lines (50 loc) · 1.76 KB
/
interval_test.go
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
package pqinterval
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewCreatesCorrectInterval(t *testing.T) {
i := New(1, 2, 3, 4, 5, 6)
assert.EqualValues(t, 1, i.Years(), "interval years")
assert.EqualValues(t, 2*24+3, i.Hours(), "interval hours")
assert.EqualValues(
t,
4*60*1000000+5*1000000+6,
i.Microseconds(),
"interval microseconds",
)
}
func TestScanInterval(t *testing.T) {
i := new(Interval)
_ = i.Scan("2 days")
assert.EqualValues(t, 0, i.Years(), "scanned interval years")
assert.EqualValues(t, 48, i.Hours(), "scanned interval hours")
assert.EqualValues(t, 0, i.Microseconds(), "scanned interval microseconds")
}
func TestIntervalValue(t *testing.T) {
i := new(Interval)
_ = i.Scan("3 years 182 days 01:22:33.456789")
val, err := i.Value()
assert.Nil(t, err, "Interval.Value() error")
assert.EqualValues(
t,
"3 years 182 days 1 hours 22 minutes 33 seconds 456 milliseconds 789 microseconds",
val,
"Interval.Value() result")
}
func TestZeroInterval(t *testing.T) {
i := new(Interval)
assert.EqualValues(t, 0, i.Microseconds(), "Interval.Scan() result")
assert.EqualValues(t, 0, i.Hours(), "Interval.Scan() result")
assert.EqualValues(t, 0, i.Years(), "Interval.Scan() result")
val, err := i.Value()
assert.Nil(t, err, "Interval.Value() error")
assert.EqualValues(t, "0 microseconds", val, "Interval.Value() result")
assert.NoError(t, i.Scan("00:00:00"), "Interval.Scan() error")
assert.EqualValues(t, 0, i.Microseconds(), "Interval.Scan() result")
assert.EqualValues(t, 0, i.Hours(), "Interval.Scan() result")
assert.EqualValues(t, 0, i.Years(), "Interval.Scan() result")
val, err = i.Value()
assert.Nil(t, err, "Interval.Value() error")
assert.EqualValues(t, "0 microseconds", val, "Interval.Value() result")
}