texinfo.string-utils.test 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ;;;; texinfo.string-utils.test -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2003, 2009, 2010, 2013 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This program is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU General Public License as
  7. ;;;; published by the Free Software Foundation; either version 3 of the
  8. ;;;; License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This program is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;;; General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU General Public License
  16. ;;;; along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. ;;;; 02110-1301 USA
  19. (define-module (test-suite test-string-utils)
  20. #:use-module (test-suite lib)
  21. #:use-module (texinfo string-utils))
  22. ;; **********************************************************************
  23. ;; Test for expand-tabs
  24. ;; **********************************************************************
  25. (with-test-prefix "test-beginning-expansion"
  26. (pass-if (equal? " Hello"
  27. (expand-tabs "\tHello")))
  28. (pass-if (equal? " Hello"
  29. (expand-tabs "\t\tHello"))))
  30. (with-test-prefix "test-ending-expansion"
  31. (pass-if (equal? "Hello "
  32. (expand-tabs "Hello\t")))
  33. (pass-if (equal? "Hello "
  34. (expand-tabs "Hello\t\t"))))
  35. (with-test-prefix "test-middle-expansion"
  36. (pass-if (equal? "Hello there" (expand-tabs "Hello\tthere")))
  37. (pass-if (equal? "Hello there" (expand-tabs "Hello\t\tthere"))))
  38. (with-test-prefix "test-alternate-tab-size"
  39. (pass-if (equal? "Hello there"
  40. (expand-tabs "Hello\tthere" 3)))
  41. (pass-if (equal? "Hello there"
  42. (expand-tabs "Hello\tthere" 4)))
  43. (pass-if (equal? "Hello there"
  44. (expand-tabs "Hello\tthere" 5))))
  45. ;; **********************************************************************
  46. ;; tests for escape-special-chars
  47. ;; **********************************************************************
  48. (with-test-prefix "test-single-escape-char"
  49. (pass-if (equal? "HeElElo"
  50. (escape-special-chars "Hello" #\l #\E))))
  51. (with-test-prefix "test-multiple-escape-chars"
  52. (pass-if (equal? "HEeElElo"
  53. (escape-special-chars "Hello" "el" #\E))))
  54. ;; **********************************************************************
  55. ;; tests for collapsing-multiple-chars
  56. ;; **********************************************************************
  57. (with-test-prefix "collapse-repeated-chars"
  58. (define test-string
  59. "H e l l o t h e r e")
  60. (with-test-prefix "test-basic-collapse"
  61. (pass-if (equal? "H e l l o t h e r e"
  62. (collapse-repeated-chars test-string))))
  63. (with-test-prefix "test-choose-other-char"
  64. (pass-if (equal? "H-e-l-l-o-t-h-e-r-e"
  65. (collapse-repeated-chars (transform-string test-string #\space #\-)
  66. #\-))))
  67. (with-test-prefix "test-choose-maximum-repeats"
  68. (pass-if (equal? "H e l l o t h e r e"
  69. (collapse-repeated-chars test-string #\space 2)))
  70. (pass-if (equal? "H e l l o t h e r e"
  71. (collapse-repeated-chars test-string #\space 3)))))
  72. ;; **********************************************************************
  73. ;; Test of the object itself...
  74. ;; **********************************************************************
  75. (with-test-prefix "text wrapping"
  76. (define test-string "
  77. The last language environment specified with
  78. `set-language-environment'. This variable should be
  79. set only with M-x customize, which is equivalent
  80. to using the function `set-language-environment'.
  81. ")
  82. (with-test-prefix "runs-without-exception"
  83. (pass-if (->bool (fill-string test-string)))
  84. (pass-if (->bool (fill-string test-string #:line-width 20)))
  85. (pass-if (->bool (fill-string test-string #:initial-indent " * " #:tab-width 3))))
  86. (with-test-prefix "test-fill-equivalent-to-joined-lines"
  87. (pass-if (equal? (fill-string test-string)
  88. (string-join (string->wrapped-lines test-string) "\n" 'infix))))
  89. (with-test-prefix "test-no-collapse-ws"
  90. (pass-if (equal? (fill-string test-string #:collapse-whitespace? #f)
  91. "The last language environment specified with `set-language-environment'. This
  92. variable should be set only with M-x customize, which is equivalent to using
  93. the function `set-language-environment'.")))
  94. (with-test-prefix "two spaces after end of sentence"
  95. (pass-if-equal "This is a sentence. There should be two spaces before."
  96. (fill-string "This is a sentence. There should be two spaces before."))
  97. (pass-if-equal "This is version 2.0..."
  98. (fill-string "This is version 2.0...")))
  99. (with-test-prefix "test-no-word-break"
  100. (pass-if (equal? "thisisalongword
  101. blah
  102. blah"
  103. (fill-string "thisisalongword blah blah"
  104. #:line-width 8
  105. #:break-long-words? #f)))))