1 Star 0 Fork 63

jangocheng/carbon

forked from dromara/carbon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tag_unit_test.go 896 Bytes
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2024-01-12 10:57 . v2.3.5
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"))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jangocheng/carbon.git
git@gitee.com:jangocheng/carbon.git
jangocheng
carbon
carbon
master

搜索帮助