diff options
| author | ishaan <contact@ishaan.cc> | 2026-07-16 13:11:08 +0530 |
|---|---|---|
| committer | ishaan <contact@ishaan.cc> | 2026-07-16 13:11:08 +0530 |
| commit | cc11788404e68fcf7f5356bcc275f331c13fc36e (patch) | |
| tree | 04be33465f497956aaf08e0ef440eb453d6d26dd /internal/editor | |
| parent | 006e7975455153e32893cb38196d59d20945590e (diff) | |
testify tests for utils, editor, and crud
Diffstat (limited to 'internal/editor')
| -rw-r--r-- | internal/editor/editor_test.go | 47 |
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) +} |