@@ -2,10 +2,10 @@ package prompt
22
33import (
44 "os"
5− "path/filepath"
6− "runtime"
75 "strings"
86 "testing"
7+
8+ "github.com/charmbracelet/crush/internal/home"
99)
1010
1111func TestExpandPath(t *testing.T) {
@@ -25,16 +25,14 @@ func TestExpandPath(t *testing.T) {
2525 name: "tilde expansion",
2626 input: "~/documents",
2727 expected: func() string {
28− home, _ := os.UserHomeDir()
29− return filepath.Join(home, "documents")
28+ return home.Dir() + "/documents"
3029 },
3130 },
3231 {
3332 name: "tilde only",
3433 input: "~",
3534 expected: func() string {
36− home, _ := os.UserHomeDir()
37− return home
35+ return home.Dir()
3836 },
3937 },
4038 {
@@ -69,55 +67,3 @@ func TestExpandPath(t *testing.T) {
6967 })
7068 }
7169}
72−
73−func TestProcessContextPaths(t *testing.T) {
74− // Create a temporary directory and file for testing
75− tmpDir := t.TempDir()
76− testFile := filepath.Join(tmpDir, "test.txt")
77− testContent := "test content"
78−
79− err := os.WriteFile(testFile, []byte(testContent), 0o644)
80− if err != nil {
81− t.Fatalf("Failed to create test file: %v", err)
82− }
83−
84− // Test with absolute path to file
85− result := processContextPaths("", []string{testFile})
86− expected := "# From:" + testFile + "\n" + testContent
87−
88− if result != expected {
89− t.Errorf("processContextPaths with absolute path failed.\nGot: %q\nWant: %q", result, expected)
90− }
91−
92− // Test with directory path (should process all files in directory)
93− result = processContextPaths("", []string{tmpDir})
94− if !strings.Contains(result, testContent) {
95− t.Errorf("processContextPaths with directory path failed to include file content")
96− }
97−
98− // Test with tilde expansion (if we can create a file in home directory)
99− tmpDir = t.TempDir()
100− setHomeEnv(t, tmpDir)
101− homeTestFile := filepath.Join(tmpDir, "crush_test_file.txt")
102− err = os.WriteFile(homeTestFile, []byte(testContent), 0o644)
103− if err == nil {
104− defer os.Remove(homeTestFile) // Clean up
105−
106− tildeFile := "~/crush_test_file.txt"
107− result = processContextPaths("", []string{tildeFile})
108− expected = "# From:" + homeTestFile + "\n" + testContent
109−
110− if result != expected {
111− t.Errorf("processContextPaths with tilde expansion failed.\nGot: %q\nWant: %q", result, expected)
112− }
113− }
114−}
115−
116−func setHomeEnv(tb testing.TB, path string) {
117− tb.Helper()
118− key := "HOME"
119− if runtime.GOOS == "windows" {
120− key = "USERPROFILE"
121− }
122− tb.Setenv(key, path)
123−}