@@ -3,6 +3,8 @@ package filepicker
import (
"fmt"
"io/fs"
+ "path/filepath"
+ "strings"
"testing"
"testing/fstest"
@@ -14,6 +16,10 @@ import (
var pngMagicNumberData = []byte("\x89PNG\x0D\x0A\x1A\x0A")
+func makePathCanonical(p string) string {
+ return strings.ReplaceAll(p, "/", string(filepath.Separator))
+}
+
func TestOnPasteMockFSWithValidPath(t *testing.T) {
var mockedFSPath string
resolveTestFS := func(fsysPath string) fs.FS {
@@ -29,10 +35,10 @@ func TestOnPasteMockFSWithValidPath(t *testing.T) {
}
// Test with the first file
- cmd := onPaste(resolveTestFS, "/home/testuser/images/image1.png")
+ cmd := onPaste(resolveTestFS, makePathCanonical("/home/testuser/images/image1.png"))
msg := cmd()
- assert.Equal(t, "/home/testuser/images", mockedFSPath)
+ assert.Equal(t, makePathCanonical("/home/testuser/images"), mockedFSPath)
filePickedMsg, ok := msg.(FilePickedMsg)
require.True(t, ok)
require.NotNil(t, filePickedMsg)
@@ -55,12 +61,12 @@ func TestOnPasteMockFSWithInvalidPath(t *testing.T) {
}
// Test with the first file
- cmd, ok := onPaste(resolveTestFS, "/home/testuser/images/nonexistent.png")().(tea.Cmd)
+ cmd, ok := onPaste(resolveTestFS, makePathCanonical("/home/testuser/images/nonexistent.png"))().(tea.Cmd)
require.True(t, ok)
msg := cmd()
- assert.Equal(t, "/home/testuser/images", mockedFSPath)
+ assert.Equal(t, makePathCanonical("/home/testuser/images"), mockedFSPath)
fmt.Printf("TYPE: %T\n", msg)
infoErrMsg, ok := msg.(util.InfoMsg)
require.True(t, ok)
@@ -68,6 +74,6 @@ func TestOnPasteMockFSWithInvalidPath(t *testing.T) {
assert.Equal(t, util.InfoMsg{
Type: util.InfoTypeError,
- Msg: "unable to read the image: error getting file info: open nonexistent.png: file does not exist, /home/testuser/images/nonexistent.png",
+ Msg: "unable to read the image: error getting file info: open nonexistent.png: file does not exist, " + makePathCanonical("/home/testuser/images/nonexistent.png"),
}, infoErrMsg)
}