|
1 | 1 | import test from 'ava'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | +import * as fc from 'fast-check'; |
2 | 4 | import * as ohm from 'ohm-js'; |
3 | 5 | import {performance} from 'perf_hooks'; |
4 | 6 |
|
@@ -34,14 +36,6 @@ function unparse(m, root) { |
34 | 36 | return ans; |
35 | 37 | } |
36 | 38 |
|
37 | | -// const dumpMemoTable = pos => { |
38 | | -// const arr = []; |
39 | | -// for (let i = 0; i < 6; i++) { |
40 | | -// arr.push(view.getUint32(pos * Constants.MEMO_COL_SIZE_BYTES + i * 4, true)); |
41 | | -// } |
42 | | -// console.log(arr.map(v => v.toString(16).padStart(8, '0')).join(' ')); |
43 | | -// }; |
44 | | - |
45 | 39 | test('input in memory', async t => { |
46 | 40 | const g = ohm.grammar('G { start = "x" }'); |
47 | 41 | const matcher = await wasmMatcherForGrammar(g); |
@@ -960,15 +954,23 @@ test('space skipping & lex', async t => { |
960 | 954 | } |
961 | 955 | }); |
962 | 956 |
|
963 | | -test('unicode built-ins', async t => { |
964 | | - const g = ohm.grammar(` |
965 | | - G { |
966 | | - Start = lower upper |
967 | | - }`); |
| 957 | +// fast-check's stringMatching combiner doesn't support unicode regexes. |
| 958 | +const arbitraryStringMatching = regex => |
| 959 | + fc.string({maxLength: 2, unit: 'binary'}).filter(str => regex.test(str)); |
| 960 | + |
| 961 | +test('unicode built-ins: non-ASII (fast-check)', async t => { |
| 962 | + const g = ohm.grammar('G { Start = letter letter }'); |
968 | 963 | const m = await wasmMatcherForGrammar(g); |
969 | | - t.is(matchWithInput(m, 'aA'), 1); |
970 | | - t.is(matchWithInput(m, ' aZ'), 1); |
971 | | - t.is(matchWithInput(m, ' zA'), 1); |
972 | | - t.is(matchWithInput(m, 'a@'), 0); |
973 | | - t.is(matchWithInput(m, 'a['), 0); |
| 964 | + const hasExpectedResult = wasmMatcher => { |
| 965 | + return fc.property(arbitraryStringMatching(/^\p{L}\p{L}$/u), str => { |
| 966 | + wasmMatcher.setInput(str); |
| 967 | + assert.equal(wasmMatcher.match(), 1); |
| 968 | + }); |
| 969 | + }; |
| 970 | + const details = fc.check(hasExpectedResult(m), { |
| 971 | + includeErrorInReport: true, |
| 972 | + interruptAfterTimeLimit: 200, |
| 973 | + }); |
| 974 | + t.log(`numRuns: ${details.numRuns}`); |
| 975 | + t.is(details.failed, false, `${fc.defaultReportMessage(details)}`); |
974 | 976 | }); |
0 commit comments