tseq_badinit.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. type
  2. AObj = object
  3. i: int
  4. d: float
  5. ATup = tuple
  6. i: int
  7. d: float
  8. MyEnum = enum
  9. E01, E02, E03
  10. Myrange = range[0..10]
  11. MyProc = proc (x: int): bool
  12. MyInt = distinct int
  13. MyAlias = MyInt
  14. MySet = set[char]
  15. MyArray = array[4, char]
  16. MySeq = seq[string]
  17. template test(typename, default: untyped) =
  18. proc `abc typename`(): seq[typename] =
  19. result = newSeq[typename]()
  20. result.add(default)
  21. result.setLen(3)
  22. for i in 0 ..< 2:
  23. result[i] = default
  24. const constval = `abc typename`()
  25. doAssert(constval == `abc typename`())
  26. proc `arr typename`(): array[4, typename] =
  27. for i in 0 ..< 2:
  28. result[i] = default
  29. const constarr = `arr typename`()
  30. doAssert(constarr == `arr typename`())
  31. proc even(x: int): bool = x mod 2 == 0
  32. proc `==`(x, y: MyInt): bool = ord(x) == ord(y)
  33. proc `$`(x: MyInt): string = $ord(x)
  34. proc `$`(x: proc): string =
  35. if x.isNil: "(nil)" else: "funcptr"
  36. test(int, 0)
  37. test(uint, 0)
  38. test(float, 0.1)
  39. test(char, '0')
  40. test(bool, false)
  41. test(uint8, 2)
  42. test(string, "data")
  43. test(MyProc, even)
  44. test(MyEnum, E02)
  45. test(AObj, AObj())
  46. test(ATup, (i:11, d:9.99))
  47. test(Myrange, 4)
  48. test(MyInt, MyInt(4))
  49. test(MyAlias, MyAlias(4))
  50. test(MyArray, ['0','1','2','3'])
  51. test(MySeq, @["data"])