find-name-end.test.js 796 B

12345678910111213141516171819202122232425262728
  1. 'use strict'
  2. const tap = require('tap')
  3. const findNameEnd = require('./find-name-end')
  4. tap.test('stops on a space', async t => {
  5. const input = Buffer.from('foo = bar')
  6. const pos = findNameEnd({ searchBuffer: input, startPos: 0 })
  7. t.equal(pos, 3)
  8. })
  9. tap.test('stops on an equals', async t => {
  10. const input = Buffer.from('foo=bar')
  11. const pos = findNameEnd({ searchBuffer: input, startPos: 0 })
  12. t.equal(pos, 3)
  13. })
  14. tap.test('returns -1 for bad character', async t => {
  15. const input = Buffer.from('føø=bar')
  16. const pos = findNameEnd({ searchBuffer: input, startPos: 0 })
  17. t.equal(pos, -1)
  18. })
  19. tap.test('recognizes all valid characters', async t => {
  20. const input = Buffer.from('Foo.0-bar=baz')
  21. const pos = findNameEnd({ searchBuffer: input, startPos: 0 })
  22. t.equal(pos, 9)
  23. })