diff options
author | spf13 <steve.francia@gmail.com> | 2014-04-08 23:15:57 -0400 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-04-09 17:15:04 -0400 |
commit | 93bcddebb3030705dcb643dffb65890a270b5182 (patch) | |
tree | 46dac123f4ea8320d7dde2823b0d7c7df75688d0 /hugolib/page_taxonomy_test.go | |
parent | aae6fa0b6b6319187992231baf773768585820d6 (diff) |
Renamed Indexes to Taxonomies. Old template and config parameters still work.
Diffstat (limited to 'hugolib/page_taxonomy_test.go')
-rw-r--r-- | hugolib/page_taxonomy_test.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/hugolib/page_taxonomy_test.go b/hugolib/page_taxonomy_test.go new file mode 100644 index 000000000..36924f9d5 --- /dev/null +++ b/hugolib/page_taxonomy_test.go @@ -0,0 +1,79 @@ +package hugolib + +import ( + "strings" + "testing" +) + +var PAGE_YAML_WITH_TAXONOMIES_A = `--- +tags: ['a', 'b', 'c'] +categories: 'd' +--- +YAML frontmatter with tags and categories taxonomy.` + +var PAGE_YAML_WITH_TAXONOMIES_B = `--- +tags: + - "a" + - "b" + - "c" +categories: 'd' +--- +YAML frontmatter with tags and categories taxonomy.` + +var PAGE_JSON_WITH_TAXONOMIES = `{ + "categories": "d", + "tags": [ + "a", + "b", + "c" + ] +} +JSON Front Matter with tags and categories` + +var PAGE_TOML_WITH_TAXONOMIES = `+++ +tags = [ "a", "b", "c" ] +categories = "d" ++++ +TOML Front Matter with tags and categories` + +func TestParseTaxonomies(t *testing.T) { + for _, test := range []string{PAGE_TOML_WITH_TAXONOMIES, + PAGE_JSON_WITH_TAXONOMIES, + PAGE_YAML_WITH_TAXONOMIES_A, + PAGE_YAML_WITH_TAXONOMIES_B, + } { + p, err := ReadFrom(strings.NewReader(test), "page/with/taxonomy") + if err != nil { + t.Fatalf("Failed parsing %q: %s", test, err) + } + + param := p.GetParam("tags") + params := param.([]string) + + expected := []string{"a", "b", "c"} + if !compareStringSlice(params, expected) { + t.Errorf("Expected %s: got: %s", expected, params) + } + + param = p.GetParam("categories") + singleparam := param.(string) + + if singleparam != "d" { + t.Fatalf("Expected: d, got: %s", singleparam) + } + } +} + +func compareStringSlice(a, b []string) bool { + if len(a) != len(b) { + return false + } + + for i, v := range a { + if b[i] != v { + return false + } + } + + return true +} |