加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
outputer_test.go 26.24 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2021-09-06 11:14 . remove some methods
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
package carbon
import (
"fmt"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCarbon_String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05 13:14:15"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, fmt.Sprintf("%s", Parse(test.input)), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05 13:14:15 +0800 CST"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToMonthString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-01-05", "January"},
{"2020-02-05", "February"},
{"2020-03-05", "March"},
{"2020-04-05", "April"},
{"2020-05-05", "May"},
{"2020-06-05", "June"},
{"2020-07-05", "July"},
{"2020-08-05", "August"},
{"2020-09-05", "September"},
{"2020-10-05", "October"},
{"2020-11-05", "November"},
{"2020-12-05", "December"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToMonthString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToMonthString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToShortMonthString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-01-05", "Jan"},
{"2020-02-05", "Feb"},
{"2020-03-05", "Mar"},
{"2020-04-05", "Apr"},
{"2020-05-05", "May"},
{"2020-06-05", "Jun"},
{"2020-07-05", "Jul"},
{"2020-08-05", "Aug"},
{"2020-09-05", "Sep"},
{"2020-10-05", "Oct"},
{"2020-11-05", "Nov"},
{"2020-12-05", "Dec"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortMonthString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortMonthString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToWeekString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-01", "Saturday"},
{"2020-08-02", "Sunday"},
{"2020-08-03", "Monday"},
{"2020-08-04", "Tuesday"},
{"2020-08-05", "Wednesday"},
{"2020-08-06", "Thursday"},
{"2020-08-07", "Friday"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToWeekString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToWeekString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToShortWeekString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-01", "Sat"},
{"2020-08-02", "Sun"},
{"2020-08-03", "Mon"},
{"2020-08-04", "Tue"},
{"2020-08-05", "Wed"},
{"2020-08-06", "Thu"},
{"2020-08-07", "Fri"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortWeekString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortWeekString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToDayDateTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, Aug 5, 2020 1:14 PM"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDayDateTimeString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDayDateTimeString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToDateTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05 13:14:15"},
{"2020-08-05", "2020-08-05 00:00:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDateTimeString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDateTimeString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToShortDateTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "20200805131415"},
{"2020-08-05", "20200805000000"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortDateTimeString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortDateTimeString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05"},
{"2020-08-05", "2020-08-05"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDateString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDateString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToShortDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "20200805"},
{"2020-08-05", "20200805"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortDateString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortDateString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "13:14:15"},
{"2020-08-05", "00:00:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToTimeString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToTimeString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToShortTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "131415"},
{"2020-08-05", "000000"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortTimeString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortTimeString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToAtomString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToAtomString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToAtomString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToAnsicString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed Aug 5 13:14:15 2020"},
{"2020-08-05", "Wed Aug 5 00:00:00 2020"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToAnsicString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToAnsicString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToCookieString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wednesday, 05-Aug-2020 13:14:15 CST"},
{"2020-08-05", "Wednesday, 05-Aug-2020 00:00:00 CST"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToCookieString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToCookieString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRssString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 +0800"},
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRssString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRssString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToW3cString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToW3cString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToW3cString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToUnixDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed Aug 5 13:14:15 CST 2020"},
{"2020-08-05", "Wed Aug 5 00:00:00 CST 2020"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToUnixDateString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToUnixDateString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRubyDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed Aug 05 13:14:15 +0800 2020"},
{"2020-08-05", "Wed Aug 05 00:00:00 +0800 2020"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRubyDateString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRubyDateString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToKitchenString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "1:14PM"},
{"2020-08-05", "12:00AM"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, test.expected, c.ToKitchenString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, test.expected, c.ToKitchenString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToIso8601String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToIso8601String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToIso8601String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc822String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "05 Aug 20 13:14 CST"},
{"2020-08-05", "05 Aug 20 00:00 CST"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc822String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc822String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc822zString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "05 Aug 20 13:14 +0800"},
{"2020-08-05", "05 Aug 20 00:00 +0800"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc822zString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc822zString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc850String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wednesday, 05-Aug-20 13:14:15 CST"},
{"2020-08-05", "Wednesday, 05-Aug-20 00:00:00 CST"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc850String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc850String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc1036String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 20 13:14:15 +0800"},
{"2020-08-05", "Wed, 05 Aug 20 00:00:00 +0800"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1036String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1036String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc1123String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 CST"},
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 CST"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1123String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1123String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc1123zString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 +0800"},
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1123zString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1123zString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc2822String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 +0800"},
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc2822String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc2822String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc3339String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc3339String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc3339String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc7231String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 GMT"},
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 GMT"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc7231String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc7231String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_Layout(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
param string // 参数值
expected string // 期望值
}{
{"", "2006年01月02日", ""},
{"0", "2006年01月02日", ""},
{"0000-00-00", "2006年01月02日", ""},
{"00:00:00", "2006年01月02日", ""},
{"0000-00-00 00:00:00", "Y年m月d日", ""},
{"2020-08-05 13:14:15", "2006年01月02日", "2020年08月05日"},
{"2020-08-05 13:14:15", "Mon, 02 Jan 2006 15:04:05 GMT", "Wed, 05 Aug 2020 13:14:15 GMT"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Layout(test.param), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToLayoutString(test.param), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Layout(test.param, PRC), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToLayoutString(test.param, PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_Format(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
param string // 参数值
expected string // 期望值
}{
{"", "Y年m月d日", ""},
{"0", "Y年m月d日", ""},
{"0000-00-00", "Y年m月d日", ""},
{"00:00:00", "Y年m月d日", ""},
{"0000-00-00 00:00:00", "Y年m月d日", ""},
{"2020-08-05 13:14:15", "Y年m月d日", "2020年08月05日"},
{"2020-08-05 01:14:15", "j", "5"},
{"2020-08-05 01:14:15", "W", "32"},
{"2020-08-05 01:14:15", "M", "Aug"},
{"2020-08-05 01:14:15", "F", "August"},
{"2020-08-05 01:14:15", "N", "3"},
{"2020-08-05 01:14:15", "L", "1"},
{"2020-08-05 01:14:15", "L", "1"},
{"2021-08-05 01:14:15", "L", "0"},
{"2020-08-05 01:14:15", "G", "1"},
{"2020-08-05 13:14:15", "U", "1596604455"},
{"2020-08-05 13:14:15.999", "u", "999"},
{"2020-08-05 13:14:15", "w", "2"},
{"2020-08-05 13:14:15", "t", "31"},
{"2020-08-05 13:14:15", "z", "217"},
{"2020-08-05 13:14:15", "e", "PRC"},
{"2020-08-05 13:14:15", "Q", "3"},
{"2020-08-05 13:14:15", "C", "21"},
{"2020-08-05 13:14:15", "jS", "5th"},
{"2020-08-22 13:14:15", "jS", "22nd"},
{"2020-08-23 13:14:15", "jS", "23rd"},
{"2020-08-31 13:14:15", "jS", "31st"},
{"2020-08-31 13:14:15", "I\\t \\i\\s Y-m-d H:i:s", "It is 2020-08-31 13:14:15"},
{"2020-08-05 13:14:15", "上次上报时间:Y-m-d H:i:s,请每日按时打卡", "上次上报时间:2020-08-05 13:14:15,请每日按时打卡"},
{"2020-08-05 13:14:15", "l jS of F Y h:i:s A", "Wednesday 5th of August 2020 01:14:15 PM"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Format(test.param), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToFormatString(test.param), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToFormatString(test.param, PRC), "Current test index is "+strconv.Itoa(index))
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化