-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
87 lines (76 loc) · 2.55 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import assert from 'node:assert/strict'
import test from 'node:test'
import {h} from 'hastscript'
import {shiftHeading} from 'hast-util-shift-heading'
test('shiftHeading', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(
Object.keys(await import('hast-util-shift-heading')).sort(),
['shiftHeading']
)
})
await t.test('should throw when not given a number', async function () {
assert.throws(function () {
// @ts-ignore: check how a missing `shift` is handled.
shiftHeading(h(''))
}, /^Error: Expected a non-null finite integer, not `undefined`$/)
})
await t.test('should throw when given not a number', async function () {
assert.throws(function () {
shiftHeading(h(''), Number.NaN)
}, /^Error: Expected a non-null finite integer, not `NaN`$/)
})
await t.test('should throw when not given an integer', async function () {
assert.throws(function () {
shiftHeading(h(''), 0.1)
}, /^Error: Expected a non-null finite integer, not `0.1`$/)
})
await t.test(
'should throw when not given a finite number',
async function () {
assert.throws(function () {
shiftHeading(h(''), Number.POSITIVE_INFINITY)
}, /^Error: Expected a non-null finite integer, not `Infinity`$/)
}
)
await t.test(
'should throw when not given a non-null number',
async function () {
assert.throws(function () {
shiftHeading(h(''), 0)
}, /^Error: Expected a non-null finite integer, not `0`$/)
}
)
await t.test('should shift nodes upwards', async function () {
const tree = h('h1', 'Alpha')
shiftHeading(tree, 1)
assert.deepEqual(tree, h('h2', 'Alpha'))
})
await t.test('should shift nodes downwards', async function () {
const tree = h('h2', 'Bravo')
shiftHeading(tree, -1)
assert.deepEqual(tree, h('h1', 'Bravo'))
})
await t.test('should not shift upwards past h1', async function () {
const tree = h('h2', 'Charlie')
shiftHeading(tree, -2)
assert.deepEqual(tree, h('h1', 'Charlie'))
})
await t.test('should not shift downwards past h6', async function () {
const tree = h('h5', 'Delta')
shiftHeading(tree, 2)
assert.deepEqual(tree, h('h6', 'Delta'))
})
await t.test('should change a tree', async function () {
const tree = h('main', [
h('h1', 'Echo'),
h('p', 'Foxtrot'),
h('h5', 'Golf')
])
shiftHeading(tree, 2)
assert.deepEqual(
tree,
h('main', [h('h3', 'Echo'), h('p', 'Foxtrot'), h('h6', 'Golf')])
)
})
})