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