tropes.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import ropes
  2. block:
  3. let r: Rope = nil
  4. doAssert r[0] == '\0'
  5. block:
  6. var
  7. r1 = rope("Hello")
  8. r2 = rope("Nim-Lang")
  9. let r = r1 & r2
  10. let s = $r
  11. for i in 0 ..< r.len:
  12. doAssert r[i] == s[i]
  13. doAssert r[66] == '\0'
  14. block:
  15. let r = rope("Hello, Nim-Lang")
  16. let s = $r
  17. for i in 0 ..< r.len:
  18. doAssert r[i] == s[i]
  19. doAssert r[66] == '\0'
  20. block:
  21. var r: Rope
  22. r.add rope("Nim ")
  23. r.add rope("is ")
  24. r.add rope("a ")
  25. r.add rope("great ")
  26. r.add rope("language")
  27. let s = $r
  28. for i in 0 ..< r.len:
  29. doAssert r[i] == s[i]
  30. doAssert r[66] == '\0'
  31. block:
  32. var r: Rope
  33. r.add rope("My Conquest")
  34. r.add rope(" is ")
  35. r.add rope("the Sea of Stars")
  36. let s = $r
  37. for i in 0 ..< r.len:
  38. doAssert r[i] == s[i]
  39. doAssert r[66] == '\0'
  40. block:
  41. var r: Rope
  42. r.add rope("My Conquest")
  43. r.add rope(" is ")
  44. r.add rope("the Sea of Stars")
  45. var i: int
  46. for item in r:
  47. doAssert r[i] == item
  48. inc i
  49. doAssert r[66] == '\0'
  50. block:
  51. let r1 = "$1 $2 $3" % [rope("Nim"), rope("is"), rope("a great language")]
  52. doAssert $r1 == "Nim is a great language"
  53. let r2 = "$# $# $#" % [rope("Nim"), rope("is"), rope("a great language")]
  54. doAssert $r2 == "Nim is a great language"