summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspf13 <steve.francia@gmail.com>2013-08-13 10:47:58 -0400
committerspf13 <steve.francia@gmail.com>2013-08-13 10:47:58 -0400
commit6e27239485ffd83b33b743fef53efffd63f0826c (patch)
treeae2b94118439cd3e7b3350585b70497b8ef5ac26
parentec02fa4bddaf07d392671497c31c8136763d78f7 (diff)
parentca5a94a98866a664fb68be06b609537a619a19ea (diff)
Merge branch 'master' of github.com:spf13/hugo
-rw-r--r--hugolib/helpers.go2
-rw-r--r--hugolib/page_index_test.go79
2 files changed, 80 insertions, 1 deletions
diff --git a/hugolib/helpers.go b/hugolib/helpers.go
index b2eb39673..c814a6289 100644
--- a/hugolib/helpers.go
+++ b/hugolib/helpers.go
@@ -27,7 +27,7 @@ import (
"time"
)
-var sanitizeRegexp = regexp.MustCompile("[^a-zA-Z0-9/_-]")
+var sanitizeRegexp = regexp.MustCompile("[^a-zA-Z0-9./_-]")
// TODO: Make these wrappers private
// Wrapper around Fprintf taking verbose flag in account.
diff --git a/hugolib/page_index_test.go b/hugolib/page_index_test.go
new file mode 100644
index 000000000..49c7504c7
--- /dev/null
+++ b/hugolib/page_index_test.go
@@ -0,0 +1,79 @@
+package hugolib
+
+import (
+ "strings"
+ "testing"
+)
+
+var PAGE_YAML_WITH_INDEXES_A = `---
+tags: ['a', 'b', 'c']
+categories: 'd'
+---
+YAML frontmatter with tags and categories index.`
+
+var PAGE_YAML_WITH_INDEXES_B = `---
+tags:
+ - "a"
+ - "b"
+ - "c"
+categories: 'd'
+---
+YAML frontmatter with tags and categories index.`
+
+var PAGE_JSON_WITH_INDEXES = `{
+ "categories": "d",
+ "tags": [
+ "a",
+ "b",
+ "c"
+ ]
+}
+JSON Front Matter with tags and categories`
+
+var PAGE_TOML_WITH_INDEXES = `+++
+tags = [ "a", "b", "c" ]
+categories = "d"
++++
+TOML Front Matter with tags and categories`
+
+func TestParseIndexes(t *testing.T) {
+ for _, test := range []string{PAGE_TOML_WITH_INDEXES,
+ PAGE_JSON_WITH_INDEXES,
+ PAGE_YAML_WITH_INDEXES_A,
+ PAGE_YAML_WITH_INDEXES_B,
+ } {
+ p, err := ReadFrom(strings.NewReader(test), "page/with/index")
+ if err != nil {
+ t.Fatalf("Failed parsing page: %s", 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
+}