test.nim 422 B

1234567891011121314151617181920212223242526272829
  1. import unittest
  2. import impl
  3. type T = object
  4. a: int
  5. impl T:
  6. proc new {.ctor.} =
  7. this.a = 10
  8. proc new*(a: int) {.ctor.} =
  9. this.a = a
  10. proc sqr: int = this.a * this.a
  11. proc mul(x: int): int = this.a * x
  12. proc mulBy*(x: int) {.mut.} =
  13. this.a *= x
  14. test "impl and ctor":
  15. check T.new.sqr == 100
  16. check T.new(3).mul(4) == 12
  17. var x: T
  18. new x
  19. check x.a == 10
  20. x.mulBy(3)
  21. check x.a == 30