1 Star 0 Fork 66

ajunlonglive/carbon

forked from dromara/carbon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
carbon_test.go 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2021-08-10 11:01 . unified unit test format
package carbon
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCarbon_Now(t *testing.T) {
assert := assert.New(t)
actual1 := Now().ToDateString()
expected1 := time.Now().Format(DateFormat)
assert.Equal(expected1, actual1)
actual2 := Now(Local).ToDateString()
expected2 := time.Now().In(time.Local).Format(DateFormat)
assert.Equal(expected2, actual2)
}
func TestError_Now(t *testing.T) {
timezone := "xxx"
c := Now(timezone)
assert.NotNil(t, c.Error, "It should catch an exception in Now()")
}
func TestCarbon_Yesterday(t *testing.T) {
assert := assert.New(t)
c1 := Yesterday()
expected1 := time.Now().AddDate(0, 0, -1).Format(DateFormat)
assert.Nil(c1.Error)
assert.Equal(expected1, c1.ToDateString())
c2 := Yesterday(Local)
expected2 := time.Now().In(time.Local).AddDate(0, 0, -1).Format(DateFormat)
assert.Nil(c2.Error)
assert.Equal(expected2, c2.ToDateString())
c3 := Parse("2020-08-05").Yesterday()
assert.Nil(c3.Error)
assert.Equal("2020-08-04", c3.ToDateString(), "It should be equal to 2020-08-04")
}
func TestError_Yesterday(t *testing.T) {
timezone := "xxx"
c := Yesterday(timezone)
assert.NotNil(t, c.Error, "It should catch an exception in Yesterday()")
}
func TestCarbon_Tomorrow(t *testing.T) {
assert := assert.New(t)
c1 := Tomorrow()
expected1 := time.Now().AddDate(0, 0, 1).Format(DateFormat)
assert.Nil(c1.Error)
assert.Equal(expected1, c1.ToDateString())
c2 := Tomorrow(Local)
expected2 := time.Now().In(time.Local).AddDate(0, 0, 1).Format(DateFormat)
assert.Nil(c2.Error)
assert.Equal(expected2, c2.ToDateString())
c3 := Parse("2020-08-05").Tomorrow()
assert.Nil(c3.Error)
assert.Equal("2020-08-06", c3.ToDateString(), "It should be equal to 2020-08-06")
}
func TestError_Tomorrow(t *testing.T) {
timezone := "xxx"
c := Tomorrow(timezone)
assert.NotNil(t, c.Error, "It should catch an exception in Tomorrow()")
}
func TestCarbon_Time2Carbon(t *testing.T) {
assert := assert.New(t)
expected := time.Now().Format(DateTimeFormat)
actual := Time2Carbon(time.Now()).ToDateTimeString()
assert.Equal(expected, actual)
}
func TestCarbon_Carbon2Time(t *testing.T) {
assert := assert.New(t)
expected := time.Now().Format(DateTimeFormat)
actual := Now().Carbon2Time().Format(DateTimeFormat)
assert.Equal(expected, actual)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ajunlonglive/carbon.git
git@gitee.com:ajunlonglive/carbon.git
ajunlonglive
carbon
carbon
v2.0.1

搜索帮助

0d507c66 1850385 C8b1a773 1850385