@@ -2,10 +2,10 @@ package prompt
8+ "github.com/charmbracelet/crush/internal/home"
11func TestExpandPath(t *testing.T) {
11func TestExpandPath(t *testing.T) {
@@ -25,16 +25,14 @@ func TestExpandPath(t *testing.T) {
25 name: "tilde expansion",
25 name: "tilde expansion",
26 input: "~/documents",
26 input: "~/documents",
27 expected: func() string {
27 expected: func() string {
28− home, _ := os.UserHomeDir()
29− return filepath.Join(home, "documents")
28+ return home.Dir() + "/documents"
33 name: "tilde only",
32 name: "tilde only",
34 input: "~",
33 input: "~",
35 expected: func() string {
34 expected: func() string {
36− home, _ := os.UserHomeDir()
35+ return home.Dir()
@@ -69,55 +67,3 @@ func TestExpandPath(t *testing.T) {
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"
79− err := os.WriteFile(testFile, []byte(testContent), 0o644)
81− t.Fatalf("Failed to create test file: %v", err)
84− // Test with absolute path to file
85− result := processContextPaths("", []string{testFile})
86− expected := "# From:" + testFile + "\n" + testContent
88− if result != expected {
89− t.Errorf("processContextPaths with absolute path failed.\nGot: %q\nWant: %q", result, expected)
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")
98− // Test with tilde expansion (if we can create a file in home directory)
100− setHomeEnv(t, tmpDir)
101− homeTestFile := filepath.Join(tmpDir, "crush_test_file.txt")
102− err = os.WriteFile(homeTestFile, []byte(testContent), 0o644)
104− defer os.Remove(homeTestFile) // Clean up
106− tildeFile := "~/crush_test_file.txt"
107− result = processContextPaths("", []string{tildeFile})
108− expected = "# From:" + homeTestFile + "\n" + testContent
110− if result != expected {
111− t.Errorf("processContextPaths with tilde expansion failed.\nGot: %q\nWant: %q", result, expected)
116−func setHomeEnv(tb testing.TB, path string) {
119− if runtime.GOOS == "windows" {
122− tb.Setenv(key, path)