trepr.nim 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. '''
  13. """
  14. # xxx consider merging with `tests/stdlib/trepr.nim` to increase overall test coverage
  15. import tables
  16. type
  17. NimSym = distinct NimNode
  18. MyType = tuple
  19. a: bool
  20. n: NimSym
  21. proc myproc(t: MyType) =
  22. echo repr(t)
  23. proc myproc2(t: MyType) =
  24. var x = Table[string, t]()
  25. echo repr(x)
  26. proc myproc3(t: MyType) =
  27. var x: TableRef[string, t]
  28. echo repr(x)
  29. macro dumpSym(a: typed) =
  30. myproc((a: true, n: NimSym(a)))
  31. myproc2((a: true, n: NimSym(a)))
  32. myproc3((a: true, n: NimSym(a)))
  33. dumpSym(doAssert)
  34. # bug 13731
  35. import os
  36. var a: File
  37. echo repr a
  38. # bug 13872
  39. echo repr(2'u16)
  40. # bug 14270
  41. type
  42. Obj = ref object
  43. member: ref seq[string]
  44. var c = Obj(member: new seq[string])
  45. c.member[] = @["hello"]
  46. echo c.repr
  47. var c2 = new tuple[member: ref seq[string]]
  48. c2.member = new seq[string]
  49. c2.member[] = @["hello"]
  50. echo c2.repr
  51. proc p2 =
  52. echo "hey"
  53. discard repr p2
  54. #####################################################################
  55. # bug #15043
  56. import macros
  57. macro extract(): untyped =
  58. result = newStmtList()
  59. var x: seq[tuple[node: NimNode]]
  60. proc test(n: NimNode) {.closure.} =
  61. x.add (node: n)
  62. test(parseExpr("discard"))
  63. extract()