aboutsummaryrefslogtreecommitdiff
path: root/internal/editor/editor_test.go
blob: 86bc0953669c98f5a1d46cc64c3abf0a27adf023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)
}