32 Star 408 Fork 63

GVPdromara/carbon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
database_unit_test.go 1.98 KB
一键复制 编辑 原始数据 按行查看 历史
package carbon
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCarbon_Scan(t *testing.T) {
c := NewCarbon()
err := c.Scan(time.Now())
assert.Nil(t, err)
assert.Equal(t, c.ToDateTimeString(), Now().ToDateTimeString())
}
func TestCarbon_Value(t *testing.T) {
c := Now()
v, err := c.Value()
assert.Nil(t, err)
assert.Equal(t, v, c.time)
}
func TestError_Scan(t *testing.T) {
c, v := NewCarbon(), "xxx"
err := c.Scan(v)
assert.Equal(t, err, fmt.Errorf("can not convert %v to carbon", v))
}
func TestError_Value(t *testing.T) {
c := Parse("")
v, err := c.Value()
assert.Nil(t, err)
assert.Equal(t, v, nil)
}
func TestCarbon_GormDataType(t *testing.T) {
var carbon Carbon
assert.Equal(t, "time", carbon.GormDataType())
var dateTime DateTime
assert.Equal(t, "time", dateTime.GormDataType())
var dateTimeMilli DateTimeMilli
assert.Equal(t, "time", dateTimeMilli.GormDataType())
var dateTimeMicro DateTimeMicro
assert.Equal(t, "time", dateTimeMicro.GormDataType())
var dateTimeNano DateTimeNano
assert.Equal(t, "time", dateTimeNano.GormDataType())
var date Date
assert.Equal(t, "time", date.GormDataType())
var dateMilli DateMilli
assert.Equal(t, "time", dateMilli.GormDataType())
var dateMicro DateMicro
assert.Equal(t, "time", dateMicro.GormDataType())
var dateNano DateNano
assert.Equal(t, "time", dateNano.GormDataType())
var time Time
assert.Equal(t, "time", time.GormDataType())
var timeMilli TimeMilli
assert.Equal(t, "time", timeMilli.GormDataType())
var timeMicro TimeMicro
assert.Equal(t, "time", timeMicro.GormDataType())
var timeNano TimeNano
assert.Equal(t, "time", timeNano.GormDataType())
var timestamp Timestamp
assert.Equal(t, "int", timestamp.GormDataType())
var timestampMilli TimestampMilli
assert.Equal(t, "int", timestampMilli.GormDataType())
var timestampMicro TimestampMicro
assert.Equal(t, "int", timestampMicro.GormDataType())
var timestampNano TimestampNano
assert.Equal(t, "int", timestampNano.GormDataType())
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dromara/carbon.git
git@gitee.com:dromara/carbon.git
dromara
carbon
carbon
master

搜索帮助