1
- import test from 'tape'
1
+ import assert from 'node:assert/strict'
2
+ import test from 'node:test'
2
3
import { h } from 'hastscript'
3
4
import { findAndReplace } from './index.js'
4
5
5
- test ( 'findAndReplace' , ( t ) => {
6
- t . throws (
6
+ test ( 'findAndReplace' , ( ) => {
7
+ assert . throws (
7
8
( ) => {
8
9
// @ts -expect-error runtime.
9
10
findAndReplace ( create ( ) , true )
@@ -12,7 +13,7 @@ test('findAndReplace', (t) => {
12
13
'should throw on invalid search and replaces'
13
14
)
14
15
15
- t . deepEqual (
16
+ assert . deepEqual (
16
17
findAndReplace ( create ( ) , 'emphasis' ) ,
17
18
h ( 'p' , [
18
19
'Some ' ,
@@ -26,7 +27,7 @@ test('findAndReplace', (t) => {
26
27
'should remove without `replace`'
27
28
)
28
29
29
- t . deepEqual (
30
+ assert . deepEqual (
30
31
findAndReplace ( create ( ) , 'emphasis' , '!!!' ) ,
31
32
h ( 'p' , [
32
33
'Some ' ,
@@ -40,7 +41,7 @@ test('findAndReplace', (t) => {
40
41
'should work when given `find` and `replace`'
41
42
)
42
43
43
- t . deepEqual (
44
+ assert . deepEqual (
44
45
findAndReplace (
45
46
create ( ) ,
46
47
/ e m ( \w + ) i s / ,
@@ -58,7 +59,7 @@ test('findAndReplace', (t) => {
58
59
'should work when given `find` as a `RegExp` and `replace` as a `Function`'
59
60
)
60
61
61
- t . deepEqual (
62
+ assert . deepEqual (
62
63
findAndReplace ( create ( ) , 'emphasis' , ( ) => '' ) ,
63
64
h ( 'p' , [
64
65
'Some ' ,
@@ -72,7 +73,7 @@ test('findAndReplace', (t) => {
72
73
'should work when given `replace` returns an empty string'
73
74
)
74
75
75
- t . deepEqual (
76
+ assert . deepEqual (
76
77
findAndReplace ( create ( ) , 'emphasis' , ( ) => h ( 'a' , h ( 'b' , 'c' ) ) ) ,
77
78
h ( 'p' , [
78
79
'Some ' ,
@@ -86,7 +87,7 @@ test('findAndReplace', (t) => {
86
87
'should work when given `replace` returns a node'
87
88
)
88
89
89
- t . deepEqual (
90
+ assert . deepEqual (
90
91
findAndReplace ( create ( ) , 'emphasis' , ( ) => [ h ( 'a' ) , h ( 'b' , 'c' ) ] ) ,
91
92
h ( 'p' , [
92
93
'Some ' ,
@@ -100,7 +101,7 @@ test('findAndReplace', (t) => {
100
101
'should work when given `replace` returns a list of nodes'
101
102
)
102
103
103
- t . deepEqual (
104
+ assert . deepEqual (
104
105
findAndReplace ( create ( ) , [
105
106
[ 'emphasis' , '!!!' ] ,
106
107
[ 'importance' , '???' ]
@@ -117,7 +118,7 @@ test('findAndReplace', (t) => {
117
118
'should work when given `search` as an matrix of strings'
118
119
)
119
120
120
- t . deepEqual (
121
+ assert . deepEqual (
121
122
findAndReplace ( create ( ) , { code : 'hacks' , ',' : '!' } ) ,
122
123
h ( 'p' , [
123
124
'Some ' ,
@@ -133,7 +134,7 @@ test('findAndReplace', (t) => {
133
134
'should work when given `search` as an object of strings'
134
135
)
135
136
136
- t . deepEqual (
137
+ assert . deepEqual (
137
138
findAndReplace ( create ( ) , / \B m p \B / , '[MP]' ) ,
138
139
h ( 'p' , [
139
140
'Some ' ,
@@ -147,7 +148,7 @@ test('findAndReplace', (t) => {
147
148
'should work on partial matches'
148
149
)
149
150
150
- t . deepEqual (
151
+ assert . deepEqual (
151
152
findAndReplace ( create ( ) , {
152
153
emphasis ( ) {
153
154
return h ( 'a' , 'importance' )
@@ -166,7 +167,7 @@ test('findAndReplace', (t) => {
166
167
'should find-and-replace recursively'
167
168
)
168
169
169
- t . deepEqual (
170
+ assert . deepEqual (
170
171
findAndReplace (
171
172
h ( 'p' , [
172
173
'Some ' ,
@@ -193,13 +194,13 @@ test('findAndReplace', (t) => {
193
194
'should ignore from options'
194
195
)
195
196
196
- t . deepEqual (
197
+ assert . deepEqual (
197
198
findAndReplace ( create ( ) , 'emphasis' , ( ) => false ) ,
198
199
create ( ) ,
199
200
'should not replace when returning `false`'
200
201
)
201
202
202
- t . deepEqual (
203
+ assert . deepEqual (
203
204
findAndReplace ( h ( 'p' , 'Some emphasis, importance, and code.' ) , {
204
205
importance ( /** @type {string } */ match ) {
205
206
return h ( 'strong' , match )
@@ -215,7 +216,7 @@ test('findAndReplace', (t) => {
215
216
'should not be order-sensitive with strings'
216
217
)
217
218
218
- t . deepEqual (
219
+ assert . deepEqual (
219
220
findAndReplace ( h ( 'p' , 'aaa bbb' ) , [
220
221
[
221
222
/ \b \w + \b / g,
@@ -227,7 +228,7 @@ test('findAndReplace', (t) => {
227
228
h ( 'p' , [ h ( 'strong' , 'aaa' ) , ' bbb' ] ) ,
228
229
'should support a match, and then a `false`'
229
230
)
230
- t . deepEqual (
231
+ assert . deepEqual (
231
232
findAndReplace ( h ( 'p' , 'Some emphasis, importance, and code.' ) , [
232
233
[
233
234
/ i m p o r t a n c e / g,
@@ -252,7 +253,7 @@ test('findAndReplace', (t) => {
252
253
'should not be order-sensitive with regexes'
253
254
)
254
255
255
- t . deepEqual (
256
+ assert . deepEqual (
256
257
findAndReplace ( create ( ) , 'and' , 'alert(1)' ) ,
257
258
h ( 'p' , [
258
259
'Some ' ,
@@ -268,7 +269,7 @@ test('findAndReplace', (t) => {
268
269
'security: replacer as string (safe)'
269
270
)
270
271
271
- t . deepEqual (
272
+ assert . deepEqual (
272
273
findAndReplace ( create ( ) , 'and' , ( ) => h ( 'script' , 'alert(1)' ) ) ,
273
274
h ( 'p' , [
274
275
'Some ' ,
@@ -283,8 +284,6 @@ test('findAndReplace', (t) => {
283
284
] ) ,
284
285
'security: replacer as function (unsafe)'
285
286
)
286
-
287
- t . end ( )
288
287
} )
289
288
290
289
function create ( ) {
0 commit comments