Skip to content

Commit 3ec858c

Browse files
committed
test: TestPrepareDiffs
1 parent 3bae6b3 commit 3ec858c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

llm/api_client_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package llm
22

33
import (
44
"context"
5+
"encoding/base64"
56
"encoding/json"
67
"io"
78
"net/http"
@@ -206,6 +207,52 @@ func TestEndpoint(t *testing.T) {
206207
}
207208
}
208209

210+
func TestPrepareDiffs(t *testing.T) {
211+
testCases := []struct {
212+
name string
213+
input []string
214+
expected []string
215+
}{
216+
{
217+
name: "Single diff with headers and content",
218+
input: []string{
219+
"--- a/file.txt\n" +
220+
"+++ b/file.txt\n" +
221+
"@@ -1,1 +1,1 @@\n" +
222+
"-old line\n" +
223+
"+new line\n",
224+
},
225+
expected: []string{
226+
base64.StdEncoding.EncodeToString([]byte("@@ -1,1 +1,1 @@\n-old line\n+new line\n\n")),
227+
},
228+
},
229+
{
230+
name: "Multiple diffs",
231+
input: []string{
232+
"--- a/file1.txt\n" +
233+
"+++ b/file1.txt\n" +
234+
"-line 1\n" +
235+
"+line 2\n",
236+
"--- a/file2.txt\n" +
237+
"+++ b/file2.txt\n" +
238+
"content2a\n" +
239+
"+content2b\n",
240+
},
241+
expected: []string{
242+
base64.StdEncoding.EncodeToString([]byte("-line 1\n+line 2\n\n")),
243+
base64.StdEncoding.EncodeToString([]byte("content2a\n+content2b\n\n")),
244+
},
245+
},
246+
}
247+
248+
for _, tc := range testCases {
249+
t.Run(tc.name, func(t *testing.T) {
250+
actual := prepareDiffs(tc.input)
251+
assert.Equal(t, tc.expected, actual)
252+
})
253+
}
254+
}
255+
209256
// Helper function for testing
210257
func testLogger(t *testing.T) *zerolog.Logger {
211258
t.Helper()

0 commit comments

Comments
 (0)