tisolation.nim 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. discard """
  2. targets: "c cpp"
  3. matrix: "--gc:refc; --gc:orc"
  4. """
  5. import std/[isolation, json]
  6. proc main(moveZeroesOut: static bool) =
  7. block:
  8. type
  9. Empty = ref object
  10. var x = isolate(Empty())
  11. discard extract(x)
  12. block: # string literals
  13. var data = isolate("string")
  14. doAssert data.extract == "string"
  15. if moveZeroesOut:
  16. doAssert data.extract == ""
  17. block: # string literals
  18. var data = isolate("")
  19. doAssert data.extract == ""
  20. if moveZeroesOut:
  21. doAssert data.extract == ""
  22. block:
  23. var src = "string"
  24. var data = isolate(move src)
  25. doAssert data.extract == "string"
  26. if moveZeroesOut:
  27. doAssert src.len == 0
  28. block: # int literals
  29. var data = isolate(1)
  30. doAssert data.extract == 1
  31. if moveZeroesOut:
  32. doAssert data.extract == 0
  33. block: # float literals
  34. var data = isolate(1.6)
  35. doAssert data.extract == 1.6
  36. if moveZeroesOut:
  37. doAssert data.extract == 0.0
  38. block:
  39. var data = isolate(@["1", "2"])
  40. doAssert data.extract == @["1", "2"]
  41. if moveZeroesOut:
  42. doAssert data.extract == @[]
  43. block:
  44. var data = isolate(@["1", "2", "3", "4", "5"])
  45. doAssert data.extract == @["1", "2", "3", "4", "5"]
  46. if moveZeroesOut:
  47. doAssert data.extract == @[]
  48. block:
  49. var data = isolate(@["", ""])
  50. doAssert data.extract == @["", ""]
  51. if moveZeroesOut:
  52. doAssert data.extract == @[]
  53. block:
  54. var src = @["1", "2"]
  55. var data = isolate(move src)
  56. doAssert data.extract == @["1", "2"]
  57. if moveZeroesOut:
  58. doAssert src.len == 0
  59. block:
  60. var data = isolate(@[1, 2])
  61. doAssert data.extract == @[1, 2]
  62. if moveZeroesOut:
  63. doAssert data.extract == @[]
  64. block:
  65. var data = isolate(["1", "2"])
  66. doAssert data.extract == ["1", "2"]
  67. if moveZeroesOut:
  68. doAssert data.extract == ["", ""]
  69. block:
  70. var data = isolate([1, 2])
  71. doAssert data.extract == [1, 2]
  72. if moveZeroesOut:
  73. doAssert data.extract == [0, 0]
  74. block:
  75. type
  76. Test = object
  77. id: int
  78. var data = isolate(Test(id: 12))
  79. doAssert data.extract.id == 12
  80. block:
  81. type
  82. Test = object
  83. id: int
  84. var src = Test(id: 12)
  85. var data = isolate(src)
  86. doAssert data.extract.id == 12
  87. block:
  88. type
  89. Test = object
  90. id: int
  91. var src = Test(id: 12)
  92. var data = isolate(move src)
  93. doAssert data.extract.id == 12
  94. block:
  95. type
  96. Test = ref object
  97. id: int
  98. var data = isolate(Test(id: 12))
  99. doAssert data.extract.id == 12
  100. block:
  101. var x: seq[Isolated[JsonNode]]
  102. x.add isolate(newJString("1234"))
  103. doAssert $x == """@[(value: "1234")]"""
  104. static: main(moveZeroesOut = false)
  105. main(moveZeroesOut = true)