Add more test (#2692)

master
anqiansong 2 years ago committed by GitHub
parent ebe28882eb
commit a49f9060c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

Binary file not shown.

@ -7,68 +7,188 @@ import (
) )
func TestString_IsEmptyOrSpace(t *testing.T) { func TestString_IsEmptyOrSpace(t *testing.T) {
ret := From(" ").IsEmptyOrSpace() cases := []struct {
assert.Equal(t, true, ret) input string
ret2 := From("ll??").IsEmptyOrSpace() want bool
assert.Equal(t, false, ret2) }{
ret3 := From(` {
`).IsEmptyOrSpace() want: true,
assert.Equal(t, true, ret3) },
{
input: " ",
want: true,
},
{
input: "\t",
want: true,
},
{
input: "\n",
want: true,
},
{
input: "\f",
want: true,
},
{
input: " ",
want: true,
},
}
for _, v := range cases {
s := From(v.input)
assert.Equal(t, v.want, s.IsEmptyOrSpace())
}
} }
func TestString_Snake2Camel(t *testing.T) { func TestString_Snake2Camel(t *testing.T) {
ret := From("____this_is_snake").ToCamel() cases := []struct {
assert.Equal(t, "ThisIsSnake", ret) input string
want string
ret2 := From("测试_test_Data").ToCamel() }{
assert.Equal(t, "测试TestData", ret2) {
input: "__",
ret3 := From("___").ToCamel() want: "",
assert.Equal(t, "", ret3) },
{
ret4 := From("testData_").ToCamel() input: "go_zero",
assert.Equal(t, "TestData", ret4) want: "GoZero",
},
ret5 := From("testDataTestData").ToCamel() {
assert.Equal(t, "TestDataTestData", ret5) input: "の_go_zero",
want: "のGoZero",
},
{
input: "goZero",
want: "GoZero",
},
{
input: "goZero",
want: "GoZero",
},
{
input: "goZero_",
want: "GoZero",
},
{
input: "go_Zero_",
want: "GoZero",
},
{
input: "_go_Zero_",
want: "GoZero",
},
}
for _, c := range cases {
ret := From(c.input).ToCamel()
assert.Equal(t, c.want, ret)
}
} }
func TestString_Camel2Snake(t *testing.T) { func TestString_Camel2Snake(t *testing.T) {
ret := From("ThisIsCCCamel").ToSnake() cases := []struct {
assert.Equal(t, "this_is_c_c_camel", ret) input string
want string
ret2 := From("测试Test_Data_test_data").ToSnake() }{
assert.Equal(t, "测试_test__data_test_data", ret2) {
input: "goZero",
want: "go_zero",
},
{
input: "Gozero",
want: "gozero",
},
{
input: "GoZero",
want: "go_zero",
},
{
input: "Go_Zero",
want: "go__zero",
},
}
for _, c := range cases {
ret := From(c.input).ToSnake()
assert.Equal(t, c.want, ret)
}
} }
func TestTitle(t *testing.T) { func TestTitle(t *testing.T) {
cases := []struct { cases := []struct {
src string input string
exec string want string
}{
{
input: "go zero",
want: "Go Zero",
},
{
input: "goZero",
want: "GoZero",
},
{
input: "GoZero",
want: "GoZero",
},
{
input: "の go zero",
want: "の Go Zero",
},
{
input: "Gozero",
want: "Gozero",
},
{
input: "Go_zero",
want: "Go_zero",
},
{
input: "go_zero",
want: "Go_zero",
},
{
input: "Go_Zero",
want: "Go_Zero",
},
}
for _, c := range cases {
ret := From(c.input).Title()
assert.Equal(t, c.want, ret)
}
}
func TestUntitle(t *testing.T) {
cases := []struct {
input string
want string
}{ }{
{ {
src: "hello world!", input: "go zero",
exec: "Hello World!", want: "go zero",
},
{
input: "GoZero",
want: "goZero",
}, },
{ {
src: "go zero", input: "Gozero",
exec: "Go Zero", want: "gozero",
}, },
{ {
src: "goZero", input: "Go_zero",
exec: "GoZero", want: "go_zero",
}, },
{ {
src: "GoZero", input: "go_zero",
exec: "GoZero", want: "go_zero",
}, },
{ {
src: "测试this is data", input: "Go_Zero",
exec: "测试This Is Data", want: "go_Zero",
}, },
} }
for _, c := range cases { for _, c := range cases {
ret := From(c.src).Title() ret := From(c.input).Untitle()
assert.Equal(t, c.exec, ret) assert.Equal(t, c.want, ret)
} }
} }

Loading…
Cancel
Save