aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/template_test.go
diff options
context:
space:
mode:
authorTatsushi Demachi <[email protected]>2014-08-16 13:12:34 +0900
committerspf13 <[email protected]>2014-08-18 11:31:17 -0400
commit002a5b675691a06cc593e2728bb00731cafa964f (patch)
treeee411547d7d2445282198b7380d693f00cc9d3a9 /hugolib/template_test.go
parent6e15f652bdef4f7e9d9c9b4c0cd764707aa7e48e (diff)
downloadhugo-002a5b675691a06cc593e2728bb00731cafa964f.tar.gz
hugo-002a5b675691a06cc593e2728bb00731cafa964f.zip
Add 'where' template function
Diffstat (limited to 'hugolib/template_test.go')
-rw-r--r--hugolib/template_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/hugolib/template_test.go b/hugolib/template_test.go
index 029e2a49f..9a34e99de 100644
--- a/hugolib/template_test.go
+++ b/hugolib/template_test.go
@@ -55,3 +55,30 @@ func TestFirst(t *testing.T) {
}
}
}
+
+func TestWhere(t *testing.T) {
+ type X struct {
+ A, B string
+ }
+ for i, this := range []struct {
+ sequence interface{}
+ key interface{}
+ match interface{}
+ expect interface{}
+ }{
+ {[]map[int]string{{1: "a", 2: "m"}, {1: "c", 2: "d"}, {1: "e", 3: "m"}}, 2, "m", []map[int]string{{1: "a", 2: "m"}}},
+ {[]map[string]int{{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "x": 4}}, "b", 4, []map[string]int{{"a": 3, "b": 4}}},
+ {[]X{{"a", "b"}, {"c", "d"}, {"e", "f"}}, "B", "f", []X{{"e", "f"}}},
+ {[]*map[int]string{&map[int]string{1: "a", 2: "m"}, &map[int]string{1: "c", 2: "d"}, &map[int]string{1: "e", 3: "m"}}, 2, "m", []*map[int]string{&map[int]string{1: "a", 2: "m"}}},
+ {[]*X{&X{"a", "b"}, &X{"c", "d"}, &X{"e", "f"}}, "B", "f", []*X{&X{"e", "f"}}},
+ } {
+ results, err := Where(this.sequence, this.key, this.match)
+ if err != nil {
+ t.Errorf("[%d] failed: %s", i, err)
+ continue
+ }
+ if !reflect.DeepEqual(results, this.expect) {
+ t.Errorf("[%d] Where clause matching %v with %v, got %v but expected %v", i, this.key, this.match, results, this.expect)
+ }
+ }
+}