@@ -8,67 +8,61 @@ import test from 'node:test'
8
8
import { ParseEnglish } from 'parse-english'
9
9
import { visit } from 'unist-util-visit'
10
10
import { isLiteral } from './index.js'
11
- import * as mod from './index.js'
12
-
13
- test ( 'isLiteral()' , ( ) => {
14
- assert . deepEqual (
15
- Object . keys ( mod ) . sort ( ) ,
16
- [ 'isLiteral' ] ,
17
- 'should expose the public api'
18
- )
19
-
20
- assert . throws (
21
- ( ) => {
22
- // @ts -expect-error runtime.
11
+
12
+ test ( 'isLiteral' , async function ( t ) {
13
+ await t . test ( 'should expose the public api' , async function ( ) {
14
+ assert . deepEqual ( Object . keys ( await import ( './index.js' ) ) . sort ( ) , [
15
+ 'isLiteral'
16
+ ] )
17
+ } )
18
+
19
+ await t . test ( 'should throw without arguments' , async function ( ) {
20
+ assert . throws ( function ( ) {
21
+ // @ts -expect-error: check how the runtime handles a missing node.
23
22
isLiteral ( )
24
- } ,
25
- / P a r e n t m u s t b e a n o d e / ,
26
- 'should throw without arguments'
27
- )
28
-
29
- assert . throws (
30
- ( ) => {
31
- // @ts -expect-error runtime.
23
+ } , / P a r e n t m u s t b e a n o d e / )
24
+ } )
25
+
26
+ await t . test ( 'should throw without parent' , async function ( ) {
27
+ assert . throws ( function ( ) {
28
+ // @ts -expect-error: check how the runtime handles a non-none.
32
29
isLiteral ( { } )
33
- } ,
34
- / P a r e n t m u s t b e a n o d e / ,
35
- 'should throw without parent'
36
- )
37
-
38
- assert . throws (
39
- ( ) => {
40
- // @ts -expect-error runtime.
30
+ } , / P a r e n t m u s t b e a n o d e / )
31
+ } )
32
+
33
+ await t . test ( 'should throw without node' , async function ( ) {
34
+ assert . throws ( function ( ) {
35
+ // @ts -expect-error: check how the runtime handles a non-none.
41
36
isLiteral ( { children : [ ] } )
42
- } ,
43
- / I n d e x m u s t b e a n u m b e r / ,
44
- 'should throw without node'
45
- )
46
-
47
- assert . throws (
48
- ( ) => {
49
- // @ts -expect-error runtime.
37
+ } , / I n d e x m u s t b e a n u m b e r / )
38
+ } )
39
+
40
+ await t . test ( 'should throw if `node` is not in `parent`' , async function ( ) {
41
+ assert . throws ( function ( ) {
42
+ // @ts -expect-error: check how the runtime handles a non-none.
50
43
isLiteral ( { children : [ ] } , { type : 'a' } )
51
- } ,
52
- / N o d e m u s t b e a c h i l d o f ` p a r e n t ` / ,
53
- 'should throw if `node` is not in `parent`'
54
- )
55
-
56
- assert . doesNotThrow ( ( ) => {
57
- const n = { type : 'a' }
58
- // @ts -expect-error runtime.
59
- isLiteral ( { children : [ n ] } , n )
60
- } , 'should not throw if `node` is in `parent`' )
61
-
62
- assert . doesNotThrow ( ( ) => {
63
- process ( 'Well? Ha! Funky' , ( _ , index , parent ) => {
64
- assert . strictEqual (
65
- parent && index !== undefined && isLiteral ( parent , index ) ,
66
- false
67
- )
44
+ } , / N o d e m u s t b e a c h i l d o f ` p a r e n t ` / )
45
+ } )
46
+
47
+ await t . test ( 'should not throw if `node` is in `parent`' , async function ( ) {
48
+ assert . doesNotThrow ( function ( ) {
49
+ const n = { type : 'a' }
50
+ // @ts -expect-error: check how the runtime handles a non-none.
51
+ isLiteral ( { children : [ n ] } , n )
68
52
} )
69
- } , 'should work on single word sentences' )
53
+ } )
54
+
55
+ await t . test ( 'should work on single word sentences' , async function ( ) {
56
+ assert . doesNotThrow ( function ( ) {
57
+ process ( 'Well? Ha! Funky' , function ( _ , index , parent ) {
58
+ assert ( parent )
59
+ assert ( index !== undefined )
60
+ assert . strictEqual ( isLiteral ( parent , index ) , false )
61
+ } )
62
+ } )
63
+ } )
70
64
71
- assert . doesNotThrow ( ( ) => {
65
+ await t . test ( 'should work on initial nodes' , async function ( ) {
72
66
const fixtures = [
73
67
'Foo - is meant as a literal.' ,
74
68
'Foo – is meant as a literal.' ,
@@ -83,17 +77,15 @@ test('isLiteral()', () => {
83
77
let index = - 1
84
78
85
79
while ( ++ index < fixtures . length ) {
86
- process ( fixtures [ index ] , ( _ , index , parent ) => {
87
- assert . strictEqual (
88
- parent && index !== undefined && isLiteral ( parent , index ) ,
89
- index === 0 ,
90
- String ( index )
91
- )
80
+ process ( fixtures [ index ] , function ( _ , index , parent ) {
81
+ assert ( parent )
82
+ assert ( index !== undefined )
83
+ assert . strictEqual ( isLiteral ( parent , index ) , index === 0 )
92
84
} )
93
85
}
94
- } , 'Initial' )
86
+ } )
95
87
96
- assert . doesNotThrow ( ( ) => {
88
+ await t . test ( 'should work on final nodes' , async function ( ) {
97
89
const fixtures = [
98
90
'Meant as a literal is - foo.' ,
99
91
'Meant as a literal is – foo.' ,
@@ -108,17 +100,18 @@ test('isLiteral()', () => {
108
100
let index = - 1
109
101
110
102
while ( ++ index < fixtures . length ) {
111
- process ( fixtures [ index ] , ( _ , index , parent ) => {
103
+ process ( fixtures [ index ] , function ( _ , index , parent ) {
104
+ assert ( parent )
105
+ assert ( index !== undefined )
112
106
assert . strictEqual (
113
- parent && index !== undefined && isLiteral ( parent , index ) ,
114
- parent && index === parent . children . length - 2 ,
115
- String ( index )
107
+ isLiteral ( parent , index ) ,
108
+ index === parent . children . length - 2
116
109
)
117
110
} )
118
111
}
119
- } , 'Final' )
112
+ } )
120
113
121
- assert . doesNotThrow ( ( ) => {
114
+ await t . test ( 'should work on internal nodes' , async function ( ) {
122
115
const fixtures = [
123
116
'The word, foo, is meant as a literal.' ,
124
117
'The word -foo- is meant as a literal.' ,
@@ -150,7 +143,7 @@ test('isLiteral()', () => {
150
143
let index = - 1
151
144
152
145
while ( ++ index < fixtures . length ) {
153
- process ( fixtures [ index ] , ( _ , place , parent ) => {
146
+ process ( fixtures [ index ] , function ( _ , place , parent ) {
154
147
let pos = 5
155
148
156
149
// Adjacent hyphens are part of the word.
@@ -163,21 +156,22 @@ test('isLiteral()', () => {
163
156
pos = 6
164
157
}
165
158
166
- assert . strictEqual (
167
- parent && place !== undefined && isLiteral ( parent , place ) ,
168
- place === pos ,
169
- String ( index )
170
- )
159
+ assert ( parent )
160
+ assert ( place !== undefined )
161
+ assert . strictEqual ( isLiteral ( parent , place ) , place === pos )
171
162
} )
172
163
}
173
- } , 'Internal' )
164
+ } )
174
165
} )
175
166
176
167
/**
177
168
* Shortcut to process a fixture and invoke `visitor` for each of its word
178
169
* nodes.
170
+ *
179
171
* @param {string } fixture
172
+ * Natural language.
180
173
* @param {Visitor } visitor
174
+ * Visitor.
181
175
*/
182
176
function process ( fixture , visitor ) {
183
177
const tree = new ParseEnglish ( ) . parse ( fixture )
0 commit comments