| 1 | import { |
| 2 | processTestCase, |
| 3 | type CompletionTestCase, |
| 4 | } from "./completionTestUtils"; |
| 5 | |
| 6 | describe("processTestCase utility", () => { |
| 7 | it("processes simple console.log completion", () => { |
| 8 | const testCase: CompletionTestCase = { |
| 9 | original: "console.log(|cur||till|)", |
| 10 | completion: "\"foo,\", bar", |
| 11 | }; |
| 12 | |
| 13 | expect(processTestCase(testCase)).toEqual({ |
| 14 | input: { |
| 15 | lastLineOfCompletionText: "\"foo,\", bar", |
| 16 | currentText: ")", |
| 17 | cursorPosition: "console.log(".length, |
| 18 | }, |
| 19 | expectedResult: { |
| 20 | completionText: "\"foo,\", bar", |
| 21 | }, |
| 22 | }); |
| 23 | }); |
| 24 | |
| 25 | it("processes simple console.log completion with overwriting", () => { |
| 26 | const testCase: CompletionTestCase = { |
| 27 | original: "console.log(|cur|)|till|", |
| 28 | completion: "\"foo,\", bar);", |
| 29 | }; |
| 30 | |
| 31 | expect(processTestCase(testCase)).toEqual({ |
| 32 | input: { |
| 33 | lastLineOfCompletionText: "\"foo,\", bar);", |
| 34 | currentText: ")", |
| 35 | cursorPosition: "console.log(".length, |
| 36 | }, |
| 37 | expectedResult: { |
| 38 | completionText: "\"foo,\", bar);", |
| 39 | range: { |
| 40 | start: "console.log(".length, |
| 41 | end: "console.log()".length, |
| 42 | }, |
| 43 | }, |
| 44 | }); |
| 45 | }); |
| 46 | |
| 47 | it("partially applying completion", () => { |
| 48 | const testCase: CompletionTestCase = { |
| 49 | original: "|cur||till|fetch(\"https://example.com\");", |
| 50 | completion: "await fetch(\"https://example.com\");", |
| 51 | appliedCompletion: "await ", |
| 52 | }; |
| 53 | |
| 54 | expect(processTestCase(testCase)).toEqual({ |
| 55 | input: { |
| 56 | lastLineOfCompletionText: "await fetch(\"https://example.com\");", |
| 57 | currentText: "fetch(\"https://example.com\");", |
| 58 | cursorPosition: 0, |
| 59 | }, |
| 60 | expectedResult: { |
| 61 | completionText: "await ", |
| 62 | }, |
| 63 | }); |
| 64 | }); |
| 65 | }); |