tcomparisons.nim 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. discard """
  2. targets: "c cpp js"
  3. """
  4. template main =
  5. block: # proc equality
  6. var prc: proc(): int {.closure.}
  7. prc = nil
  8. doAssert prc == nil
  9. doAssert prc.isNil
  10. prc = proc(): int =
  11. result = 123
  12. doAssert prc != nil
  13. doAssert not prc.isNil
  14. doAssert prc == prc
  15. let prc2 = prc
  16. doAssert prc == prc2
  17. doAssert prc2 != nil
  18. doAssert not prc2.isNil
  19. doAssert not prc.isNil
  20. prc = proc(): int =
  21. result = 456
  22. doAssert prc != nil
  23. doAssert not prc.isNil
  24. doAssert prc != prc2
  25. block: # iterator equality
  26. when nimvm: discard # vm does not support closure iterators
  27. else:
  28. when not defined(js): # js also does not support closure iterators
  29. var iter: iterator(): int {.closure.}
  30. iter = nil
  31. doAssert iter == nil
  32. doAssert iter.isNil
  33. iter = iterator(): int =
  34. yield 123
  35. doAssert iter != nil
  36. doAssert not iter.isNil
  37. doAssert iter == iter
  38. let iter2 = iter
  39. doAssert iter == iter2
  40. doAssert iter2 != nil
  41. doAssert not iter2.isNil
  42. doAssert not iter.isNil
  43. iter = iterator(): int =
  44. yield 456
  45. doAssert iter != nil
  46. doAssert not iter.isNil
  47. doAssert iter != iter2
  48. static: main()
  49. main()