2013-09-01 16:24:03 +00:00
|
|
|
package target
|
|
|
|
|
|
|
|
import (
|
2014-12-07 18:48:00 +00:00
|
|
|
"path/filepath"
|
2013-09-01 16:24:03 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-11-04 05:39:37 +00:00
|
|
|
func TestPageTranslator(t *testing.T) {
|
2013-09-01 16:24:03 +00:00
|
|
|
tests := []struct {
|
|
|
|
content string
|
|
|
|
expected string
|
|
|
|
}{
|
2013-09-01 16:56:58 +00:00
|
|
|
{"/", "index.html"},
|
2013-09-25 04:24:49 +00:00
|
|
|
{"index.html", "index.html"},
|
|
|
|
{"bar/index.html", "bar/index.html"},
|
2013-09-01 16:24:03 +00:00
|
|
|
{"foo", "foo/index.html"},
|
|
|
|
{"foo.html", "foo/index.html"},
|
|
|
|
{"foo.xhtml", "foo/index.xhtml"},
|
2013-09-12 17:48:59 +00:00
|
|
|
{"section", "section/index.html"},
|
|
|
|
{"section/", "section/index.html"},
|
2013-09-01 16:24:03 +00:00
|
|
|
{"section/foo", "section/foo/index.html"},
|
|
|
|
{"section/foo.html", "section/foo/index.html"},
|
|
|
|
{"section/foo.rss", "section/foo/index.rss"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2014-11-04 05:39:37 +00:00
|
|
|
f := new(PagePub)
|
2014-12-07 18:48:00 +00:00
|
|
|
dest, err := f.Translate(filepath.FromSlash(test.content))
|
|
|
|
expected := filepath.FromSlash(test.expected)
|
2013-09-01 16:24:03 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Translate returned and unexpected err: %s", err)
|
|
|
|
}
|
|
|
|
|
2014-12-07 18:48:00 +00:00
|
|
|
if dest != expected {
|
|
|
|
t.Errorf("Translate expected return: %s, got: %s", expected, dest)
|
2013-09-01 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-04 05:39:37 +00:00
|
|
|
func TestPageTranslatorBase(t *testing.T) {
|
2013-09-05 16:57:25 +00:00
|
|
|
tests := []struct {
|
2013-09-12 17:48:59 +00:00
|
|
|
content string
|
2013-09-05 16:57:25 +00:00
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{"/", "a/base/index.html"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2014-11-04 05:39:37 +00:00
|
|
|
f := &PagePub{PublishDir: "a/base"}
|
|
|
|
fts := &PagePub{PublishDir: "a/base/"}
|
2013-09-05 16:57:25 +00:00
|
|
|
|
2014-11-04 05:39:37 +00:00
|
|
|
for _, fs := range []*PagePub{f, fts} {
|
2013-09-05 16:57:25 +00:00
|
|
|
dest, err := fs.Translate(test.content)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Translated returned and err: %s", err)
|
|
|
|
}
|
|
|
|
|
2014-12-07 18:48:00 +00:00
|
|
|
if dest != filepath.FromSlash(test.expected) {
|
2013-09-05 16:57:25 +00:00
|
|
|
t.Errorf("Translate expected: %s, got: %s", test.expected, dest)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-18 05:16:54 +00:00
|
|
|
func TestTranslateUglyURLs(t *testing.T) {
|
2013-09-01 16:56:58 +00:00
|
|
|
tests := []struct {
|
|
|
|
content string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{"foo.html", "foo.html"},
|
|
|
|
{"/", "index.html"},
|
2013-09-12 17:48:59 +00:00
|
|
|
{"section", "section.html"},
|
2013-09-01 16:56:58 +00:00
|
|
|
{"index.html", "index.html"},
|
2013-09-01 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
2013-09-01 16:56:58 +00:00
|
|
|
for _, test := range tests {
|
2015-03-11 17:34:57 +00:00
|
|
|
f := &PagePub{UglyURLs: true}
|
2014-12-07 18:48:00 +00:00
|
|
|
dest, err := f.Translate(filepath.FromSlash(test.content))
|
2013-09-01 16:56:58 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Translate returned an unexpected err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if dest != test.expected {
|
|
|
|
t.Errorf("Translate expected return: %s, got: %s", test.expected, dest)
|
|
|
|
}
|
2013-09-01 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTranslateDefaultExtension(t *testing.T) {
|
2014-11-04 05:39:37 +00:00
|
|
|
f := &PagePub{DefaultExtension: ".foobar"}
|
2013-09-01 16:24:03 +00:00
|
|
|
dest, _ := f.Translate("baz")
|
2014-12-07 18:48:00 +00:00
|
|
|
if dest != filepath.FromSlash("baz/index.foobar") {
|
2013-09-01 16:24:03 +00:00
|
|
|
t.Errorf("Translate expected return: %s, got %s", "baz/index.foobar", dest)
|
|
|
|
}
|
|
|
|
}
|