Elffuss BraidHub

kikocis/continue public

4940c71be2bf · 3.4 KiBRawPermalink
1import { describe, expect, it } from "vitest";
2import { Position } from "../..";
3import { CODE_TO_EDIT_CLOSE, CODE_TO_EDIT_OPEN, CURSOR } from "../constants";
4import {
5 currentFileContentBlock,
6 editHistoryBlock,
7 recentlyViewedCodeSnippetsBlock,
8} from "./mercuryCoderNextEdit";
9
10describe("mercuryCoderNextEdit", () => {
11 describe("recentlyViewedCodeSnippetsBlock", () => {
12 it("should format a list of code snippets correctly", () => {
13 const snippets = [
14 { filepath: "/path/to/file1.ts", content: "const a = 1;" },
15 {
16 filepath: "/path/to/file2.ts",
17 content: "function test() { return true; }",
18 },
19 ];
20
21 const result = recentlyViewedCodeSnippetsBlock(snippets);
22
23 const expected =
24 "code_snippet_file_path: /path/to/file1.ts\n" +
25 "const a = 1;\n" +
26 "code_snippet_file_path: /path/to/file2.ts\n" +
27 "function test() { return true; }";
28
29 expect(result).toBe(expected);
30 });
31
32 it("should handle empty snippets array", () => {
33 const result = recentlyViewedCodeSnippetsBlock([]);
34 expect(result).toBe("");
35 });
36 });
37
38 describe("currentFileContentBlock", () => {
39 it("should correctly format current file content with editable region and cursor", () => {
40 const fileContent = "line 1\nline 2\nline 3\nline 4\nline 5";
41 const editableRegionStartLine = 1;
42 const editableRegionEndLine = 3;
43 const cursorPosition: Position = { line: 2, character: 3 };
44
45 const result = currentFileContentBlock(
46 fileContent,
47 editableRegionStartLine,
48 editableRegionEndLine,
49 cursorPosition,
50 );
51
52 const expected =
53 "line 1\n" +
54 CODE_TO_EDIT_OPEN +
55 "\n" +
56 "line 2\n" +
57 "lin" +
58 CURSOR +
59 "e 3\n" +
60 "line 4\n" +
61 CODE_TO_EDIT_CLOSE +
62 "\n" +
63 "line 5";
64
65 expect(result).toBe(expected);
66 });
67
68 it("should handle cursor at the beginning of a line", () => {
69 const fileContent = "line 1\nline 2\nline 3";
70 const editableRegionStartLine = 0;
71 const editableRegionEndLine = 2;
72 const cursorPosition: Position = { line: 1, character: 0 };
73
74 const result = currentFileContentBlock(
75 fileContent,
76 editableRegionStartLine,
77 editableRegionEndLine,
78 cursorPosition,
79 );
80
81 expect(result).toContain(CODE_TO_EDIT_OPEN);
82 expect(result).toContain(CURSOR + "line 2");
83 expect(result).toContain(CODE_TO_EDIT_CLOSE);
84 });
85
86 it("should handle cursor at the end of a line", () => {
87 const fileContent = "line 1\nline 2\nline 3";
88 const editableRegionStartLine = 0;
89 const editableRegionEndLine = 2;
90 const cursorPosition: Position = { line: 1, character: 6 };
91
92 const result = currentFileContentBlock(
93 fileContent,
94 editableRegionStartLine,
95 editableRegionEndLine,
96 cursorPosition,
97 );
98
99 expect(result).toContain("line 2" + CURSOR);
100 });
101 });
102
103 describe("editHistoryBlock", () => {
104 it("should return the edit diff history unchanged", () => {
105 const diffHistory = "diff --git a/file.ts b/file.ts\n@@ -1,3 +1,4 @@";
106 const result = editHistoryBlock(diffHistory);
107 expect(result).toBe(diffHistory);
108 });
109
110 it("should handle empty diff history", () => {
111 const result = editHistoryBlock("");
112 expect(result).toBe("");
113 });
114 });
115});