forked from dromara/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag_unit_test.go
46 lines (40 loc) · 896 Bytes
/
tag_unit_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
package carbon
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestCarbon_parseTag(t *testing.T) {
now := Now().SetTag(&tag{
carbon: "",
})
key, value, tz := now.parseTag()
assert.Equal(t, "layout", key)
assert.Equal(t, DateTimeLayout, value)
assert.Equal(t, Local, tz)
}
func TestCarbon_SetTag(t *testing.T) {
c := NewCarbon().SetTag(&tag{
tz: PRC,
})
assert.Nil(t, c.Error)
assert.Equal(t, PRC, c.tag.tz)
}
func TestError_SetTag(t *testing.T) {
now := Now("xxx").SetTag(&tag{
carbon: "datetime",
tz: Local,
})
assert.NotNil(t, now.Error)
}
func TestError_LoadTag(t *testing.T) {
type Student struct {
Birthday Carbon `json:"birthday" carbon:"xxx"`
}
student := Student{
Birthday: Now(),
}
err1 := LoadTag(student)
assert.Equal(t, err1, invalidPtrError())
err2 := LoadTag(&student)
assert.Equal(t, err2, invalidTagError("Birthday"))
}