Skip to content

Commit 38ba0ee

Browse files
committed
test: parse/stringify roundtrip preserves equivalence
1 parent 95e727b commit 38ba0ee

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

test/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('isEquivalent', () => {
8686

8787
describe('without', () => {
8888
const withoutCases = [
89-
[/^a*$/, /^a{3,10}$/, /^(a{,2}|a{11,})$/],
89+
[/^a*$/, /^a{3,10}$/, /^(a{0,2}|a{11,})$/],
9090
]
9191
for (const [re1, re2, expected] of withoutCases) {
9292
test(`${re1} without ${re2} is ${expected}`, () => {

test/regex-parser.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { describe, it } from "node:test"
1+
import { describe, it, test } from "node:test"
22
import assert from "node:assert"
33
import { parseRegExp, parseRegExpString } from "../src/regex-parser"
4+
import { RB } from "../src/index"
45
import { ParseError } from "../src/parser"
56
import * as AST from "../src/ast"
67
import * as CharSet from "../src/char-set"
8+
import fc from "fast-check"
9+
import * as Arbitrary from './arbitrary-ast'
710

811
// Helper functions for cleaner test construction
912
function char(c: string) {
@@ -130,3 +133,25 @@ describe('parseRegExp', () => {
130133
})
131134

132135
})
136+
137+
test('parse/stringify roundtrip preserves equivalence', { todo: true }, () => {
138+
fc.assert(
139+
fc.property(
140+
Arbitrary.regexp(),
141+
(inputRegExp) => {
142+
const builder = RB(inputRegExp)
143+
const outputRegExp = builder.toRegExp()
144+
145+
// console.debug(inputRegExp)
146+
// console.debug(outputRegExp)
147+
148+
for (const str of builder.enumerate().take(10)) {
149+
assert.match(str, outputRegExp)
150+
assert.match(str, inputRegExp)
151+
}
152+
}
153+
),
154+
{ seed: -1651123632, path: "89:0", endOnFailure: true }
155+
)
156+
})
157+

test/regex.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ describe('fromRegExpAST', () => {
311311
assert.equal(actual.hash, expected.hash, RE.debugShow(actual) + '\n\n' + RE.debugShow(expected))
312312
})
313313
}
314+
315+
it('fixme', { todo: true }, () => {
316+
const actual = RE.fromRegExpAST(parseRegExp(/^(a(?!b))*$/))
317+
const expected = RE.star(RE.string('a'))
318+
assert.equal(actual.hash, expected.hash)
319+
})
320+
314321
})
315322

316323
})

0 commit comments

Comments
 (0)