twordwrap.nim 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. discard """
  2. matrix: "--mm:refc; --mm:orc"
  3. """
  4. import std/wordwrap
  5. import std/assertions
  6. when true:
  7. let
  8. inp = """ this is a long text -- muchlongerthan10chars and here
  9. it goes"""
  10. outp = " this is a\nlong text\n--\nmuchlongerthan10chars\nand here\nit goes"
  11. doAssert wrapWords(inp, 10, false) == outp
  12. let
  13. longInp = """ThisIsOneVeryLongStringWhichWeWillSplitIntoEightSeparatePartsNow"""
  14. longOutp = "ThisIsOn\neVeryLon\ngStringW\nhichWeWi\nllSplitI\nntoEight\nSeparate\nPartsNow"
  15. doAssert wrapWords(longInp, 8, true) == longOutp
  16. # test we don't break Umlauts into invalid bytes:
  17. let fies = "äöüöäöüöäöüöäöüööäöüöäößßßßüöäößßßßßß"
  18. let fiesRes = "ä\nö\nü\nö\nä\nö\nü\nö\nä\nö\nü\nö\nä\nö\nü\nö\nö\nä\nö\nü\nö\nä\nö\nß\nß\nß\nß\nü\nö\nä\nö\nß\nß\nß\nß\nß\nß"
  19. doAssert wrapWords(fies, 1, true) == fiesRes
  20. let longlongword = """abc uitdaeröägfßhydüäpydqfü,träpydqgpmüdträpydföägpydörztdüöäfguiaeowäzjdtrüöäp psnrtuiydrözenrüöäpyfdqazpesnrtulocjtüö
  21. äzydgyqgfqfgprtnwjlcydkqgfüöezmäzydydqüüöäpdtrnvwfhgckdumböäpydfgtdgfhtdrntdrntydfogiayqfguiatrnydrntüöärtniaoeydfgaoeiqfglwcßqfgxvlcwgtfhiaoen
  22. rsüöäapmböäptdrniaoydfglckqfhouenrtsüöäptrniaoeyqfgulocfqclgwxßqflgcwßqfxglcwrniatrnmüböäpmöäbpümöäbpüöämpbaoestnriaesnrtdiaesrtdniaesdrtnaetdr
  23. iaoenvlcyfglwckßqfgvwkßqgfvlwkßqfgvlwckßqvlwkgfUIαοιαοιαχολωχσωχνωκψρχκψρτιεαοσηζϵηζιοεννκεωνιαλωσωκνκψρκγτφγτχκγτεκργτιχνκιωχσιλωσλωχξλξλξωχωχ
  24. ξχλωωχαοεοιαεοαεοιαεοαεοιαοεσναοεκνρκψγκψφϵιηαααοε"""
  25. let longlongwordRes = """
  26. abc uitdaeröägfßhydüäpydqfü,träpydqgpmüdträpydföägpydörztdüöäfguiaeowäzjdtrüöäp
  27. psnrtuiydrözenrüöäpyfdqazpesnrtulocjtüöäzydgyqgfqfgprtnwjlcydkqgfüöezmäzydydqüü
  28. öäpdtrnvwfhgckdumböäpydfgtdgfhtdrntdrntydfogiayqfguiatrnydrntüöärtniaoeydfgaoeiq
  29. fglwcßqfgxvlcwgtfhiaoenrsüöäapmböäptdrniaoydfglckqfhouenrtsüöäptrniaoeyqfgulocf
  30. qclgwxßqflgcwßqfxglcwrniatrnmüböäpmöäbpümöäbpüöämpbaoestnriaesnrtdiaesrtdniaesdr
  31. tnaetdriaoenvlcyfglwckßqfgvwkßqgfvlwkßqfgvlwckßqvlwkgfUIαοιαοιαχολωχσωχνωκψρχκψ
  32. ρτιεαοσηζϵηζιοεννκεωνιαλωσωκνκψρκγτφγτχκγτεκργτιχνκιωχσιλωσλωχξλξλξωχωχ
  33. ξχλωωχαοεοιαεοαεοιαεοαεοιαοεσναοεκνρκψγκψφϵιηαααοε"""
  34. doAssert wrapWords(longlongword) == longlongwordRes
  35. # bug #14579
  36. const input60 = """
  37. This string is wrapped to 60 characters. If we call
  38. wrapwords on it it will be re-wrapped to 80 characters.
  39. """
  40. const input60Res = """This string is wrapped to 60 characters. If we call wrapwords on it it will be
  41. re-wrapped to 80 characters."""
  42. doAssert wrapWords(input60) == input60Res