trepr.nim 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. discard """
  2. targets: "c cpp js"
  3. matrix: ";--gc:arc"
  4. """
  5. # if excessive, could remove 'cpp' from targets
  6. from strutils import endsWith, contains
  7. template main() =
  8. doAssert repr({3,5}) == "{3, 5}"
  9. block:
  10. type TEnum = enum a, b
  11. var val = {a, b}
  12. when nimvm:
  13. discard
  14. #[
  15. # BUG:
  16. {0, 1}
  17. {97..99, 65..67}
  18. ]#
  19. else:
  20. doAssert repr(val) == "{a, b}"
  21. doAssert repr({'a'..'c', 'A'..'C'}) == "{'A', 'B', 'C', 'a', 'b', 'c'}"
  22. type
  23. TObj {.pure, inheritable.} = object
  24. data: int
  25. TFoo = ref object of TObj
  26. d2: float
  27. var foo: TFoo
  28. new(foo)
  29. #[
  30. BUG:
  31. --gc:arc returns `"abc"`
  32. regular gc returns with address, e.g. 0x1068aae60"abc", but only
  33. for c,cpp backends (not js, vm)
  34. ]#
  35. block:
  36. doAssert repr("abc").endsWith "\"abc\""
  37. var b: cstring = "def"
  38. doAssert repr(b).endsWith "\"def\""
  39. block:
  40. var c = @[1,2]
  41. when nimvm:
  42. discard # BUG: this shows [1, 2] instead of @[1, 2]
  43. else:
  44. # BUG (already mentioned above): some backends / gc show address, others don't
  45. doAssert repr(c).endsWith "@[1, 2]"
  46. let d = @["foo", "bar"]
  47. let s = repr(d)
  48. # depending on backend/gc, we get 0x106a1c350@[0x106a1c390"foo", 0x106a1c3c0"bar"]
  49. doAssert "\"foo\"," in s
  50. var arr = [1, 2, 3]
  51. doAssert repr(arr) == "[1, 2, 3]"
  52. block: # bug #7878
  53. proc reprOpenarray(variable: var openarray[int]): string = repr(variable)
  54. when defined(js): discard # BUG: doesn't work
  55. else:
  56. doAssert reprOpenarray(arr) == "[1, 2, 3]"
  57. static: main()
  58. main()