mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
9f77f93071
File handling was broken on Windows. This commit contains a revision of the path handling with separation of file paths and urls where needed. There may be remaining issues and there may be better ways to do this, but it is easier to start that refactoring job with a set of passing tests. Fixes #687 Fixes #660
37 lines
855 B
Go
37 lines
855 B
Go
package target
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestHTMLRedirectAlias(t *testing.T) {
|
|
var o Translator
|
|
o = new(HTMLRedirectAlias)
|
|
|
|
tests := []struct {
|
|
value string
|
|
expected string
|
|
}{
|
|
{"", ""},
|
|
{"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")},
|
|
{"alias 3.html", "alias-3.html"},
|
|
{"alias4.html", "alias4.html"},
|
|
{"/alias 5.html", filepath.FromSlash("/alias-5.html")},
|
|
{"/трям.html", filepath.FromSlash("/трям.html")},
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|