1package modes
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7)
8
9func TestBuildStudyPrompt(t *testing.T) {
10 tmp := t.TempDir()
11 subdir := filepath.Join(tmp, "internal")
12 if err := os.Mkdir(subdir, 0o755); err != nil {
13 t.Fatal(err)
14 }
15 file := filepath.Join(tmp, "main.go")
16 if err := os.WriteFile(file, []byte("package main\n"), 0o644); err != nil {
17 t.Fatal(err)
18 }
19
20 cases := []struct {
21 name string
22 arg string
23 cwd string
24 want string
25 }{
26 {
27 name: "empty arg keeps the original cwd prompt",
28 arg: "",
29 cwd: tmp,
30 want: "Read and understand everything in the current directory.",
31 },
32 {
33 name: "relative dir becomes a directory prompt",
34 arg: "internal",
35 cwd: tmp,
36 want: "Read and understand everything in the directory internal.",
37 },
38 {
39 name: "absolute dir under cwd is shown as a relative path",
40 arg: subdir,
41 cwd: tmp,
42 want: "Read and understand everything in the directory internal.",
43 },
44 {
45 name: "relative file becomes a file prompt",
46 arg: "main.go",
47 cwd: tmp,
48 want: "Read and understand the file main.go.",
49 },
50 {
51 name: "absolute file under cwd is shown as a relative path",
52 arg: file,
53 cwd: tmp,
54 want: "Read and understand the file main.go.",
55 },
56 {
57 name: "missing path falls back to the directory phrasing",
58 arg: "does-not-exist",
59 cwd: tmp,
60 want: "Read and understand everything in the directory does-not-exist.",
61 },
62 {
63 name: "absolute path outside cwd keeps its absolute form",
64 arg: subdir,
65 cwd: filepath.Join(tmp, "elsewhere"),
66 want: "Read and understand everything in the directory " + subdir + ".",
67 },
68 {
69 name: "leading and trailing whitespace are stripped",
70 arg: " main.go ",
71 cwd: tmp,
72 want: "Read and understand the file main.go.",
73 },
74 }
75
76 for _, tc := range cases {
77 t.Run(tc.name, func(t *testing.T) {
78 got := buildStudyPrompt(tc.arg, tc.cwd)
79 if got != tc.want {
80 t.Fatalf("buildStudyPrompt(%q, %q)\n got: %q\n want: %q", tc.arg, tc.cwd, got, tc.want)
81 }
82 })
83 }
84}