Elffuss BraidHub

kikocis/continue public

c53d47aeb2c4 · 2.8 KiBRawPermalink
1import { processTestCase } from "./completionTestUtils";
2import { processSingleLineCompletion } from "./processSingleLineCompletion";
3
4describe("processSingleLineCompletion", () => {
5 it("should handle simple end of line completion", () => {
6 const testCase = processTestCase({
7 original: "console.log(|cur|",
8 completion: '"Hello, world!")',
9 });
10
11 const result = processSingleLineCompletion(
12 testCase.input.lastLineOfCompletionText,
13 testCase.input.currentText,
14 testCase.input.cursorPosition,
15 );
16
17 expect(result).toEqual(testCase.expectedResult);
18 });
19
20 it("should handle midline insert repeating the end of line", () => {
21 const testCase = processTestCase({
22 original: "console.log(|cur|);|till|",
23 completion: '"Hello, world!");',
24 });
25
26 const result = processSingleLineCompletion(
27 testCase.input.lastLineOfCompletionText,
28 testCase.input.currentText,
29 testCase.input.cursorPosition,
30 );
31
32 expect(result).toEqual(testCase.expectedResult);
33 });
34
35 it("should handle midline insert repeating the end of line plus adding a semicolon", () => {
36 const testCase = processTestCase({
37 original: "console.log(|cur|)|till|",
38 completion: '"Hello, world!");',
39 });
40
41 const result = processSingleLineCompletion(
42 testCase.input.lastLineOfCompletionText,
43 testCase.input.currentText,
44 testCase.input.cursorPosition,
45 );
46
47 expect(result).toEqual(testCase.expectedResult);
48 });
49
50 it("should handle simple midline insert", () => {
51 const testCase = processTestCase({
52 original: "console.log(|cur|)",
53 completion: '"Hello, world!"',
54 });
55
56 const result = processSingleLineCompletion(
57 testCase.input.lastLineOfCompletionText,
58 testCase.input.currentText,
59 testCase.input.cursorPosition,
60 );
61
62 expect(result).toEqual(testCase.expectedResult);
63 });
64
65 it("should handle complex dif with addition in the beginning", () => {
66 const testCase = processTestCase({
67 original: 'console.log(|cur||till|, "param1", )', // TODO
68 completion: '"Hello world!", "param1", param1);',
69 appliedCompletion: '"Hello world!"',
70 });
71
72 const result = processSingleLineCompletion(
73 testCase.input.lastLineOfCompletionText,
74 testCase.input.currentText,
75 testCase.input.cursorPosition,
76 );
77
78 expect(result).toEqual(testCase.expectedResult);
79 });
80
81 it("should handle simple insertion even with random equality", () => {
82 const testCase = processTestCase({
83 original: 'print(f"Foobar length: |cur||till|")',
84 completion: "{len(foobar)}",
85 });
86
87 const result = processSingleLineCompletion(
88 testCase.input.lastLineOfCompletionText,
89 testCase.input.currentText,
90 testCase.input.cursorPosition,
91 );
92
93 expect(result).toEqual(testCase.expectedResult);
94 });
95});