@@ -10,16 +10,21 @@ import {matchWithInput, unparse, toWasmGrammar} from './_helpers.js';
1010const scriptRel = relPath => new URL ( relPath , import . meta. url ) ;
1111const grammarSource = fs . readFileSync ( scriptRel ( 'data/liquid-html.ohm' ) , 'utf8' ) ;
1212
13- const liquid = ohm . grammars ( grammarSource ) ;
13+ const grammars = ohm . grammars ( grammarSource ) ;
14+
15+ test ( 'basic compilation' , async t => {
16+ Object . values ( grammars ) . forEach ( async g => await toWasmGrammar ( g ) ) ;
17+ t . pass ( ) ;
18+ } ) ;
1419
1520test ( 'basic matching (small)' , async t => {
1621 const input = `---
1722 layout: default
1823 ---
1924 {% assign year = page.started | date: '%Y' %}` ;
20- t . is ( liquid . LiquidHTML . match ( input ) . succeeded ( ) , true ) ;
25+ t . is ( grammars . LiquidHTML . match ( input ) . succeeded ( ) , true ) ;
2126
22- const g = await toWasmGrammar ( liquid . LiquidHTML ) ;
27+ const g = await toWasmGrammar ( grammars . LiquidHTML ) ;
2328 t . is ( matchWithInput ( g , input ) , 1 ) ;
2429 t . is ( unparse ( g ) , input ) ;
2530} ) ;
@@ -31,25 +36,25 @@ test('swatch.liquid', async t => {
3136 class="{% if x == 'x' %}x{% endif %}"
3237 {% endif %}
3338>` ;
34- const g = await toWasmGrammar ( liquid . LiquidHTML ) ;
39+ const g = await toWasmGrammar ( grammars . LiquidHTML ) ;
3540 t . is ( matchWithInput ( g , input ) , 1 ) ;
3641} ) ;
3742
3843test ( 'html comment' , async t => {
3944 const input = `{% if x %}
4045 <!-- x -->
4146 {% endif %}` ;
42- const g = await toWasmGrammar ( liquid . LiquidHTML ) ;
47+ const g = await toWasmGrammar ( grammars . LiquidHTML ) ;
4348 t . is ( matchWithInput ( g , input ) , 1 ) ;
4449} ) ;
4550
4651test ( 'book-review.liquid' , async t => {
4752 const input = fs . readFileSync ( scriptRel ( 'data/book-review.liquid' ) , 'utf8' ) ;
4853 let start = performance . now ( ) ;
49- t . is ( liquid . LiquidHTML . match ( input ) . succeeded ( ) , true ) ; // Trigger fillInputBuffer
54+ t . is ( grammars . LiquidHTML . match ( input ) . succeeded ( ) , true ) ; // Trigger fillInputBuffer
5055 t . log ( `Ohm.js: ${ ( performance . now ( ) - start ) . toFixed ( 2 ) } ms` ) ;
5156
52- const g = await toWasmGrammar ( liquid . LiquidHTML ) ;
57+ const g = await toWasmGrammar ( grammars . LiquidHTML ) ;
5358 start = performance . now ( ) ;
5459 t . is ( matchWithInput ( g , input ) , 1 ) ;
5560 t . log ( `Wasm: ${ ( performance . now ( ) - start ) . toFixed ( 2 ) } ms` ) ;
0 commit comments