tslice.nim 580 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import macros
  2. macro test(): untyped =
  3. result = nnkStmtList.newTree()
  4. let n = nnkStmtList.newTree(
  5. newIdentNode("one"),
  6. newIdentNode("two"),
  7. newIdentNode("three"),
  8. newIdentNode("four"),
  9. newIdentNode("five"),
  10. newIdentNode("six")
  11. )
  12. var i = 1
  13. for x in n[1 .. ^2]:
  14. assert x == n[i]
  15. i.inc
  16. assert i == 5
  17. i = 3
  18. for x in n[3..^1]:
  19. assert x == n[i]
  20. i.inc
  21. assert i == 6
  22. i = 0
  23. for x in n[0..3]:
  24. assert x == n[i]
  25. i.inc
  26. assert i == 4
  27. i = 0
  28. for x in n[0..5]:
  29. assert x == n[i]
  30. i.inc
  31. assert i == 6
  32. test()