trepr.nim 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. discard """
  2. cmd: "nim c --gc:arc $file"
  3. nimout: '''(a: true, n: doAssert)
  4. Table[system.string, trepr.MyType](data: @[], counter: 0)
  5. nil
  6. '''
  7. output: '''
  8. nil
  9. 2
  10. Obj(member: ref @["hello"])
  11. ref (member: ref @["hello"])
  12. ObjUa(v: 0, a: [...])
  13. '''
  14. """
  15. # xxx consider merging with `tests/stdlib/trepr.nim` to increase overall test coverage
  16. import tables
  17. type
  18. NimSym = distinct NimNode
  19. MyType = tuple
  20. a: bool
  21. n: NimSym
  22. proc myproc(t: MyType) =
  23. echo repr(t)
  24. proc myproc2(t: MyType) =
  25. var x = Table[string, t]()
  26. echo repr(x)
  27. proc myproc3(t: MyType) =
  28. var x: TableRef[string, t]
  29. echo repr(x)
  30. macro dumpSym(a: typed) =
  31. myproc((a: true, n: NimSym(a)))
  32. myproc2((a: true, n: NimSym(a)))
  33. myproc3((a: true, n: NimSym(a)))
  34. dumpSym(doAssert)
  35. # bug 13731
  36. import os
  37. var a: File
  38. echo repr a
  39. # bug 13872
  40. echo repr(2'u16)
  41. # bug 14270
  42. type
  43. Obj = ref object
  44. member: ref seq[string]
  45. var c = Obj(member: new seq[string])
  46. c.member[] = @["hello"]
  47. echo c.repr
  48. var c2 = new tuple[member: ref seq[string]]
  49. c2.member = new seq[string]
  50. c2.member[] = @["hello"]
  51. echo c2.repr
  52. proc p2 =
  53. echo "hey"
  54. discard repr p2
  55. #####################################################################
  56. # bug #15043
  57. import macros
  58. macro extract(): untyped =
  59. result = newStmtList()
  60. var x: seq[tuple[node: NimNode]]
  61. proc test(n: NimNode) {.closure.} =
  62. x.add (node: n)
  63. test(parseExpr("discard"))
  64. extract()
  65. type
  66. ObjUa = ref object
  67. v: int
  68. a: UncheckedArray[char]
  69. echo ObjUa().repr