mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-14 00:16:45 +00:00
Add tests for Apply
This commit is contained in:
1 parent
3f0f186b91
commit
f470cf9590
2 files changed
+42
No files matched your search
@@ -832,6 +832,48 @@ func TestMarkdownify(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApply(t *testing.T) {
|
||||||
|
strings := []interface{}{"a\n", "b\n"}
|
||||||
|
noStringers := []interface{}{tstNoStringer{}, tstNoStringer{}}
|
||||||
|
|
||||||
|
var nilErr *error = nil
|
||||||
|
|
||||||
|
chomped, _ := Apply(strings, "chomp", ".")
|
||||||
|
assert.Equal(t, []interface{}{"a", "b"}, chomped)
|
||||||
|
|
||||||
|
chomped, _ = Apply(strings, "chomp", "c\n")
|
||||||
|
assert.Equal(t, []interface{}{"c", "c"}, chomped)
|
||||||
|
|
||||||
|
chomped, _ = Apply(nil, "chomp", ".")
|
||||||
|
assert.Equal(t, []interface{}{}, chomped)
|
||||||
|
|
||||||
|
_, err := Apply(strings, "apply", ".")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("apply with apply should fail")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = Apply(nilErr, "chomp", ".")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("apply with nil in seq should fail")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = Apply(strings, "dobedobedo", ".")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("apply with unknown func should fail")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = Apply(noStringers, "chomp", ".")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("apply when func fails should fail")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = Apply(tstNoStringer{}, "chomp", ".")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("apply with non-sequence should fail")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestChomp(t *testing.T) {
|
func TestChomp(t *testing.T) {
|
||||||
base := "\n This is\na story "
|
base := "\n This is\na story "
|
||||||
for i, item := range []string{
|
for i, item := range []string{
|
||||||
|
|||||||
Executable
BIN
Binary file not shown.
Reference in new issue
Block a user