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 { selectAll } from 'hast-util-select'
4
5
import { truncate } from './index.js'
5
6
6
- test ( 'hastUtilTruncate' , ( t ) => {
7
- t . deepEqual (
7
+ test ( 'hastUtilTruncate' , ( ) => {
8
+ assert . deepEqual (
8
9
truncate ( h ( 'p' , 'Lorem ipsum dolor sit amet' ) , { size : 11 } ) ,
9
10
h ( 'p' , 'Lorem ipsum' ) ,
10
11
'should truncate'
11
12
)
12
13
13
- t . deepEqual (
14
+ assert . deepEqual (
14
15
truncate ( h ( 'p' , 'Lorem ipsum dolor sit amet' ) , { size : 10 } ) ,
15
16
h ( 'p' , 'Lorem' ) ,
16
17
'should truncate to a nice break'
17
18
)
18
19
19
- t . deepEqual (
20
+ assert . deepEqual (
20
21
truncate ( h ( 'p' , 'Lorem ipsum dolor sit amet' ) , { size : 4 } ) ,
21
22
h ( 'p' , 'Lore' ) ,
22
23
'should truncate to an ugly break if there’s no perfect break'
23
24
)
24
25
25
- t . deepEqual (
26
+ assert . deepEqual (
26
27
truncate ( h ( 'p' , 'Lorem ipsum dolor sit amet' ) , { size : 10 , ellipsis : '…' } ) ,
27
28
h ( 'p' , 'Lorem…' ) ,
28
29
'should truncate w/ `ellipsis`'
29
30
)
30
31
31
- t . deepEqual (
32
+ assert . deepEqual (
32
33
truncate ( h ( 'p' , 'Lorem ipsum dolor sit amet' ) , { size : 11 } ) ,
33
34
h ( 'p' , 'Lorem ipsum' ) ,
34
35
'should truncate right to `size`, if that’s a perfect break'
35
36
)
36
37
37
- t . deepEqual (
38
+ assert . deepEqual (
38
39
truncate ( h ( 'p' , 'Lorem ipsum dolor sit amet' ) , { size : 12 } ) ,
39
40
h ( 'p' , 'Lorem ipsum' ) ,
40
41
'should truncate right to the wordbreak before `size`, if that points to whitespace'
41
42
)
42
43
43
- t . deepEqual (
44
+ assert . deepEqual (
44
45
truncate ( h ( 'p' , 'Lorem ipsum, dolor sit amet' ) , { size : 11 } ) ,
45
46
h ( 'p' , 'Lorem ipsum' ) ,
46
47
'should truncate right to the wordbreak before `size`, if that points to punctuation'
47
48
)
48
49
49
- t . deepEqual (
50
+ assert . deepEqual (
50
51
truncate ( h ( 'p' , 'Lorem ipsum, dolor sit amet' ) , { size : 12 } ) ,
51
52
h ( 'p' , 'Lorem ipsum,' ) ,
52
53
'should truncate right to the punctuation at `size`, if that points to whitespace'
53
54
)
54
55
55
- t . deepEqual (
56
+ assert . deepEqual (
56
57
truncate ( h ( 'p' , 'Lorem ipsum dolor sit amet' ) , {
57
58
size : 10 ,
58
59
maxCharacterStrip : 0
@@ -67,7 +68,7 @@ test('hastUtilTruncate', (t) => {
67
68
' adipisicing elit'
68
69
] )
69
70
70
- t . deepEqual (
71
+ assert . deepEqual (
71
72
truncate (
72
73
h ( 'p' , [
73
74
'Lorem ipsum dolor sit amet, ' ,
@@ -83,11 +84,9 @@ test('hastUtilTruncate', (t) => {
83
84
'should copy elements'
84
85
)
85
86
86
- t . deepEqual (
87
+ assert . deepEqual (
87
88
truncate ( tree , { ignore : selectAll ( 'del' , tree ) } ) ,
88
89
h ( 'p' , [ 'Lorem ipsum dolor sit amet, ' , ' adipisicing elit' ] ) ,
89
90
'should truncate w/ `ignore`'
90
91
)
91
-
92
- t . end ( )
93
92
} )
0 commit comments