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