github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/platform/path_test.go (about) 1 package platform 2 3 import ( 4 "runtime" 5 "strings" 6 "testing" 7 8 "github.com/bananabytelabs/wazero/internal/testing/require" 9 ) 10 11 func TestToPosixPath(t *testing.T) { 12 t.Parallel() 13 14 tests := []struct { 15 input string 16 expected string 17 }{ 18 {}, 19 {input: ".", expected: "."}, 20 {input: "/", expected: `/`}, 21 {input: `/`, expected: `/`}, 22 {input: "/foo/bar", expected: `/foo/bar`}, 23 {input: `\foo\bar`, expected: `/foo/bar`}, 24 {input: "foo/bar", expected: `foo/bar`}, 25 {input: `foo\bar`, expected: `foo/bar`}, 26 {input: "c:/foo/bar", expected: `c:/foo/bar`}, 27 {input: `c:\foo\bar`, expected: `c:/foo/bar`}, 28 } 29 30 for _, tt := range tests { 31 tc := tt 32 33 // We don't expect to translate backslashes unless we are on windows. 34 if strings.IndexByte(tc.input, '\\') != -1 && runtime.GOOS != "windows" { 35 continue 36 } 37 38 t.Run(tc.input, func(t *testing.T) { 39 require.Equal(t, tc.expected, ToPosixPath(tc.input)) 40 }) 41 } 42 }