Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. fun test() {
  2.  
  3. // Raw strings are much nicer to read and maintain
  4. val scrutinee = parseStatement("""
  5. for (int i = 0;; i++) {
  6. blazour(i);
  7. }
  8. """)
  9.  
  10. // match an AST subtree deeply
  11. scrutinee assertMatches node<ASTStatement> {
  12.  
  13. // The node and child functions define matchers
  14. // The block can contain matchers for the children of the scrutinised node
  15. // If a node is not of the correct type, this can be reported with a nice error message (transparently to the test code)
  16.  
  17. child<ASTForStatement> {
  18.  
  19. child<ASTForInit>() // This would fail if the first child is not a ForInit
  20. child<ASTForUpdate>()
  21.  
  22. child<ASTBlock> {
  23. // test a predicate on the current node
  24. assertNode("Should have done X", n -> n.getScope().whatever()) // n is an ASTBlock -> typesafe
  25.  
  26. val block = getNode() // The current node is available to perform more advanced treatment
  27.  
  28. child<ASTStatement>()
  29. }
  30. }
  31. }
  32. }
Add Comment
Please, Sign In to add comment