| 1 | import { describe, expect, it } from 'vitest'; |
| 2 | |
| 3 | import { applySuggestion, extractSuggestion |
| 4 | |
| 5 | describe('extractSuggestion', () |
| 6 | it('reads the first suggestion block and nothing else', |
| 7 | expect( |
| 8 | extractSuggestion( |
| 9 | 'Try:\n```suggestion\nconst a = 1;\nconst b = 2;\n |
| 10 | ), |
| 11 | ).toBe('const a = 1;\n |
| 12 | expect(extractSuggestion('```suggestion |
| 13 | expect(extractSuggestion('```suggestion |
| 14 | }); |
| 15 | |
| 16 | it('reads an empty block as a deletion, and no block as no suggestion', |
| 17 | expect(extractSuggestion('```suggestion |
| 18 | expect(extractSuggestion('```ts |
| 19 | expect(extractSuggestion('no code here |
| 20 | }); |
| 21 | }); |
| 22 | |
| 23 | describe('applySuggestion', () |
| 24 | it('replaces a range and keeps the final newline', |
| 25 | expect(applySuggestion('a |
| 26 | expect(applySuggestion('a |
| 27 | }); |
| 28 | |
| 29 | it('deletes lines for an empty suggestion', |
| 30 | expect(applySuggestion('a |
| 31 | }); |
| 32 | |
| 33 | it('keeps CRLF files CRLF', |
| 34 | expect(applySuggestion('a |
| 35 | }); |
| 36 | }); |