find-name-start.test.js 612 B

12345678910111213141516171819202122232425262728
  1. 'use strict'
  2. const tap = require('tap')
  3. const findNameStart = require('./find-name-start')
  4. tap.test('returns correct position', async t => {
  5. const input = Buffer.from(' foo')
  6. t.equal(
  7. findNameStart({ searchBuffer: input, startPos: 0 }),
  8. 3
  9. )
  10. })
  11. tap.test('skips leading comma', async t => {
  12. const input = Buffer.from(' , foo=bar')
  13. t.equal(
  14. findNameStart({ searchBuffer: input, startPos: 0 }),
  15. 3
  16. )
  17. })
  18. tap.test('returns -1 for invalid lead char', async t => {
  19. const input = Buffer.from(' øfoo')
  20. t.equal(
  21. findNameStart({ searchBuffer: input, startPos: 0 }),
  22. -1
  23. )
  24. })