-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Simplify pretty print expressions test by reducing cases and in…
…creasing runs
- Loading branch information
Showing
2 changed files
with
26 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,21 @@ | ||
import fc from "fast-check"; | ||
import { AstExpression, eqExpressions, getAstFactory } from "../../ast/ast"; | ||
import { eqExpressions, getAstFactory } from "../../ast/ast"; | ||
import { prettyPrint } from "../../prettyPrinter"; | ||
import { getParser } from "../../grammar"; | ||
import { | ||
randomAstConditional, | ||
randomAstOpBinary, | ||
randomAstOpUnary, | ||
randomAstExpression, | ||
randomAstInitOf, | ||
randomAstNull, | ||
randomAstStaticCall, | ||
randomAstStructInstance, | ||
randomAstStructFieldInitializer, | ||
randomAstId, | ||
randomAstFieldAccess, | ||
randomAstMethodCall, | ||
randomAstBoolean, | ||
randomAstNumber, | ||
randomAstString, | ||
} from "../utils/expression/randomAst"; | ||
import { randomAstExpression } from "../utils/expression/randomAst"; | ||
|
||
describe("Pretty Print Expressions", () => { | ||
const maxDepth = 3; | ||
const expression = () => randomAstExpression(maxDepth); | ||
|
||
const cases: [string, fc.Arbitrary<AstExpression>][] = [ | ||
// | ||
// Primary expressions | ||
// | ||
["AstMethodCall", randomAstMethodCall(expression(), expression())], | ||
["AstFieldAccess", randomAstFieldAccess(expression())], | ||
["AstStaticCall", randomAstStaticCall(expression())], | ||
[ | ||
"AstStructInstance", | ||
randomAstStructInstance( | ||
randomAstStructFieldInitializer(expression()), | ||
), | ||
], | ||
["AstId", randomAstId()], | ||
["AstNull", randomAstNull()], | ||
["AstInitOf", randomAstInitOf(expression())], | ||
["AstString", randomAstString()], | ||
|
||
// | ||
// Literals | ||
// | ||
["AstNumber", randomAstNumber()], | ||
["AstBoolean", randomAstBoolean()], | ||
|
||
[ | ||
"AstConditional", | ||
randomAstConditional(expression(), expression(), expression()), | ||
], | ||
["AstOpBinary", randomAstOpBinary(expression(), expression())], | ||
["AstOpUnary", randomAstOpUnary(expression())], | ||
]; | ||
|
||
cases.forEach(([caseName, astGenerator]) => { | ||
it(`should parse ${caseName}`, () => { | ||
fc.assert( | ||
fc.property(astGenerator, (generatedAst) => { | ||
const prettyBefore = prettyPrint(generatedAst); | ||
const parser = getParser(getAstFactory(), "new"); | ||
const parsedAst = parser.parseExpression(prettyBefore); | ||
expect(eqExpressions(generatedAst, parsedAst)).toBe(true); | ||
}), | ||
{ seed: 1 }, | ||
); | ||
}); | ||
it(`should parse Ast`, () => { | ||
fc.assert( | ||
fc.property(randomAstExpression(maxDepth), (generatedAst) => { | ||
const prettyBefore = prettyPrint(generatedAst); | ||
const parser = getParser(getAstFactory(), "new"); | ||
const parsedAst = parser.parseExpression(prettyBefore); | ||
expect(eqExpressions(generatedAst, parsedAst)).toBe(true); | ||
}), | ||
{ seed: 1, numRuns: 5000 }, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters