-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
54 lines (47 loc) · 1.57 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
import assert from 'node:assert/strict'
import test from 'node:test'
import {parse} from 'acorn'
import {positionFromEstree} from 'unist-util-position-from-estree'
test('positionFromEstree', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(
Object.keys(await import('unist-util-position-from-estree')).sort(),
['positionFromEstree']
)
})
await t.test('should support a missing node', async function () {
assert.deepEqual(positionFromEstree(), undefined)
})
await t.test('should support node w/o `loc`s', async function () {
assert.deepEqual(
positionFromEstree(parse('x', {ecmaVersion: 2020})),
undefined
)
})
await t.test('should support node w/ `loc`s', async function () {
assert.deepEqual(
positionFromEstree(parse('x', {ecmaVersion: 2020, locations: true})),
{
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 2, offset: 1}
}
)
})
await t.test('should support node w/ `range`s', async function () {
assert.deepEqual(
positionFromEstree(parse('x', {ecmaVersion: 2020, ranges: true})),
undefined
)
})
await t.test('should handle points w/o line/column', async function () {
assert.deepEqual(positionFromEstree({loc: {start: {}, end: {}}}), undefined)
})
await t.test('should handle points w/ too low values', async function () {
assert.deepEqual(
positionFromEstree({
loc: {start: {line: -1, column: -1}, end: {line: 1, column: 0}}
}),
undefined
)
})
})