tnodecompare.nim 866 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import macros
  2. static:
  3. let nodeA = newCommentStmtNode("this is a comment")
  4. doAssert nodeA.repr == "## this is a comment"
  5. doAssert nodeA.strVal == "this is a comment"
  6. doAssert $nodeA == "this is a comment"
  7. let nodeB = newCommentStmtNode("this is a comment")
  8. doAssert nodeA == nodeB
  9. nodeB.strVal = "this is a different comment"
  10. doAssert nodeA != nodeB
  11. macro test(a: typed, b: typed): untyped =
  12. newLit(a == b)
  13. doAssert test(1, 1) == true
  14. doAssert test(1, 2) == false
  15. type
  16. Obj = object of RootObj
  17. Other = object of RootObj
  18. doAssert test(Obj, Obj) == true
  19. doAssert test(Obj, Other) == false
  20. var a, b: int
  21. doAssert test(a, a) == true
  22. doAssert test(a, b) == false
  23. macro test2: untyped =
  24. newLit(bindSym"Obj" == bindSym"Obj")
  25. macro test3: untyped =
  26. newLit(bindSym"Obj" == bindSym"Other")
  27. doAssert test2() == true
  28. doAssert test3() == false