2013-09-12 23:17:53 +00:00
|
|
|
package target
|
|
|
|
|
|
|
|
import (
|
2014-12-07 18:48:00 +00:00
|
|
|
"path/filepath"
|
2013-09-12 23:17:53 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHTMLRedirectAlias(t *testing.T) {
|
|
|
|
var o Translator
|
|
|
|
o = new(HTMLRedirectAlias)
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
value string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{"", ""},
|
2014-12-07 18:48:00 +00:00
|
|
|
{"s", filepath.FromSlash("s/index.html")},
|
|
|
|
{"/", filepath.FromSlash("/index.html")},
|
|
|
|
{"alias 1", filepath.FromSlash("alias-1/index.html")},
|
|
|
|
{"alias 2/", filepath.FromSlash("alias-2/index.html")},
|
2013-09-12 23:17:53 +00:00
|
|
|
{"alias 3.html", "alias-3.html"},
|
2013-09-13 21:46:34 +00:00
|
|
|
{"alias4.html", "alias4.html"},
|
2014-12-07 18:48:00 +00:00
|
|
|
{"/alias 5.html", filepath.FromSlash("/alias-5.html")},
|
|
|
|
{"/трям.html", filepath.FromSlash("/трям.html")},
|
2013-09-12 23:17:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
path, err := o.Translate(test.value)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Translate returned an error: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if path != test.expected {
|
|
|
|
t.Errorf("Expected: %s, got: %s", test.expected, path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|