Skip to content

Commit c89e3ff

Browse files
authored
feat: port tst test to node test runner (#2595)
1 parent 81e3d84 commit c89e3ff

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed
Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
11
'use strict'
22

3-
const { TernarySearchTree, tree } = require('../lib/core/tree')
4-
const { wellknownHeaderNames, headerNameLowerCasedRecord } = require('../lib/core/constants')
5-
const { test } = require('tap')
6-
7-
test('Ternary Search Tree', (t) => {
8-
t.plan(4)
9-
10-
t.test('The empty key cannot be added.', (t) => {
11-
t.plan(2)
12-
t.throws(() => new TernarySearchTree().insert(Buffer.from(''), ''))
3+
const { TernarySearchTree, tree } = require('../../lib/core/tree')
4+
const { wellknownHeaderNames, headerNameLowerCasedRecord } = require('../../lib/core/constants')
5+
const { describe, test } = require('node:test')
6+
const assert = require('node:assert')
7+
8+
describe('Ternary Search Tree', () => {
9+
test('The empty key cannot be added.', () => {
10+
assert.throws(() => new TernarySearchTree().insert(Buffer.from(''), ''))
1311
const tst = new TernarySearchTree()
1412
tst.insert(Buffer.from('a'), 'a')
15-
t.throws(() => tst.insert(Buffer.from(''), ''))
13+
assert.throws(() => tst.insert(Buffer.from(''), ''))
1614
})
1715

18-
t.test('duplicate key', (t) => {
19-
t.plan(2)
16+
test('duplicate key', () => {
2017
const tst = new TernarySearchTree()
2118
const key = Buffer.from('a')
2219
tst.insert(key, 'a')
23-
t.equal(tst.lookup(key), 'a')
20+
assert.strictEqual(tst.lookup(key), 'a')
2421
tst.insert(key, 'b')
25-
t.equal(tst.lookup(key), 'b')
22+
assert.strictEqual(tst.lookup(key), 'b')
2623
})
2724

28-
t.test('tree', (t) => {
29-
t.plan(wellknownHeaderNames.length)
25+
test('tree', () => {
3026
for (let i = 0; i < wellknownHeaderNames.length; ++i) {
3127
const key = wellknownHeaderNames[i]
32-
t.equal(tree.lookup(Buffer.from(key)), headerNameLowerCasedRecord[key])
28+
assert.strictEqual(tree.lookup(Buffer.from(key)), headerNameLowerCasedRecord[key])
3329
}
3430
})
3531

36-
t.test('fuzz', (t) => {
32+
test('fuzz', () => {
3733
const LENGTH = 2000
38-
t.plan(LENGTH)
3934
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
4035
const charactersLength = characters.length
4136

@@ -61,7 +56,7 @@ test('Ternary Search Tree', (t) => {
6156
}
6257

6358
for (let i = 0; i < LENGTH; ++i) {
64-
t.equal(tst.lookup(randomBuffer[i]), random[i])
59+
assert.strictEqual(tst.lookup(randomBuffer[i]), random[i])
6560
}
6661
})
6762
})

0 commit comments

Comments
 (0)