1
1
/**
2
2
* @typedef {import('unist').Node } Node
3
3
* @typedef {import('unist').Literal<string> } Literal
4
- * @typedef {import('unist').Parent } Parent
5
- *
6
- * @typedef {string } Type
7
- * @typedef {Record<string, unknown> } Props
8
- * @typedef {import('unist-util-is').TestFunctionAnything } TestFunctionAnything
9
4
*/
10
5
11
- import test from 'tape'
6
+ import assert from 'node:assert/strict'
7
+ import test from 'node:test'
12
8
import { u } from 'unist-builder'
13
9
import { remove } from './index.js'
14
10
15
- test ( 'should compare nodes by partial properties' , ( t ) => {
11
+ test ( 'should compare nodes by partial properties' , ( ) => {
16
12
const tree = u ( 'node' , [ u ( 'leaf' , '1' ) , u ( 'leaf' , '2' ) ] )
17
13
const children = tree . children
18
14
const first = tree . children [ 0 ]
19
15
20
16
const next = remove ( tree , { value : '2' } )
21
17
22
- t . equal ( next , tree )
23
- t . deepEqual ( tree , u ( 'node' , [ first ] ) )
24
- t . equal ( tree . children , children )
25
- t . equal ( tree . children [ 0 ] , first )
26
-
27
- t . end ( )
18
+ assert . equal ( next , tree )
19
+ assert . deepEqual ( tree , u ( 'node' , [ first ] ) )
20
+ assert . equal ( tree . children , children )
21
+ assert . equal ( tree . children [ 0 ] , first )
28
22
} )
29
23
30
- test ( 'should remove nodes with children' , ( t ) => {
24
+ test ( 'should remove nodes with children' , ( ) => {
31
25
const tree = u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] )
32
26
const children = tree . children
33
27
const first = tree . children [ 0 ]
34
28
const last = tree . children [ 1 ]
35
29
36
30
const next = remove ( tree , test )
37
31
38
- t . equal ( next , tree )
39
- t . deepEqual ( tree , u ( 'root' , [ last ] ) )
40
- t . equal ( tree . children , children )
41
- t . equal ( tree . children [ 0 ] , last )
42
-
43
- t . end ( )
32
+ assert . equal ( next , tree )
33
+ assert . deepEqual ( tree , u ( 'root' , [ last ] ) )
34
+ assert . equal ( tree . children , children )
35
+ assert . equal ( tree . children [ 0 ] , last )
44
36
45
37
/**
46
38
* @param {Node } node
@@ -51,15 +43,13 @@ test('should remove nodes with children', (t) => {
51
43
}
52
44
} )
53
45
54
- test ( 'should return `null` if root node is removed' , ( t ) => {
46
+ test ( 'should return `null` if root node is removed' , ( ) => {
55
47
const tree = u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] )
56
48
57
- t . equal ( remove ( tree , 'root' ) , null )
58
-
59
- t . end ( )
49
+ assert . equal ( remove ( tree , 'root' ) , null )
60
50
} )
61
51
62
- test ( 'should cascade-remove parent nodes' , ( t ) => {
52
+ test ( 'should cascade-remove parent nodes' , ( ) => {
63
53
const tree = u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] )
64
54
const children = tree . children
65
55
// @ts -expect-error it exists!
@@ -68,12 +58,10 @@ test('should cascade-remove parent nodes', (t) => {
68
58
69
59
const next = remove ( tree , test )
70
60
71
- t . equal ( next , tree )
72
- t . deepEqual ( tree , u ( 'root' , [ last ] ) )
73
- t . equal ( tree . children , children )
74
- t . equal ( tree . children [ 0 ] , last )
75
-
76
- t . end ( )
61
+ assert . equal ( next , tree )
62
+ assert . deepEqual ( tree , u ( 'root' , [ last ] ) )
63
+ assert . equal ( tree . children , children )
64
+ assert . equal ( tree . children [ 0 ] , last )
77
65
78
66
/**
79
67
* @param {Node } node
@@ -84,57 +72,47 @@ test('should cascade-remove parent nodes', (t) => {
84
72
}
85
73
} )
86
74
87
- test ( 'should cascade-remove root nodes' , ( t ) => {
75
+ test ( 'should cascade-remove root nodes' , ( ) => {
88
76
const tree = u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] )
89
77
90
78
const next = remove ( tree , 'leaf' )
91
79
92
- t . equal ( next , null )
93
-
94
- t . end ( )
80
+ assert . equal ( next , null )
95
81
} )
96
82
97
- test ( 'should not cascade-remove nodes that were empty initially' , ( t ) => {
83
+ test ( 'should not cascade-remove nodes that were empty initially' , ( ) => {
98
84
const tree = u ( 'node' , [ u ( 'node' , [ ] ) , u ( 'node' , [ u ( 'leaf' ) ] ) ] )
99
85
100
86
remove ( tree , 'leaf' )
101
87
102
- t . deepEqual ( tree , u ( 'node' , [ u ( 'node' , [ ] ) ] ) )
103
-
104
- t . end ( )
88
+ assert . deepEqual ( tree , u ( 'node' , [ u ( 'node' , [ ] ) ] ) )
105
89
} )
106
90
107
- test ( 'should support type tests' , ( t ) => {
91
+ test ( 'should support type tests' , ( ) => {
108
92
const tree = u ( 'node' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] )
109
93
110
94
remove ( tree , { cascade : false } , 'leaf' )
111
95
112
- t . deepEqual ( tree , u ( 'node' , [ u ( 'node' , [ ] ) ] ) )
113
-
114
- t . end ( )
96
+ assert . deepEqual ( tree , u ( 'node' , [ u ( 'node' , [ ] ) ] ) )
115
97
} )
116
98
117
- test ( 'should support function tests' , ( t ) => {
99
+ test ( 'should support function tests' , ( ) => {
118
100
const tree = u ( 'node' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] )
119
101
120
102
remove ( tree , { cascade : false } , ( node ) => literal ( node ) && node . value === '1' )
121
103
122
- t . deepEqual ( tree , u ( 'node' , [ u ( 'node' , [ ] ) , u ( 'leaf' , '2' ) ] ) )
123
-
124
- t . end ( )
104
+ assert . deepEqual ( tree , u ( 'node' , [ u ( 'node' , [ ] ) , u ( 'leaf' , '2' ) ] ) )
125
105
} )
126
106
127
- test ( 'opts.cascade = true' , ( t ) => {
107
+ test ( 'opts.cascade = true' , ( ) => {
128
108
const tree = u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] )
129
109
130
110
const next = remove ( tree , { cascade : true } , 'leaf' )
131
111
132
- t . equal ( next , null )
133
-
134
- t . end ( )
112
+ assert . equal ( next , null )
135
113
} )
136
114
137
- test ( 'opts.cascade = false' , ( t ) => {
115
+ test ( 'opts.cascade = false' , ( ) => {
138
116
const tree = u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] )
139
117
const siblings = tree . children
140
118
const node = siblings [ 0 ]
@@ -143,17 +121,14 @@ test('opts.cascade = false', (t) => {
143
121
144
122
const next = remove ( tree , { cascade : false } , 'leaf' )
145
123
146
- t . equal ( next , tree )
147
- t . deepEqual ( tree , u ( 'root' , [ u ( 'node' , [ ] ) ] ) )
148
- t . equal ( tree . children , siblings )
149
- t . equal ( tree . children [ 0 ] , node )
150
- // @ts -expect-error it exists!
151
- t . equal ( tree . children [ 0 ] . children , children )
152
-
153
- t . end ( )
124
+ assert . equal ( next , tree )
125
+ assert . deepEqual ( tree , u ( 'root' , [ u ( 'node' , [ ] ) ] ) )
126
+ assert . equal ( tree . children , siblings )
127
+ assert . equal ( tree . children [ 0 ] , node )
128
+ assert . equal ( tree . children [ 0 ] . children , children )
154
129
} )
155
130
156
- test ( 'example from readme' , ( t ) => {
131
+ test ( 'example from readme' , ( ) => {
157
132
const tree = u ( 'root' , [
158
133
u ( 'leaf' , '1' ) ,
159
134
u ( 'node' , [
@@ -164,12 +139,10 @@ test('example from readme', (t) => {
164
139
u ( 'leaf' , '6' )
165
140
] )
166
141
167
- t . deepEqual (
142
+ assert . deepEqual (
168
143
remove ( tree , 'leaf' ) ,
169
144
u ( 'root' , [ u ( 'node' , [ u ( 'node' , [ u ( 'other' , '4' ) ] ) ] ) ] )
170
145
)
171
-
172
- t . end ( )
173
146
} )
174
147
175
148
/**
0 commit comments