summaryrefslogtreecommitdiffstats
path: root/hugolib/site_url_test.go
diff options
context:
space:
mode:
authorNoah Campbell <noahcampbell@gmail.com>2013-09-12 16:17:53 -0700
committerNoah Campbell <noahcampbell@gmail.com>2013-09-12 16:18:30 -0700
commit2f10da15707e1db0fab90524a247bc8a2d3ded90 (patch)
tree0023014b3e3ce84d541afd017e1a3b72a251e4f1 /hugolib/site_url_test.go
parent74b55fc7c87f2887c42ce8626cb461fee5d7b907 (diff)
Move alias rendering to target
Diffstat (limited to 'hugolib/site_url_test.go')
-rw-r--r--hugolib/site_url_test.go37
1 files changed, 32 insertions, 5 deletions
diff --git a/hugolib/site_url_test.go b/hugolib/site_url_test.go
index f6098634b..5f741ae83 100644
--- a/hugolib/site_url_test.go
+++ b/hugolib/site_url_test.go
@@ -3,11 +3,12 @@ package hugolib
import (
"bytes"
"io"
- "strings"
"testing"
)
-const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\n---\nslug doc 1 content"
+const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\naliases:\n - sd1/foo/\n - sd2\n - sd3/\n - sd4.php\n---\nslug doc 1 content"
+
+//const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\n---\nslug doc 1 content"
const SLUG_DOC_2 = "---\ntitle: slug doc 2\nslug: slug-doc-2\n---\nslug doc 2 content"
const INDEX_TEMPLATE = "{{ range .Data.Pages }}.{{ end }}"
@@ -43,14 +44,25 @@ func (t *InMemoryTarget) Translate(label string) (dest string, err error) {
return label, nil
}
+var urlFakeSource = []byteSource{
+ {"content/blue/doc1.md", []byte(SLUG_DOC_1)},
+ {"content/blue/doc2.md", []byte(SLUG_DOC_2)},
+}
+
func TestPageCount(t *testing.T) {
target := new(InMemoryTarget)
- s := &Site{Target: target}
+ s := &Site{
+ Target: target,
+ Config: Config{UglyUrls: false},
+ Source: &inMemorySource{urlFakeSource},
+ }
+ s.initializeSiteInfo()
s.prepTemplates()
must(s.addTemplate("indexes/blue.html", INDEX_TEMPLATE))
- s.Pages = append(s.Pages, mustReturn(ReadFrom(strings.NewReader(SLUG_DOC_1), "content/blue/doc1.md")))
- s.Pages = append(s.Pages, mustReturn(ReadFrom(strings.NewReader(SLUG_DOC_2), "content/blue/doc2.md")))
+ if err := s.CreatePages(); err != nil {
+ t.Errorf("Unable to create pages: %s", err)
+ }
if err := s.BuildSiteMeta(); err != nil {
t.Errorf("Unable to build site metadata: %s", err)
}
@@ -59,6 +71,10 @@ func TestPageCount(t *testing.T) {
t.Errorf("Unable to render site lists: %s", err)
}
+ if err := s.RenderAliases(); err != nil {
+ t.Errorf("Unable to render site lists: %s", err)
+ }
+
blueIndex := target.files["blue"]
if blueIndex == nil {
t.Errorf("No indexed rendered. %v", target.files)
@@ -67,4 +83,15 @@ func TestPageCount(t *testing.T) {
if len(blueIndex) != 2 {
t.Errorf("Number of pages does not equal 2, got %d. %q", len(blueIndex), blueIndex)
}
+
+ for _, s := range []string{
+ "sd1/foo/index.html",
+ "sd2",
+ "sd3/index.html",
+ "sd4.php",
+ } {
+ if _, ok := target.files[s]; !ok {
+ t.Errorf("No alias rendered: %s", s)
+ }
+ }
}