tobject.nim 780 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. discard """
  2. output: "[Suite] object basic methods"
  3. """
  4. import unittest
  5. type Obj = object
  6. foo: int
  7. proc makeObj(x: int): Obj =
  8. result.foo = x
  9. suite "object basic methods":
  10. test "it should convert an object to a string":
  11. var obj = makeObj(1)
  12. # Should be "obj: (foo: 1)" or similar.
  13. check($obj == "(foo: 1)")
  14. test "it should test equality based on fields":
  15. check(makeObj(1) == makeObj(1))
  16. # bug #10203
  17. type
  18. TMyObj = TYourObj
  19. TYourObj = object of RootObj
  20. x, y: int
  21. proc init: TYourObj =
  22. result.x = 0
  23. result.y = -1
  24. proc f(x: var TYourObj) =
  25. discard
  26. var m: TMyObj = init()
  27. f(m)
  28. var a: TYourObj = m
  29. var b: TMyObj = a
  30. # bug #10195
  31. type
  32. InheritableFoo {.inheritable.} = ref object
  33. InheritableBar = ref object of InheritableFoo # ERROR.