54 lines
982 B
Go
54 lines
982 B
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizePath(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
path string
|
|
want string
|
|
}{
|
|
{
|
|
name: "Test case 1",
|
|
path: "/path/to/file",
|
|
want: "/path/to/file",
|
|
},
|
|
{
|
|
name: "Test case 2",
|
|
path: "path/to/file",
|
|
want: GetExecDir() + "/path/to/file",
|
|
},
|
|
{
|
|
name: "Test case 3",
|
|
path: "../path/to/file",
|
|
want: filepath.Join(GetExecDir(), "../path/to/file"),
|
|
},
|
|
{
|
|
name: "Test case 4",
|
|
path: "./path/to/file",
|
|
want: GetExecDir() + "/path/to/file",
|
|
},
|
|
{
|
|
name: "Test case 5",
|
|
path: "/absolute/path/to/file",
|
|
want: "/absolute/path/to/file",
|
|
},
|
|
{
|
|
name: "Test case 6",
|
|
path: "relative/path/to/file",
|
|
want: GetExecDir() + "/relative/path/to/file",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := NormalizePath(tt.path); got != tt.want {
|
|
t.Errorf("NormalizePath() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|