1# -*- tcl -*-
2# textutil.test:  tests for the textutil package.
3#
4# This file contains a collection of tests for one or more of the Tcl
5# built-in commands.  Sourcing this file into Tcl runs the tests and
6# generates output for errors.  No output means no errors were found.
7#
8
9# -------------------------------------------------------------------------
10
11source [file join \
12	[file dirname [file dirname [file join [pwd] [info script]]]] \
13	devtools testutilities.tcl]
14
15testsNeedTcl     8.5
16testsNeedTcltest 2.0
17
18support {
19    useLocal     string.tcl   textutil::string
20    useLocal     repeat.tcl   textutil::repeat
21    useLocal     adjust.tcl   textutil::adjust
22    useLocal     split.tcl    textutil::split
23    useLocal     tabify.tcl   textutil::tabify
24    useLocal     trim.tcl     textutil::trim
25    useLocal     trim.tcl     textutil::trim
26    useLocal     wcswidth.tcl textutil::wcswidth
27}
28testing {
29    useLocalKeep textutil.tcl textutil
30}
31
32# -------------------------------------------------------------------------
33
34test textutil-1.0 {blank -1} {
35    textutil::blank -1
36} {}
37
38test textutil-1.1 {blank 0} {
39    textutil::blank 0
40} {}
41
42test textutil-1.2 {blank 1} {
43    textutil::blank 1
44} { }
45
46test textutil-1.3 {blank 10} {
47    textutil::blank 10
48} {          }
49
50
51
52test textutil-2.0 {chop empty} {
53    textutil::chop {}
54} {}
55
56test textutil-2.1 {chop single} {
57    textutil::chop { }
58} {}
59
60test textutil-2.2 {chop long} {
61    textutil::chop {abcde}
62} {abcd}
63
64
65
66test textutil-3.0 {tail empty} {
67    textutil::tail {}
68} {}
69
70test textutil-3.1 {tail single} {
71    textutil::tail { }
72} {}
73
74test textutil-3.2 {tail long} {
75    textutil::tail {abcde}
76} {bcde}
77
78
79
80test textutil-4.0 {cap empty} {
81    textutil::cap {}
82} {}
83
84test textutil-4.1 {cap single} {
85    textutil::cap {a}
86} {A}
87
88test textutil-4.2 {cap long} {
89    textutil::cap {abcde}
90} {Abcde}
91
92test textutil-4.3 {cap capped} {
93    textutil::cap {Abcde}
94} {Abcde}
95
96
97
98test textutil-5.0 {uncap empty} {
99    textutil::uncap {}
100} {}
101
102test textutil-5.1 {uncap single} {
103    textutil::uncap {A}
104} {a}
105
106test textutil-5.2 {uncap long} {
107    textutil::uncap {Abcde}
108} {abcde}
109
110test textutil-5.3 {uncap uncapped} {
111    textutil::uncap {abcde}
112} {abcde}
113
114
115
116test textutil-6.0 {lcs, no strings} {
117    textutil::longestCommonPrefixList {}
118} {}
119
120test textutil-6.1 {lcs, one string} {
121    textutil::longestCommonPrefixList {foo}
122} {foo}
123
124test textutil-6.2 {lcs, two strings, no prefix} {
125    textutil::longestCommonPrefixList {foo bar}
126} {}
127
128test textutil-6.3 {lcs, two strings, small prefix} {
129    textutil::longestCommonPrefixList {foo fbar}
130} {f}
131
132test textutil-6.4 {lcs, two strings, common} {
133    textutil::longestCommonPrefixList {foo foo}
134} {foo}
135
136test textutil-6.5 {lcs, multiple strings} {
137    textutil::longestCommonPrefixList {foo fox fubar}
138} {f}
139
140# -------------------------------------------------------------------------
141
142test textutil-7.0 {capEachWord, wrong args, not enough} -body {
143    textutil::capEachWord
144} -returnCodes error -result {wrong # args: should be "textutil::capEachWord sentence"}
145
146test textutil-7.1 {capEachWord, wrong args, too many} -body {
147    textutil::capEachWord S X
148} -returnCodes error -result {wrong # args: should be "textutil::capEachWord sentence"}
149
150test textutil-7.2 {capEachWord, empty} -body {
151    textutil::capEachWord {}
152} -result {}
153
154test textutil-7.3 {capEachWord, single word} -body {
155    textutil::capEachWord alpha
156} -result Alpha
157
158test textutil-7.4 {capEachWord, multiple words} -body {
159    textutil::capEachWord {here comes the sun}
160} -result {Here Comes The Sun}
161
162test textutil-7.5 {capEachWord, blocks} -body {
163    textutil::capEachWord {here \comes the $sun}
164} -result {Here \comes The $sun}
165
166# -------------------------------------------------------------------------
167
168test textutil-8.0 {wcswidth} -body {
169   textutil::wcswidth {The Quick Brown Fox}
170} -result 19
171
172test textutil-8.1 {wcswidth} -body {
173   textutil::wcswidth {道德經}
174} -result 6
175
176test textutil-8.2 {wcswidth} -body {
177   textutil::wcswidth {道德經 of the fox}
178} -result 17
179# -------------------------------------------------------------------------
180testsuiteCleanup
181return
182