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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# -*- tcl -*-
# tabify.test: tests for the tabify sub-package of the textutil package.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# -------------------------------------------------------------------------
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.2
testsNeedTcltest 1.0
support {
useLocal repeat.tcl textutil::repeat
}
testing {
useLocal tabify.tcl textutil::tabify
}
# -------------------------------------------------------------------------
test tabify-0.1 {tabify string} {
::textutil::tabify::tabify " hello, world "
} "\thello,\tworld\t"
test tabify-0.2 {tabify string with 4 chars} {
::textutil::tabify::tabify " hello, world " 4
} "\t\thello,\t\tworld\t\t"
test tabify-0.3 {tabify string with 5 chars} {
::textutil::tabify::tabify " hello, world " 5
} "\t hello,\t world\t "
test tabify-1.1 {untabify string} {
::textutil::tabify::untabify "\thello,\tworld\t"
} " hello, world "
test tabify-1.2 {untabify string with 4 chars} {
::textutil::tabify::untabify "\t\thello,\t\tworld\t\t" 4
} " hello, world "
test tabify-1.3 {untabify string with 5 chars} {
::textutil::tabify::untabify "\t hello,\t world\t " 5
} " hello, world "
#
# Tests for version 2 of (un)tabify
#
#
# tests 2.1 - 2.3: see how a single space (after 'hello') is not converted
# to a tab
#
test tabify-2.1 {version 2: tabify, tab size 3} {
::textutil::tabify::tabify2 "hello world" 3
# ---|||---|||--
} "hello \tworld"
test tabify-2.2 {version 2: tabify, tab size 3, more spaces than needed} {
::textutil::tabify::tabify2 "hello world" 3
} "hello \t world"
test tabify-2.3 {version 2: tabify, tab size 3, less spaces than needed} {
::textutil::tabify::tabify2 "hello world" 3
} "hello world"
test tabify-2.4 {version 2: tabify, tab size 8} {
::textutil::tabify::tabify2 "hello world"
} "hello\tworld"
test tabify-2.5 {version 2: tabify, tab size 8, more spaces than needed} {
::textutil::tabify::tabify2 "hello world"
} "hello\t world"
test tabify-2.6 {version 2: tabify, tab size 8, less spaces than needed} {
::textutil::tabify::tabify2 "hello world"
} "hello world"
#
# tests 2.7 & 2.8: 'end of line' (\n or not) of last line is preserved
#
test tabify-2.7 {version 2: tabify, tab size 8, multi line} {
::textutil::tabify::tabify2 "line 1 \n line 2\nline 3 \n line 4"
} "line 1\t\n\tline 2\nline 3\t\n\tline 4"
test tabify-2.8 {version 2: tabify, tab size 8, multi line} {
::textutil::tabify::tabify2 "line 1 \n line 2\nline 3 \n line 4\n"
} "line 1\t\n\tline 2\nline 3\t\n\tline 4\n"
# Test handling of existing tabs ... 2.9 as test and 2.10 the
# discrimator to check that it is correct if I use spaces
# instead of a tab, to see that my understanding is basically correct.
test tabify-2.9 {version 2: handling of existing tabs} {
::textutil::tabify::tabify2 "hello\tworld bye"
# hello...world bye
# --------||||||||---
} "hello\tworld\tbye"
test tabify-2.10 {version 2: handling of existing tabs} {
::textutil::tabify::tabify2 "hello world bye"
} "hello\tworld\tbye"
#
# untabify
#
test tabify-3.1 {version 2: untabify, tab size 3} {
::textutil::tabify::untabify2 "hello \tworld" 3
} "hello world"
test tabify-3.2 {version 2: untabify, tab size 3, tab to single space} {
::textutil::tabify::untabify2 "hello\t\tworld" 3
} "hello world"
#
# The change in tab size from 3 to 8 (silently) results in building the
# appropriate 'Spaces' strings (in 3.5 'Spaces(6)' is needed)
#
test tabify-3.3 {version 2: untabify, tab size 8} {
::textutil::tabify::untabify2 "hello\tworld"
} "hello world"
test tabify-3.4 {version 2: untabify, tab size 8, mix of tab and spaces} {
::textutil::tabify::untabify2 "hello \tworld"
} "hello world"
test tabify-3.5 {version 2: untabify, tab size 8, requires 'long' space string} {
::textutil::tabify::untabify2 "hello\tmy\tworld"
} "hello my world"
#
# tests 3.6 & 3.7: 'end of line' (\n or not) of last line is preserved
#
test tabify-3.6 {version 2: untabify, tab size 8, multi line} {
::textutil::tabify::untabify2 "line 1\t\n\tline 2\nline 3\t\n\tline 4"
} "line 1 \n line 2\nline 3 \n line 4"
test tabify-3.7 {version 2: untabify, tab size 8, multi line} {
::textutil::tabify::untabify2 "line 1\t\n\tline 2\nline 3\t\n\tline 4\n"
} "line 1 \n line 2\nline 3 \n line 4\n"
#
# Edge cases: test for empty string
#
test tabify-4.1 {tabify empty string} { ::textutil::tabify::tabify "" } ""
test tabify-4.2 {untabify empty string} { ::textutil::tabify::untabify "" } ""
test tabify-4.3 {tabify2 empty string} { ::textutil::tabify::tabify2 "" } ""
test tabify-4.4 {untabify2 empty string} { ::textutil::tabify::untabify2 "" } ""
|