mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Clean up the trim template func test
This commit is contained in:
parent
8c84048033
commit
c1e4309516
1 changed files with 27 additions and 8 deletions
|
@ -1639,14 +1639,33 @@ func TestReplace(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrim(t *testing.T) {
|
func TestTrim(t *testing.T) {
|
||||||
v, _ := trim("1234 my way 13", "123")
|
|
||||||
assert.Equal(t, "4 my way ", v)
|
for i, this := range []struct {
|
||||||
v, _ = trim(" my way ", " ")
|
v1 interface{}
|
||||||
assert.Equal(t, "my way", v)
|
v2 string
|
||||||
v, _ = trim(1234, "14")
|
expect interface{}
|
||||||
assert.Equal(t, "23", v)
|
}{
|
||||||
_, e := trim(tstNoStringer{}, " ")
|
{"1234 my way 13", "123 ", "4 my way"},
|
||||||
assert.NotNil(t, e, "tstNoStringer isn't trimmable")
|
{" my way ", " ", "my way"},
|
||||||
|
{1234, "14", "23"},
|
||||||
|
{tstNoStringer{}, " ", false},
|
||||||
|
} {
|
||||||
|
result, err := trim(this.v1, this.v2)
|
||||||
|
|
||||||
|
if b, ok := this.expect.(bool); ok && !b {
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("[%d] trim didn't return an expected error", i)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("[%d] failed: %s", i, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(result, this.expect) {
|
||||||
|
t.Errorf("[%d] got '%s' but expected %s", i, result, this.expect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDateFormat(t *testing.T) {
|
func TestDateFormat(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue