summaryrefslogtreecommitdiff
path: root/internal/tui/eventstream/export_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/tui/eventstream/export_test.go')
-rw-r--r--internal/tui/eventstream/export_test.go60
1 files changed, 53 insertions, 7 deletions
diff --git a/internal/tui/eventstream/export_test.go b/internal/tui/eventstream/export_test.go
index e60e932..9bdb2d2 100644
--- a/internal/tui/eventstream/export_test.go
+++ b/internal/tui/eventstream/export_test.go
@@ -1,8 +1,12 @@
package eventstream
-import "testing"
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
-func TestResolveEditorCommandPrefersSudoEditor(t *testing.T) {
+func TestResolveEditorCommandPrefersEditor(t *testing.T) {
t.Setenv("SUDO_EDITOR", "nano")
t.Setenv("VISUAL", "vim")
t.Setenv("EDITOR", "nvim")
@@ -11,18 +15,60 @@ func TestResolveEditorCommandPrefersSudoEditor(t *testing.T) {
if err != nil {
t.Fatalf("resolve editor: %v", err)
}
- if source != "SUDO_EDITOR" {
- t.Fatalf("expected SUDO_EDITOR source, got %q", source)
+ if source != "EDITOR" {
+ t.Fatalf("expected EDITOR source, got %q", source)
}
- if len(parts) != 1 || parts[0] != "nano" {
- t.Fatalf("expected nano command, got %#v", parts)
+ if len(parts) != 1 || parts[0] != "nvim" {
+ t.Fatalf("expected nvim command, got %#v", parts)
}
}
-func TestResolveEditorCommandFallsBackToVi(t *testing.T) {
+func TestResolveEditorCommandFallsBackToVisualBeforeSudoEditor(t *testing.T) {
+ t.Setenv("SUDO_EDITOR", "nano")
+ t.Setenv("VISUAL", "vim")
+ t.Setenv("EDITOR", "")
+
+ parts, source, err := resolveEditorCommand()
+ if err != nil {
+ t.Fatalf("resolve editor: %v", err)
+ }
+ if source != "VISUAL" {
+ t.Fatalf("expected VISUAL source, got %q", source)
+ }
+ if len(parts) != 1 || parts[0] != "vim" {
+ t.Fatalf("expected vim command, got %#v", parts)
+ }
+}
+
+func TestResolveEditorCommandFallsBackToHxWhenAvailable(t *testing.T) {
+ t.Setenv("SUDO_EDITOR", "")
+ t.Setenv("VISUAL", "")
+ t.Setenv("EDITOR", "")
+
+ binDir := t.TempDir()
+ hxPath := filepath.Join(binDir, "hx")
+ if err := os.WriteFile(hxPath, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {
+ t.Fatalf("write hx stub: %v", err)
+ }
+ t.Setenv("PATH", binDir)
+
+ parts, source, err := resolveEditorCommand()
+ if err != nil {
+ t.Fatalf("resolve editor: %v", err)
+ }
+ if source != "fallback" {
+ t.Fatalf("expected fallback source, got %q", source)
+ }
+ if len(parts) != 1 || parts[0] != "hx" {
+ t.Fatalf("expected hx fallback, got %#v", parts)
+ }
+}
+
+func TestResolveEditorCommandFallsBackToViWhenHxMissing(t *testing.T) {
t.Setenv("SUDO_EDITOR", "")
t.Setenv("VISUAL", "")
t.Setenv("EDITOR", "")
+ t.Setenv("PATH", t.TempDir())
parts, source, err := resolveEditorCommand()
if err != nil {