Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun test() {
- // Raw strings are much nicer to read and maintain
- val scrutinee = parseStatement("""
- for (int i = 0;; i++) {
- blazour(i);
- }
- """)
- // match an AST subtree deeply
- scrutinee assertMatches node<ASTStatement> {
- // The node and child functions define matchers
- // The block can contain matchers for the children of the scrutinised node
- // If a node is not of the correct type, this can be reported with a nice error message (transparently to the test code)
- child<ASTForStatement> {
- child<ASTForInit>() // This would fail if the first child is not a ForInit
- child<ASTForUpdate>()
- child<ASTBlock> {
- // test a predicate on the current node
- assertNode("Should have done X", n -> n.getScope().whatever()) // n is an ASTBlock -> typesafe
- val block = getNode() // The current node is available to perform more advanced treatment
- child<ASTStatement>()
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment