@@ -43,10 +43,11 @@ test('cst returns', async t => {
4343 t . is ( root . ruleName , 'start' ) ;
4444
4545 // "a"
46- let { matchLength, _type, children} = root . children [ 0 ] ;
47- t . is ( children . length , 0 ) ;
48- t . is ( matchLength , 1 ) ;
49- t . is ( _type , - 1 ) ;
46+ let term = root . children [ 0 ] ;
47+ t . is ( term . children . length , 0 ) ;
48+ t . is ( term . matchLength , 1 ) ;
49+ t . is ( term . _type , 1 ) ;
50+ t . true ( term . isTerminal ( ) ) ;
5051
5152 matcher = await wasmMatcherForGrammar ( ohm . grammar ( 'G { start = "a" b\nb = "b" }' ) ) ;
5253
@@ -59,22 +60,21 @@ test('cst returns', async t => {
5960
6061 // "a"
6162 const [ childA , childB ] = root . children ;
62- ( { matchLength, _type, children} = childA ) ;
63- t . is ( children . length , 0 ) ;
64- t . is ( matchLength , 1 ) ;
65- t . is ( _type , - 1 ) ;
63+ t . is ( childA . children . length , 0 ) ;
64+ t . is ( childA . matchLength , 1 ) ;
65+ t . true ( childA . isTerminal ( ) ) ;
6666
6767 // NonterminalNode for b
6868 t . is ( childB . children . length , 1 ) ;
6969 t . is ( childB . matchLength , 1 ) ;
7070 t . is ( childB . ruleName , 'b' ) ;
7171
7272 // TerminalNode for "b"
73- // eslint-disable-next-line no-unused-vars
74- ( { matchLength , _type , children } = childB . children [ 0 ] ) ;
75- t . is ( children . length , 0 ) ;
76- t . is ( matchLength , 1 ) ;
77- t . is ( _type , - 1 ) ;
73+ term = childB . children [ 0 ] ;
74+ t . is ( term . children . length , 0 ) ;
75+ t . is ( term . matchLength , 1 ) ;
76+ t . true ( term . isTerminal ( ) ) ;
77+ t . is ( term . ctorName , '_terminal' ) ;
7878} ) ;
7979
8080test ( 'cst with lookahead' , async t => {
@@ -138,7 +138,7 @@ test('cst for opt', async t => {
138138 // iter
139139 let iter = root . children [ 0 ] ;
140140 t . is ( iter . matchLength , 1 ) ;
141- t . is ( iter . _type , - 2 ) ;
141+ t . true ( iter . isIter ( ) ) ;
142142 t . is ( iter . children . length , 1 ) ;
143143 t . is ( iter . children [ 0 ] . isTerminal ( ) , true ) ;
144144 t . is ( iter . children [ 0 ] . matchLength , 1 ) ;
@@ -157,7 +157,7 @@ test('cst for opt', async t => {
157157 // eslint-disable-next-line no-unused-vars
158158 iter = root . children [ 0 ] ;
159159 t . is ( iter . matchLength , 0 ) ;
160- t . is ( iter . _type , - 2 ) ;
160+ t . true ( iter . isIter ( ) ) ;
161161 t . is ( iter . children . length , 0 ) ;
162162} ) ;
163163
@@ -176,7 +176,7 @@ test('cst for plus', async t => {
176176 // eslint-disable-next-line no-unused-vars
177177 const iter = root . children [ 0 ] ;
178178 t . is ( iter . matchLength , 1 ) ;
179- t . is ( iter . _type , - 2 ) ;
179+ t . true ( iter . isIter ( ) ) ;
180180 t . is ( iter . children . length , 1 ) ;
181181
182182 t . is ( iter . children [ 0 ] . isTerminal ( ) , true ) ;
@@ -205,7 +205,7 @@ test('cst with (small) repetition', async t => {
205205 const iter = root . children [ 0 ] ;
206206 t . is ( iter . matchLength , 3 ) ;
207207 t . is ( iter . children . length , 3 ) ;
208- t . is ( iter . _type , - 2 ) ;
208+ t . true ( iter . isIter ( ) ) ;
209209
210210 // Terminal children
211211 const [ childA , childB , childC ] = iter . children ;
@@ -229,39 +229,36 @@ test('cst with repetition and lookahead', async t => {
229229 t . is ( matchWithInput ( matcher , input ) , 1 ) ;
230230
231231 // x
232- let { matchLength , _type , children } = matcher . getCstRoot ( ) ;
233- t . is ( matchLength , 3 ) ;
234- t . is ( children . length , 1 ) ;
235- t . is ( _type , 0 ) ;
232+ const root = matcher . getCstRoot ( ) ;
233+ t . is ( root . matchLength , 3 ) ;
234+ t . is ( root . children . length , 1 ) ;
235+ t . true ( root . isNonterminal ( ) ) ;
236236
237237 // iter
238- ( { matchLength , _type , children } = children [ 0 ] ) ;
239- t . is ( matchLength , 3 ) ;
240- t . is ( children . length , 3 ) ;
241- t . is ( _type , - 2 ) ;
238+ const iter = root . children [ 0 ] ;
239+ t . is ( iter . matchLength , 3 ) ;
240+ t . is ( iter . children . length , 3 ) ;
241+ t . true ( iter . isIter ( ) ) ;
242242
243- const [ childA , childB , childC ] = children ;
244- ( { matchLength, _type, children} = childA ) ;
245- t . is ( matchLength , 1 ) ;
246- t . is ( children . length , 1 ) ;
247- t . is ( _type , 0 ) ;
248- t . is ( children [ 0 ] . isTerminal ( ) , true ) ;
249- t . is ( children [ 0 ] . matchLength , 1 ) ;
243+ const [ childA , childB , childC ] = iter . children ;
244+ t . is ( childA . matchLength , 1 ) ;
245+ t . is ( childA . children . length , 1 ) ;
246+ t . true ( childA . isNonterminal ( ) ) ;
247+ t . true ( childA . children [ 0 ] . isTerminal ( ) ) ;
248+ t . is ( childA . children [ 0 ] . matchLength , 1 ) ;
250249
251- ( { matchLength, _type, children} = childB ) ;
252- t . is ( matchLength , 1 ) ;
253- t . is ( children . length , 1 ) ;
254- t . is ( _type , 0 ) ;
255- t . is ( children [ 0 ] . isTerminal ( ) , true ) ;
256- t . is ( children [ 0 ] . matchLength , 1 ) ;
250+ t . is ( childB . matchLength , 1 ) ;
251+ t . is ( childB . children . length , 1 ) ;
252+ t . true ( childB . isNonterminal ( ) ) ;
253+ t . true ( childB . children [ 0 ] . isTerminal ( ) ) ;
254+ t . is ( childB . children [ 0 ] . matchLength , 1 ) ;
257255
258256 // eslint-disable-next-line no-unused-vars
259- ( { matchLength, _type, children} = childC ) ;
260- t . is ( matchLength , 1 ) ;
261- t . is ( children . length , 1 ) ;
262- t . is ( _type , 0 ) ;
263- t . is ( children [ 0 ] . isTerminal ( ) , true ) ;
264- t . is ( children [ 0 ] . matchLength , 1 ) ;
257+ t . is ( childC . matchLength , 1 ) ;
258+ t . is ( childC . children . length , 1 ) ;
259+ t . true ( childC . isNonterminal ( ) ) ;
260+ t . true ( childC . children [ 0 ] . isTerminal ( ) ) ;
261+ t . is ( childC . children [ 0 ] . matchLength , 1 ) ;
265262
266263 matcher = await wasmMatcherForGrammar ( ohm . grammar ( 'G {x = (~space any)+ spaces any+}' ) ) ;
267264 input = '/ab xy' ;
@@ -564,34 +561,31 @@ test('basic memoization', async t => {
564561 return view . getUint32 ( colOffset + SIZEOF_UINT32 * ruleId , true ) ;
565562 } ;
566563
567- const cstRoot = matcher . getCstRoot ( ) ;
564+ const root = matcher . getCstRoot ( ) ;
568565
569566 // start
570- let { matchLength, _type, children} = cstRoot ;
571- t . is ( matchLength , 2 ) ;
572- t . is ( children . length , 2 ) ;
573- t . is ( _type , 0 ) ;
567+ t . is ( root . matchLength , 2 ) ;
568+ t . is ( root . children . length , 2 ) ;
569+ t . is ( root . ctorName , 'start' ) ;
574570
575- const [ childA , childB ] = children ;
571+ const [ childA , childB ] = root . children ;
576572
577573 // "a"
578- t . is ( childA . isTerminal ( ) , true ) ;
574+ t . true ( childA . isTerminal ( ) ) ;
579575 t . is ( childA . matchLength , 1 ) ;
580576
581577 // b
582- // eslint-disable-next-line no-unused-vars
583- ( { matchLength, _type, children} = childB ) ;
584- t . is ( matchLength , 1 ) ;
585- t . is ( children . length , 1 ) ;
586- t . is ( _type , 0 ) ;
578+ t . is ( childB . matchLength , 1 ) ;
579+ t . is ( childB . children . length , 1 ) ;
580+ t . is ( childB . ctorName , 'b' ) ;
587581
588582 // "b"
589- t . is ( children [ 0 ] . isTerminal ( ) , true ) ;
590- t . is ( children [ 0 ] . matchLength , 1 ) ;
583+ t . true ( childB . children [ 0 ] . isTerminal ( ) ) ;
584+ t . is ( childB . children [ 0 ] . matchLength , 1 ) ;
591585
592586 // Expect memo for `b` at position 1, and `start` at position 0.
593587 t . is ( getMemo ( 1 , 'b' ) , childB . _base ) ;
594- t . is ( getMemo ( 0 , 'start' ) , cstRoot . _base ) ;
588+ t . is ( getMemo ( 0 , 'start' ) , root . _base ) ;
595589} ) ;
596590
597591test ( 'more memoization' , async t => {
@@ -979,3 +973,14 @@ test.failing('unicode', async t => {
979973 t . is ( matchWithInput ( m , source ) , 1 ) ;
980974 t . is ( unparse ( m ) , source ) ;
981975} ) ;
976+
977+ // eslint-disable-next-line ava/no-skip-test
978+ test . skip ( 'iter node map' , async t => {
979+ const m = await wasmMatcherForGrammar ( ohm . grammar ( 'G { Start = (letter digit)* }' ) ) ;
980+ t . is ( matchWithInput ( m , 'a1 b2 c 3' ) , 1 ) ;
981+ const iter = m . getCstRoot ( ) . children [ 0 ] ;
982+ t . deepEqual (
983+ iter . map ( ( letter , digit ) => `${ digit } ${ letter } ` ) ,
984+ [ '1a' , '2b' , '3c' ] ,
985+ ) ;
986+ } ) ;
0 commit comments