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