|
| 1 | +import { getOptions } from '../recastOptions' |
| 2 | + |
| 3 | +describe('recastOptions', () => { |
| 4 | + describe('getOptions', () => { |
| 5 | + it('should return Unix line terminator for code with only LF', () => { |
| 6 | + const code = 'const a = 1\nconst b = 2\n' |
| 7 | + const result = getOptions(code) |
| 8 | + |
| 9 | + expect(result).toEqual({ lineTerminator: '\n' }) |
| 10 | + }) |
| 11 | + |
| 12 | + it('should return Windows line terminator for code with only CRLF', () => { |
| 13 | + const code = 'const a = 1\r\nconst b = 2\r\n' |
| 14 | + const result = getOptions(code) |
| 15 | + |
| 16 | + expect(result).toEqual({ lineTerminator: '\r\n' }) |
| 17 | + }) |
| 18 | + |
| 19 | + it('should return Unix line terminator for code with mixed line terminators', () => { |
| 20 | + const code = 'const a = 1\r\nconst b = 2\nconst c = 3\r\n' |
| 21 | + const result = getOptions(code) |
| 22 | + |
| 23 | + expect(result).toEqual({ lineTerminator: '\n' }) |
| 24 | + }) |
| 25 | + |
| 26 | + it('should return Unix line terminator for code with no line terminators', () => { |
| 27 | + const code = 'const a = 1' |
| 28 | + const result = getOptions(code) |
| 29 | + |
| 30 | + expect(result).toEqual({ lineTerminator: '\n' }) |
| 31 | + }) |
| 32 | + |
| 33 | + it('should return Unix line terminator for empty string', () => { |
| 34 | + const code = '' |
| 35 | + const result = getOptions(code) |
| 36 | + |
| 37 | + expect(result).toEqual({ lineTerminator: '\n' }) |
| 38 | + }) |
| 39 | + |
| 40 | + it('should handle code with LF at beginning after CR', () => { |
| 41 | + const code = '\r\nconst a = 1\nconst b = 2' |
| 42 | + const result = getOptions(code) |
| 43 | + |
| 44 | + expect(result).toEqual({ lineTerminator: '\n' }) |
| 45 | + }) |
| 46 | + |
| 47 | + it('should handle single CRLF without other line breaks', () => { |
| 48 | + const code = 'const a = 1\r\nconst b = 2' |
| 49 | + const result = getOptions(code) |
| 50 | + |
| 51 | + expect(result).toEqual({ lineTerminator: '\r\n' }) |
| 52 | + }) |
| 53 | + |
| 54 | + it('should handle multiple CRLF without LF', () => { |
| 55 | + const code = 'line1\r\nline2\r\nline3\r\n' |
| 56 | + const result = getOptions(code) |
| 57 | + |
| 58 | + expect(result).toEqual({ lineTerminator: '\r\n' }) |
| 59 | + }) |
| 60 | + |
| 61 | + it('should detect LF even when preceded by CR in different context', () => { |
| 62 | + const code = 'const str = "\\r"\nconst a = 1\r\n' |
| 63 | + const result = getOptions(code) |
| 64 | + |
| 65 | + expect(result).toEqual({ lineTerminator: '\n' }) |
| 66 | + }) |
| 67 | + }) |
| 68 | +}) |
0 commit comments