tsystem.nim 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. discard """
  2. targets: "c cpp js"
  3. """
  4. import stdtest/testutils
  5. # TODO: in future work move existing `system` tests here, where they belong
  6. template main =
  7. block: # closure
  8. proc outer() =
  9. var a = 0
  10. proc inner1 = a.inc
  11. proc inner2 = discard
  12. doAssert inner1 is "closure"
  13. doAssert inner2 isnot "closure"
  14. doAssert inner1 is (proc)
  15. doAssert inner2 is (proc)
  16. let inner1b = inner1
  17. doAssert inner1b is "closure"
  18. doAssert inner1b == inner1
  19. outer()
  20. block: # rawProc, rawProc, bug #17911
  21. proc outer() =
  22. var a = 0
  23. var b = 0
  24. proc inner1() = a.inc
  25. proc inner2() = a += 2
  26. proc inner3() = b.inc
  27. let inner1b = inner1
  28. doAssert inner2 != inner1
  29. doAssert inner3 != inner1
  30. whenVMorJs: discard
  31. do:
  32. doAssert rawProc(inner1b) == rawProc(inner1)
  33. doAssert rawProc(inner2) != rawProc(inner1)
  34. doAssert rawProc(inner3) != rawProc(inner1)
  35. doAssert rawEnv(inner1b) == rawEnv(inner1)
  36. doAssert rawEnv(inner2) == rawEnv(inner1) # because both use `a`
  37. # doAssert rawEnv(inner3) != rawEnv(inner1) # because `a` vs `b` # this doesn't hold
  38. outer()
  39. block: # system.delete
  40. block:
  41. var s = @[1]
  42. s.delete(0)
  43. doAssert s == @[]
  44. block:
  45. var s = @["foo", "bar"]
  46. s.delete(1)
  47. doAssert s == @["foo"]
  48. when false:
  49. var s: seq[string]
  50. doAssertRaises(IndexDefect):
  51. s.delete(0)
  52. block:
  53. doAssert not compiles(@["foo"].delete(-1))
  54. block: # bug #6710
  55. var s = @["foo"]
  56. s.delete(0)
  57. doAssert s == @[]
  58. when false: # bug #16544: deleting out of bounds index should raise
  59. var s = @["foo"]
  60. doAssertRaises(IndexDefect):
  61. s.delete(1)
  62. static: main()
  63. main()