mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Split Windows and Unix specific path tests
This commit is contained in:
parent
b155e8b4cb
commit
8ad4fd05d8
3 changed files with 54 additions and 1 deletions
|
@ -395,7 +395,6 @@ func TestAbsPathify(t *testing.T) {
|
|||
}
|
||||
data := []test{
|
||||
{os.TempDir(), filepath.FromSlash("/work"), filepath.Clean(os.TempDir())}, // TempDir has trailing slash
|
||||
// todo bep breaks on Windows: {filepath.FromSlash("/banana/../dir/"), filepath.FromSlash("/work"), filepath.FromSlash("/dir")},
|
||||
{"dir", filepath.FromSlash("/work"), filepath.FromSlash("/work/dir")},
|
||||
}
|
||||
|
||||
|
|
27
helpers/path_unix_test.go
Normal file
27
helpers/path_unix_test.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
// +build !windows
|
||||
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPlatformAbsPathify(t *testing.T) {
|
||||
type test struct {
|
||||
inPath, workingDir, expected string
|
||||
}
|
||||
data := []test{
|
||||
{"/banana/../dir/", "/work", "/dir"},
|
||||
}
|
||||
|
||||
for i, d := range data {
|
||||
// todo see comment in AbsPathify
|
||||
viper.Set("WorkingDir", d.workingDir)
|
||||
|
||||
expected := AbsPathify(d.inPath)
|
||||
if d.expected != expected {
|
||||
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected)
|
||||
}
|
||||
}
|
||||
}
|
27
helpers/path_windows_test.go
Normal file
27
helpers/path_windows_test.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPlatformAbsPathify(t *testing.T) {
|
||||
type test struct {
|
||||
inPath, workingDir, expected string
|
||||
}
|
||||
data := []test{
|
||||
{"c:\\banana\\..\\dir", "c:\\foo", "c:\\dir"},
|
||||
{"\\dir", "c:\\foo", "c:\\foo\\dir"},
|
||||
{"c:\\", "c:\\foo", "c:\\"},
|
||||
}
|
||||
|
||||
for i, d := range data {
|
||||
// todo see comment in AbsPathify
|
||||
viper.Set("WorkingDir", d.workingDir)
|
||||
|
||||
expected := AbsPathify(d.inPath)
|
||||
if d.expected != expected {
|
||||
t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue