| 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 |
|
| 20 |
(define-module (test-suite test-string-utils) |
| 21 |
#:use-module (test-suite lib) |
| 22 |
#:use-module (texinfo string-utils)) |
| 23 |
|
| 24 |
|
| 25 |
;; ********************************************************************** |
| 26 |
;; Test for expand-tabs |
| 27 |
;; ********************************************************************** |
| 28 |
(with-test-prefix "test-beginning-expansion" |
| 29 |
(pass-if (equal? " Hello" |
| 30 |
(expand-tabs "\tHello"))) |
| 31 |
(pass-if (equal? " Hello" |
| 32 |
(expand-tabs "\t\tHello")))) |
| 33 |
|
| 34 |
(with-test-prefix "test-ending-expansion" |
| 35 |
(pass-if (equal? "Hello " |
| 36 |
(expand-tabs "Hello\t"))) |
| 37 |
(pass-if (equal? "Hello " |
| 38 |
(expand-tabs "Hello\t\t")))) |
| 39 |
|
| 40 |
(with-test-prefix "test-middle-expansion" |
| 41 |
(pass-if (equal? "Hello there" (expand-tabs "Hello\tthere"))) |
| 42 |
(pass-if (equal? "Hello there" (expand-tabs "Hello\t\tthere")))) |
| 43 |
|
| 44 |
(with-test-prefix "test-alternate-tab-size" |
| 45 |
(pass-if (equal? "Hello there" |
| 46 |
(expand-tabs "Hello\tthere" 3))) |
| 47 |
(pass-if (equal? "Hello there" |
| 48 |
(expand-tabs "Hello\tthere" 4))) |
| 49 |
(pass-if (equal? "Hello there" |
| 50 |
(expand-tabs "Hello\tthere" 5)))) |
| 51 |
|
| 52 |
;; ********************************************************************** |
| 53 |
;; tests for escape-special-chars |
| 54 |
;; ********************************************************************** |
| 55 |
(with-test-prefix "test-single-escape-char" |
| 56 |
(pass-if (equal? "HeElElo" |
| 57 |
(escape-special-chars "Hello" #\l #\E)))) |
| 58 |
|
| 59 |
(with-test-prefix "test-multiple-escape-chars" |
| 60 |
(pass-if (equal? "HEeElElo" |
| 61 |
(escape-special-chars "Hello" "el" #\E)))) |
| 62 |
|
| 63 |
|
| 64 |
;; ********************************************************************** |
| 65 |
;; tests for collapsing-multiple-chars |
| 66 |
;; ********************************************************************** |
| 67 |
(with-test-prefix "collapse-repeated-chars" |
| 68 |
(define test-string |
| 69 |
"H e l l o t h e r e") |
| 70 |
|
| 71 |
(with-test-prefix "test-basic-collapse" |
| 72 |
(pass-if (equal? "H e l l o t h e r e" |
| 73 |
(collapse-repeated-chars test-string)))) |
| 74 |
|
| 75 |
(with-test-prefix "test-choose-other-char" |
| 76 |
(pass-if (equal? "H-e-l-l-o-t-h-e-r-e" |
| 77 |
(collapse-repeated-chars (transform-string test-string #\space #\-) |
| 78 |
#\-)))) |
| 79 |
|
| 80 |
(with-test-prefix "test-choose-maximum-repeats" |
| 81 |
(pass-if (equal? "H e l l o t h e r e" |
| 82 |
(collapse-repeated-chars test-string #\space 2))) |
| 83 |
(pass-if (equal? "H e l l o t h e r e" |
| 84 |
(collapse-repeated-chars test-string #\space 3))))) |
| 85 |
|
| 86 |
;; ********************************************************************** |
| 87 |
;; Test of the object itself... |
| 88 |
;; ********************************************************************** |
| 89 |
(with-test-prefix "text wrapping" |
| 90 |
(define test-string " |
| 91 |
The last language environment specified with |
| 92 |
`set-language-environment'. This variable should be |
| 93 |
set only with M-x customize, which is equivalent |
| 94 |
to using the function `set-language-environment'. |
| 95 |
") |
| 96 |
|
| 97 |
(with-test-prefix "runs-without-exception" |
| 98 |
(pass-if (->bool (fill-string test-string))) |
| 99 |
(pass-if (->bool (fill-string test-string #:line-width 20))) |
| 100 |
(pass-if (->bool (fill-string test-string #:initial-indent " * " #:tab-width 3)))) |
| 101 |
|
| 102 |
(with-test-prefix "test-fill-equivalent-to-joined-lines" |
| 103 |
(pass-if (equal? (fill-string test-string) |
| 104 |
(string-join (string->wrapped-lines test-string) "\n" 'infix)))) |
| 105 |
|
| 106 |
(with-test-prefix "test-no-collapse-ws" |
| 107 |
(pass-if (equal? (fill-string test-string #:collapse-whitespace? #f) |
| 108 |
"The last language environment specified with `set-language-environment'. This |
| 109 |
variable should be set only with M-x customize, which is equivalent to using |
| 110 |
the function `set-language-environment'."))) |
| 111 |
|
| 112 |
(with-test-prefix "two spaces after end of sentence" |
| 113 |
(pass-if-equal "This is a sentence. There should be two spaces before." |
| 114 |
(fill-string "This is a sentence. There should be two spaces before.")) |
| 115 |
|
| 116 |
(pass-if-equal "This is version 2.0..." |
| 117 |
(fill-string "This is version 2.0..."))) |
| 118 |
|
| 119 |
(with-test-prefix "test-no-word-break" |
| 120 |
(pass-if (equal? "thisisalongword |
| 121 |
blah |
| 122 |
blah" |
| 123 |
(fill-string "thisisalongword blah blah" |
| 124 |
#:line-width 8 |
| 125 |
#:break-long-words? #f))))) |