mirror of
https://gitee.com/dromara/carbon.git
synced 2024-11-30 03:07:36 +08:00
36 lines
697 B
Go
36 lines
697 B
Go
package carbon
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestCarbon_Tag(t *testing.T) {
|
|
now := Now().SetTag("layout")
|
|
assert.Equal(t, "layout", now.Tag())
|
|
}
|
|
|
|
func TestCarbon_SetTag(t *testing.T) {
|
|
now := Now().SetTag("layout")
|
|
assert.Equal(t, "layout", now.tag)
|
|
}
|
|
|
|
func TestError_SetTag(t *testing.T) {
|
|
now := Now("xxx").SetTag("layout")
|
|
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())
|
|
}
|