tstrutils2.nim 601 B

123456789101112131415161718192021222324252627282930313233
  1. import "$lib/.." / compiler/strutils2
  2. block: # setLen
  3. var a = "abc"
  4. a.setLen 0
  5. a.setLen 3, isInit = false
  6. doAssert a[1] == 'b'
  7. a.setLen 0
  8. a.setLen 3, isInit = true
  9. doAssert a[1] == '\0'
  10. block: # forceCopy
  11. var a: string
  12. a = "foo"
  13. shallow(a)
  14. var b: string
  15. b = a
  16. doAssert b[0].addr == a[0].addr
  17. var c: string
  18. c.forceCopy a
  19. doAssert c == a
  20. doAssert c[0].addr != a[0].addr
  21. block: # toLowerAscii
  22. var a = "fooBAr"
  23. a.toLowerAscii
  24. doAssert a == "foobar"
  25. block: # dataPointer
  26. var a: string
  27. discard a.dataPointer
  28. # doAssert a.dataPointer == nil # not guaranteed