newlines.test.ts 704 B

12345678910111213141516171819202122232425
  1. import { describe, expect, it } from 'vitest'
  2. import {
  3. getLineEndingForPlatform,
  4. normalizeLineEndings,
  5. restoreLineEndings,
  6. } from '../../src/common/newlines'
  7. describe('newlines', () => {
  8. it('normalizes CRLF and CR to LF', () => {
  9. expect(normalizeLineEndings('a\r\nb\rc')).toBe('a\nb\nc')
  10. })
  11. it('uses CRLF on Windows', () => {
  12. expect(getLineEndingForPlatform('win32')).toBe('\r\n')
  13. })
  14. it('uses LF on non-Windows platforms', () => {
  15. expect(getLineEndingForPlatform('darwin')).toBe('\n')
  16. expect(getLineEndingForPlatform('linux')).toBe('\n')
  17. })
  18. it('restores normalized text to CRLF', () => {
  19. expect(restoreLineEndings('a\nb\n', '\r\n')).toBe('a\r\nb\r\n')
  20. })
  21. })