summaryrefslogtreecommitdiffstats
path: root/helpers/general_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-07-02 20:14:06 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-07-04 09:11:49 +0200
commita1d260b41a6673adef679ec4e262c5f390432cf5 (patch)
treef9a86343fb6a73defb0805578d25eb72c6afb534 /helpers/general_test.go
parentdd9b1baab0cb860a3eb32fd9043bac18cab3f9f0 (diff)
hugolib: Extend the sections API
This commit adds some section related methods that have been asked for: * .CurrentSection * .IsDescendant * .IsAncestor Fixes #3591
Diffstat (limited to 'helpers/general_test.go')
-rw-r--r--helpers/general_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/helpers/general_test.go b/helpers/general_test.go
index ee4ed2370..4d82bc0cf 100644
--- a/helpers/general_test.go
+++ b/helpers/general_test.go
@@ -64,6 +64,45 @@ func TestFirstUpper(t *testing.T) {
}
}
+func TestHasStringsPrefix(t *testing.T) {
+ for i, this := range []struct {
+ s []string
+ prefix []string
+ expect bool
+ }{
+ {[]string{"a"}, []string{"a"}, true},
+ {[]string{}, []string{}, true},
+ {[]string{"a", "b", "c"}, []string{"a", "b"}, true},
+ {[]string{"d", "a", "b", "c"}, []string{"a", "b"}, false},
+ {[]string{"abra", "ca", "dabra"}, []string{"abra", "ca"}, true},
+ {[]string{"abra", "ca"}, []string{"abra", "ca", "dabra"}, false},
+ } {
+ result := HasStringsPrefix(this.s, this.prefix)
+ if result != this.expect {
+ t.Fatalf("[%d] got %t but expected %t", i, result, this.expect)
+ }
+ }
+}
+
+func TestHasStringsSuffix(t *testing.T) {
+ for i, this := range []struct {
+ s []string
+ suffix []string
+ expect bool
+ }{
+ {[]string{"a"}, []string{"a"}, true},
+ {[]string{}, []string{}, true},
+ {[]string{"a", "b", "c"}, []string{"b", "c"}, true},
+ {[]string{"abra", "ca", "dabra"}, []string{"abra", "ca"}, false},
+ {[]string{"abra", "ca", "dabra"}, []string{"ca", "dabra"}, true},
+ } {
+ result := HasStringsSuffix(this.s, this.suffix)
+ if result != this.expect {
+ t.Fatalf("[%d] got %t but expected %t", i, result, this.expect)
+ }
+ }
+}
+
var containsTestText = (`На берегу пустынных волн
Стоял он, дум великих полн,
И вдаль глядел. Пред ним широко