aboutsummaryrefslogtreecommitdiff
path: root/internal/editor
diff options
context:
space:
mode:
Diffstat (limited to 'internal/editor')
-rw-r--r--internal/editor/editor_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/editor/editor_test.go b/internal/editor/editor_test.go
new file mode 100644
index 0000000..86bc095
--- /dev/null
+++ b/internal/editor/editor_test.go
@@ -0,0 +1,47 @@
+package editor
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestOpenWithEditor_PlainCommand(t *testing.T) {
+ err := OpenWithEditor("/dev/null", "true")
+ require.NoError(t, err)
+}
+
+func TestOpenWithEditor_PercentS(t *testing.T) {
+ dir := t.TempDir()
+ path := filepath.Join(dir, "testfile")
+ require.NoError(t, os.WriteFile(path, []byte("content"), 0600))
+
+ err := OpenWithEditor(path, "true %s")
+ require.NoError(t, err)
+}
+
+func TestOpenWithEditor_QuotedPercentS(t *testing.T) {
+ dir := t.TempDir()
+ path := filepath.Join(dir, "testfile")
+ require.NoError(t, os.WriteFile(path, []byte("content"), 0600))
+
+ err := OpenWithEditor(path, "true '%s'")
+ require.NoError(t, err)
+}
+
+func TestOpenWithEditor_PathWithSpaces(t *testing.T) {
+ dir := t.TempDir()
+ path := filepath.Join(dir, "file with spaces")
+ require.NoError(t, os.WriteFile(path, []byte("content"), 0600))
+
+ err := OpenWithEditor(path, "true %s")
+ require.NoError(t, err)
+}
+
+func TestOpenWithEditor_InvalidCommand(t *testing.T) {
+ err := OpenWithEditor("/tmp/fake", "/nonexistent/cmd")
+ assert.Error(t, err)
+}