topenarray.nim 899 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. discard """
  2. input: "hi"
  3. output: '''
  4. hi
  5. Nim
  6. '''
  7. matrix: "--gc:arc -d:useMalloc; --gc:arc"
  8. """
  9. {.experimental: "views".}
  10. block: # bug 18627
  11. proc setPosition(params: openArray[string]) =
  12. for i in params.toOpenArray(0, params.len - 1):
  13. echo i
  14. proc uciLoop() =
  15. let params = @[readLine(stdin)]
  16. setPosition(params)
  17. uciLoop()
  18. proc uciLoop2() =
  19. let params = @["Nim"]
  20. for i in params.toOpenArray(0, params.len - 1):
  21. echo i
  22. uciLoop2()
  23. when defined(nimPreviewSlimSystem):
  24. import std/assertions
  25. block: # bug #20954
  26. block:
  27. doAssertRaises(IndexDefect):
  28. var v: array[10, int]
  29. echo len(toOpenArray(v, 20, 30))
  30. block:
  31. doAssertRaises(IndexDefect):
  32. var v: seq[int]
  33. echo len(toOpenArray(v, 20, 30))
  34. # bug #20422
  35. proc f(a: var string) =
  36. var v = a.toOpenArray(1, 3)
  37. v[0] = 'a'
  38. var a = "Hello"
  39. f(a)
  40. doAssert a == "Hallo"