Debian Codegraph @

fast-uri/test/util.test.js

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