-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathimages_test.go
More file actions
111 lines (99 loc) · 2.78 KB
/
Copy pathimages_test.go
File metadata and controls
111 lines (99 loc) · 2.78 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package commands
import (
"os"
"reflect"
"testing"
)
func TestExtractFileInclusions(t *testing.T) {
tests := []struct {
name string
prompt string
expected []string
}{
{
name: "simple file",
prompt: "Please analyze this @file.txt",
expected: []string{"file.txt"},
},
{
name: "quoted file",
prompt: "Look at this @\"my file.txt\"",
expected: []string{"my file.txt"},
},
{
name: "single quoted file",
prompt: "Look at this @'another file.py'",
expected: []string{"another file.py"},
},
{
name: "multiple files",
prompt: "Check @file1.txt and @file2.go",
expected: []string{"file1.txt", "file2.go"},
},
{
name: "relative path",
prompt: "Review @./src/main.go",
expected: []string{"./src/main.go"},
},
{
name: "absolute path",
prompt: "See @/home/user/file.txt",
expected: []string{"/home/user/file.txt"},
},
{
name: "mixed quotes and paths",
prompt: "Look at @README.md and @\"./src/config.json\"",
expected: []string{"README.md", "./src/config.json"},
},
{
name: "no file inclusions",
prompt: "Just a regular prompt",
expected: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := ExtractFileInclusions(tt.prompt)
if !reflect.DeepEqual(result, tt.expected) {
t.Errorf("ExtractFileInclusions() = %v, want %v", result, tt.expected)
}
})
}
}
func TestProcessFileInclusions(t *testing.T) {
// Create a temporary file for testing in the system's temp directory
tempDir := t.TempDir()
tempFile := tempDir + "/test_process_file_inclusions_temp_file.txt"
tempContent := "This is test file content"
// Write test content to a temporary file in the temp directory
err := os.WriteFile(tempFile, []byte(tempContent), 0644)
if err != nil {
t.Fatalf("Failed to create test file: %v", err)
}
// Ensure cleanup happens even if test fails
defer func() {
os.Remove(tempFile)
}()
// Test with the temporary file
prompt := "Analyze this @" + tempFile + " file"
expected := "Analyze this " + tempContent + " file"
result, err := ProcessFileInclusions(prompt)
if err != nil {
t.Errorf("ProcessFileInclusions() error = %v", err)
return
}
if result != expected {
t.Errorf("ProcessFileInclusions() = %v, want %v", result, expected)
}
// Test with a file that doesn't exist (should be skipped)
prompt2 := "Analyze this @nonexistent.txt file"
expected2 := "Analyze this @nonexistent.txt file" // Should remain unchanged since file doesn't exist
result2, err := ProcessFileInclusions(prompt2)
if err != nil {
t.Errorf("ProcessFileInclusions() error = %v", err)
return
}
if result2 != expected2 {
t.Errorf("ProcessFileInclusions() with non-existent file = %v, want %v", result2, expected2)
}
}