-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
174 lines (148 loc) · 4.56 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import assert from 'node:assert/strict'
import test from 'node:test'
import {pointEnd, pointStart, position} from 'unist-util-position'
const properties = {
type: 'a',
position: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 2, offset: 1}
}
}
const noFields = {type: 'b', position: {start: {}, end: {}}}
const noPoints = {type: 'c', position: {}}
const noPosition = {type: 'd'}
test('core', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('unist-util-position')).sort(), [
'pointEnd',
'pointStart',
'position'
])
})
})
test('position', async function (t) {
await t.test('should get the whole position', async function () {
assert.deepEqual(position(properties), properties.position)
})
await t.test('should not get too low values', async function () {
assert.deepEqual(
position({
type: 'x',
position: {
start: {line: 0, column: 0, offset: -1},
end: {line: 0, column: 0, offset: -1}
}
}),
undefined
)
})
await t.test('should support points w/o `offset`', async function () {
assert.deepEqual(
position({
type: 'x',
position: {start: {line: 1, column: 1}, end: {line: 1, column: 2}}
}),
{
start: {line: 1, column: 1, offset: undefined},
end: {line: 1, column: 2, offset: undefined}
}
)
})
await t.test('should return nothing when without fields', async function () {
assert.deepEqual(position(noFields), undefined)
})
await t.test('should return nothing when without points', async function () {
assert.deepEqual(position(noPoints), undefined)
})
await t.test(
'should return nothing when without position',
async function () {
assert.deepEqual(position(noPosition), undefined)
}
)
await t.test('should return nothing when without node', async function () {
assert.deepEqual(position(), undefined)
})
})
test('pointStart', async function (t) {
await t.test('should get a side', async function () {
assert.deepEqual(pointStart(properties), properties.position.start)
})
await t.test('should not get too low values', async function () {
assert.deepEqual(
pointStart({
type: 'x',
position: {
start: {line: 0, column: 0, offset: -1},
end: {line: 0, column: 0, offset: -1}
}
}),
undefined
)
})
await t.test('should support points w/o `offset`', async function () {
assert.deepEqual(
pointStart({
type: 'x',
position: {start: {line: 1, column: 1}, end: {line: 1, column: 2}}
}),
{line: 1, column: 1, offset: undefined}
)
})
await t.test('should return nothing when without fields', async function () {
assert.deepEqual(pointStart(noFields), undefined)
})
await t.test('should return nothing when without points', async function () {
assert.deepEqual(pointStart(noPoints), undefined)
})
await t.test(
'should return nothing when without position',
async function () {
assert.deepEqual(pointStart(noPosition), undefined)
}
)
await t.test('should return nothing when without node', async function () {
assert.deepEqual(pointStart(), undefined)
})
})
test('pointEnd', async function (t) {
await t.test('should get a side', async function () {
assert.deepEqual(pointEnd(properties), properties.position.end)
})
await t.test('should not get too low values', async function () {
assert.deepEqual(
pointEnd({
type: 'x',
position: {
start: {line: 0, column: 0, offset: -1},
end: {line: 0, column: 0, offset: -1}
}
}),
undefined
)
})
await t.test('should support points w/o `offset`', async function () {
assert.deepEqual(
pointEnd({
type: 'x',
position: {start: {line: 1, column: 1}, end: {line: 1, column: 2}}
}),
{line: 1, column: 2, offset: undefined}
)
})
await t.test('should return nothing when without fields', async function () {
assert.deepEqual(pointEnd(noFields), undefined)
})
await t.test('should return nothing when without points', async function () {
assert.deepEqual(pointEnd(noPoints), undefined)
})
await t.test(
'should return nothing when without position',
async function () {
assert.deepEqual(pointEnd(noPosition), undefined)
}
)
await t.test('should return nothing when without node', async function () {
assert.deepEqual(pointEnd(), undefined)
})
})