summaryrefslogtreecommitdiffstats
path: root/tpl/strings/strings_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tpl/strings/strings_test.go')
-rw-r--r--tpl/strings/strings_test.go50
1 files changed, 37 insertions, 13 deletions
diff --git a/tpl/strings/strings_test.go b/tpl/strings/strings_test.go
index 92767925a..4fcd3b59a 100644
--- a/tpl/strings/strings_test.go
+++ b/tpl/strings/strings_test.go
@@ -153,17 +153,30 @@ func TestContainsNonSpace(t *testing.T) {
for _, test := range []struct {
s any
expect bool
+ isErr bool
}{
- {"", false},
- {" ", false},
- {" ", false},
- {"\t", false},
- {"\r", false},
- {"a", true},
- {" a", true},
- {"a\n", true},
+ {"", false, false},
+ {" ", false, false},
+ {" ", false, false},
+ {"\t", false, false},
+ {"\r", false, false},
+ {"a", true, false},
+ {" a", true, false},
+ {"a\n", true, false},
+ // error
+ {tstNoStringer{}, false, true},
} {
- c.Assert(ns.ContainsNonSpace(test.s), qt.Equals, test.expect)
+
+ result, err := ns.ContainsNonSpace(test.s)
+
+ if test.isErr {
+ c.Assert(err, qt.IsNotNil)
+ continue
+ }
+
+ c.Assert(err, qt.IsNil)
+ c.Assert(result, qt.Equals, test.expect)
+
}
}
@@ -812,21 +825,32 @@ func TestDiff(t *testing.T) {
t.Parallel()
c := qt.New(t)
- for _, tt := range []struct {
+ for _, test := range []struct {
oldname string
old any
newname string
new any
- expect string
+ expect any
}{
{"old", "foo\n", "new", "bar\n", "diff old new\n--- old\n+++ new\n@@ -1,1 +1,1 @@\n-foo\n+bar\n"},
{"old", "foo\n", "new", "foo\n", ""},
{"old", "foo\n", "new", "", "diff old new\n--- old\n+++ new\n@@ -1,1 +0,0 @@\n-foo\n"},
{"old", "foo\n", "new", nil, "diff old new\n--- old\n+++ new\n@@ -1,1 +0,0 @@\n-foo\n"},
{"old", "", "new", "", ""},
+ // errors
+ {"old", tstNoStringer{}, "new", "foo", false},
+ {"old", "foo", "new", tstNoStringer{}, false},
} {
- result := ns.Diff(tt.oldname, tt.old, tt.newname, tt.new)
- c.Assert(result, qt.Equals, tt.expect)
+ result, err := ns.Diff(test.oldname, test.old, test.newname, test.new)
+
+ if b, ok := test.expect.(bool); ok && !b {
+ c.Assert(err, qt.Not(qt.IsNil))
+ continue
+ }
+
+ c.Assert(err, qt.IsNil)
+ c.Assert(result, qt.Equals, test.expect)
+
}
}