-
Notifications
You must be signed in to change notification settings - Fork 1
/
local_date_test.go
45 lines (37 loc) · 1.03 KB
/
local_date_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
package time
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func Test(t *testing.T) {
assert.Equal(t, NewLocalDate(2000, 1, 1), NewLocalDate(2000, 1, 1))
assert.NotEqual(t, NewLocalDate(2000, 1, 1), NewLocalDate(2000, 1, 2))
}
func TestConversionToTime(t *testing.T) {
assert.Equal(t,
NewLocalDate(2005, 6, 7).GetStartOfDayUTC(),
time.Date(2005, 6, 7, 0, 0, 0, 0, time.UTC))
}
func TestMarshalText(t *testing.T) {
d, _ := NewLocalDate(22345, 01, 01).MarshalText()
assert.Equal(t, []byte("22345-01-01"), d)
}
func TestMarshalJSON(t *testing.T) {
d, _ := NewLocalDate(22345, 01, 01).MarshalJSON()
assert.Equal(t, []byte(`"22345-01-01"`), d)
}
func TestUnmarshalText(t *testing.T) {
d := NullLocalDate
var dp = &d
err := dp.UnmarshalText([]byte("2000-09-10"))
assert.Nil(t, err)
assert.Equal(t, NewLocalDate(2000, 9, 10), d)
}
func TestUnmarshalJSON(t *testing.T) {
d := NullLocalDate
var dp = &d
err := dp.UnmarshalJSON([]byte(`"2000-09-10"`))
assert.Nil(t, err)
assert.Equal(t, NewLocalDate(2000, 9, 10), d)
}