util.test.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict'
  2. const test = require('tape')
  3. const {
  4. stringArrayToHexStripped,
  5. removeDotSegments
  6. } = require('../lib/utils')
  7. test('stringArrayToHexStripped', (t) => {
  8. const testCases = [
  9. [['0', '0', '0', '0'], ''],
  10. [['0', '0', '0', '1'], '1'],
  11. [['0', '0', '1', '0'], '10'],
  12. [['0', '1', '0', '0'], '100'],
  13. [['1', '0', '0', '0'], '1000'],
  14. [['1', '0', '0', '1'], '1001'],
  15. ]
  16. t.plan(testCases.length)
  17. testCases.forEach(([input, expected]) => {
  18. t.same(stringArrayToHexStripped(input), expected)
  19. })
  20. })
  21. // Just fixtures, because this function already tested by resolve
  22. test('removeDotSegments', (t) => {
  23. const testCases = []
  24. // https://github.com/fastify/fast-uri/issues/139
  25. testCases.push(['WS:/WS://1305G130505:1&%0D:1&C(XXXXX*)))))))XXX130505:UUVUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$aaaaaaaaaaaa13a',
  26. 'WS:/WS://1305G130505:1&%0D:1&C(XXXXX*)))))))XXX130505:UUVUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$aaaaaaaaaaaa13a'])
  27. t.plan(testCases.length)
  28. testCases.forEach(([input, expected]) => {
  29. t.same(removeDotSegments(input), expected)
  30. })
  31. })