import test from 'tape'
import {trimLines} from './index.js'

test('trimLines(value)', function (t) {
  // @ts-expect-error coerce.
  t.equal(trimLines(true), 'true', 'should coerce to string')
  t.equal(
    trimLines(' foo\t\n\n bar \n\tbaz '),
    ' foo\n\nbar\nbaz ',
    'should work'
  )
  t.end()
})

test('efficiency', (t) => {
  const aTonOfWhitespace = 'a' + ' '.repeat(70_000) + 'b'
  const timeoutId = setTimeout(() => {
    t.fail('should process lots of whitespace efficiently')
  }, 10)

  t.deepEqual(
    trimLines(aTonOfWhitespace),
    aTonOfWhitespace,
    'should be efficient on excessive whitespace'
  )

  setTimeout(() => {
    clearTimeout(timeoutId)
    t.end()
  }, 0)
})

import test from 'tape'
import {trimLines} from './index.js'

test('trimLines(value)', function (t) {
  // @ts-expect-error coerce.
  t.equal(trimLines(true), 'true', 'should coerce to string')
  t.equal(
    trimLines(' foo\t\n\n bar \n\tbaz '),
    ' foo\n\nbar\nbaz ',
    'should work'
  )
  t.end()
})

test('efficiency', (t) => {
  const whitespace = ' '.repeat(70_000)

  t.test('whitespace in line', (t) => {
    const timeoutId = setTimeout(() => {
      t.fail('did not pass in 10ms')
    }, 10)

    t.deepEqual(trimLines('a' + whitespace + 'b'), 'a' + whitespace + 'b')

    setTimeout(() => {
      clearTimeout(timeoutId)
      t.end()
    }, 0)
  })

  t.test('whitespace around line', (t) => {
    const timeoutId = setTimeout(() => {
      t.fail('did not pass in 10ms')
    }, 10)

    t.deepEqual(
      trimLines(
        'a' +
          whitespace +
          '\n' +
          whitespace +
          'b' +
          whitespace +
          '\n' +
          whitespace +
          'c'
      ),
      'a\nb\nc'
    )

    setTimeout(() => {
      clearTimeout(timeoutId)
      t.end()
    }, 0)
  })
})

Add test for lots of whitespace around line endings