File: doctoc.test

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (363 lines) | stat: -rw-r--r-- 10,237 bytes parent folder | download | duplicates (2)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# -*- tcl -*-
# doctoc.test:  tests for the doctools::toc 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.
#
# Copyright (c) 2003-2019 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.2
testsNeedTcltest 1.0

support {
    use textutil/expander.tcl textutil::expander
    use fileutil/fileutil.tcl fileutil
}
testing {
    useLocal doctoc.tcl doctools::toc
}

# -------------------------------------------------------------------------

array_unset env LANG*
array_unset env LC_*
set env(LANG) C ; # Usually default if nothing is set, OS X requires this.

# -------------------------------------------------------------------------

namespace import ::doctools::toc::new

# search paths .............................................................

test doctoc-1.0 {default search paths} {
    llength $::doctools::toc::paths
} 1

test doctoc-1.1 {extend package search paths} {
    ::doctools::toc::search [file dirname [info script]]
    set     res [list]
    lappend res [llength $::doctools::toc::paths]
    lappend res [lindex  $::doctools::toc::paths 0]
    set     res
} [list 2 [file dirname [info script]]]

test doctoc-1.2 {extend package search paths, error} {
    catch {::doctools::toc::search foo} result
    set     result
} {doctools::toc::search: path does not exist}

# format help .............................................................

test doctoc-2.0 {format help} {
    string length [doctools::toc::help]
} 338

# doctoc .............................................................

test doctoc-3.0 {doctoc errors} {
    catch {new} msg
    set msg
} [tcltest::wrongNumArgs "new" "name args" 0]

test doctoc-3.1 {doctoc errors} {
    catch {new set} msg
    set msg
} "command \"set\" already exists, unable to create doctoc object"

test doctoc-3.2 {doctoc errors} {
    new mydoctoc
    catch {new mydoctoc} msg
    mydoctoc destroy
    set msg
} "command \"mydoctoc\" already exists, unable to create doctoc object"

test doctoc-3.3 {doctoc errors} {
    catch {new mydoctoc -foo} msg
    set msg
} {wrong # args: doctools::new name ?opt val...??}

# doctoc methods ......................................................

test doctoc-4.0 {doctoc method errors} {
    new mydoctoc
    catch {mydoctoc} msg
    mydoctoc destroy
    set msg
} "wrong # args: should be \"mydoctoc option ?arg arg ...?\""

test doctoc-4.1 {doctoc errors} {
    new mydoctoc
    catch {mydoctoc foo} msg
    mydoctoc destroy
    set msg
} "bad option \"foo\": must be cget, configure, destroy, format, map, search, warnings, parameters, or setparam"

# cget ..................................................................

test doctoc-5.0 {cget errors} {
    new mydoctoc
    catch {mydoctoc cget} result
    mydoctoc destroy
    set result
} [tcltest::wrongNumArgs "::doctools::toc::_cget" "name option" 1]

test doctoc-5.1 {cget errors} {
    new mydoctoc
    catch {mydoctoc cget foo bar} result
    mydoctoc destroy
    set result
} [tcltest::tooManyArgs "::doctools::toc::_cget" "name option"]

test doctoc-5.2 {cget errors} {
    new mydoctoc
    catch {mydoctoc cget -foo} result
    mydoctoc destroy
    set result
} {doctools::toc::_configure: Unknown option "-foo", expected -file, or -format}

foreach {na nb option default newvalue} {
    3  4 -file       {} foo
    5  6 -format     {} html
} {
    test doctoc-5.$na {cget query} {
	new mydoctoc
	set res [mydoctoc cget $option]
	mydoctoc destroy
	set res
    } $default ; # {}

    test doctoc-5.$nb {cget set & query} {
	new mydoctoc
	mydoctoc configure $option $newvalue
	set res [mydoctoc cget $option]
	mydoctoc destroy
	set res
    } $newvalue ; # {}
}

# configure ..................................................................

test doctoc-6.0 {configure errors} {
    new mydoctoc
    catch {mydoctoc configure -foo bar -glub} result
    mydoctoc destroy
    set result
} {wrong # args: doctools::toc::_configure name ?opt val...??}
# [tcltest::wrongNumArgs "::doctools::toc::_configure" "name ?option?|?option value...?" 1]

test doctoc-6.1 {configure errors} {
    new mydoctoc
    catch {mydoctoc configure -foo} result
    mydoctoc destroy
    set result
} {doctools::toc::_configure: Unknown option "-foo", expected -file, or -format}

test doctoc-6.2 {configure retrieval} {
    new mydoctoc
    catch {mydoctoc configure} result
    mydoctoc destroy
    set result
} {-file {} -format {}}

foreach {n option illegalvalue result} {
    3 -format     barf {doctools::toc::_configure: -format: Unknown format "barf"}
} {
    test doctoc-6.$n {configure illegal value} {
	new mydoctoc
	catch {mydoctoc configure $option $illegalvalue} result
	mydoctoc destroy
	set result
    } $result
}

foreach {na nb option default newvalue} {
    4  5 -file       {} foo
    6  7 -format     {} html
} {
    test doctoc-6.$na {configure query} {
	new mydoctoc
	set res [mydoctoc configure $option]
	mydoctoc destroy
	set res
    } $default ; # {}

    test doctoc-6.$nb {configure set & query} {
	new mydoctoc
	mydoctoc configure $option $newvalue
	set res [mydoctoc configure $option]
	mydoctoc destroy
	set res
    } $newvalue ; # {}
}

test doctoc-6.8 {configure full retrieval} {
    new mydoctoc -file foo -format html
    catch {mydoctoc configure} result
    mydoctoc destroy
    set result
} {-file foo -format html}

# search ..................................................................

test doctoc-7.0 {search errors} {
    new mydoctoc
    catch {mydoctoc search} result
    mydoctoc destroy
    set result
} [tcltest::wrongNumArgs "::doctools::toc::_search" "name path" 1]

test doctoc-7.1 {search errors} {
    new mydoctoc
    catch {mydoctoc search foo bar} result
    mydoctoc destroy
    set result
} [tcltest::tooManyArgs "::doctools::toc::_search" "name path"]

test doctoc-7.2 {search errors} {
    new mydoctoc
    catch {mydoctoc search foo} result
    mydoctoc destroy
    set result
} {mydoctoc search: path does not exist}

test doctoc-7.3 {search, initial} {
    new mydoctoc
    set res [llength $::doctools::toc::doctocmydoctoc::paths]
    mydoctoc destroy
    set res
} 0

test doctoc-7.4 {extend object search paths} {
    new mydoctoc
    mydoctoc search [file dirname [info script]]
    set     res [list]
    lappend res [llength $::doctools::toc::doctocmydoctoc::paths]
    lappend res [lindex  $::doctools::toc::doctocmydoctoc::paths 0]
    mydoctoc destroy
    set     res
} [list 1 [file dirname [info script]]]

# format & warnings .......................................................

test doctoc-8.0 {format errors} {
    new mydoctoc
    catch {mydoctoc format} result
    mydoctoc destroy
    set result
} [tcltest::wrongNumArgs "::doctools::toc::_format" "name text" 1]

test doctoc-8.1 {format errors} {
    new mydoctoc
    catch {mydoctoc format foo bar} result
    mydoctoc destroy
    set result
} [tcltest::tooManyArgs "::doctools::toc::_format" "name text"]

test doctoc-8.2 {format errors} {
    new mydoctoc
    catch {mydoctoc format foo} result
    mydoctoc destroy
    set result
} {mydoctoc: No format was specified}


test doctoc-8.3 {format} {
    new mydoctoc -format wiki
    set res [mydoctoc format {[toc_begin foo bar][item at snafu gnarf][toc_end]}]
    lappend res [mydoctoc warnings]
    mydoctoc destroy
    set res
} {Table of Contents '''foo''' '''bar''' {[[snafu]]:} at -- gnarf {}}


# doctoc syntax .......................................................

test doctoc-9.0 {doctoc syntax} {
    new mydoctoc -format null
    catch {mydoctoc format foo} result
    mydoctoc destroy
    set result
} {Doctoc Error in plain text at line 1, column 0:
[plain_text foo]
--> (FmtError) TOC error (toc/plaintext), "plain_text foo" : Plain text beyond whitespace is not allowed..}

test doctoc-9.1 {doctoc syntax v1.1, empty toc, ok} {
    new mydoctoc -format null
    set result [mydoctoc format {[toc_begin TOC Test][toc_end]}]
    mydoctoc destroy
    set result
} {}

test doctoc-9.2 {doctoc syntax v1.1, mixing items and divisions, ok} {
    new mydoctoc -format null
    set result [mydoctoc format {[toc_begin TOC Test][item I1f i1 i1d][division_start D Df][item I2f i2 i2d][division_end][toc_end]}]
    mydoctoc destroy
    set result
} {}

test doctoc-9.3 {doctoc syntax v1.1, empty division, ok} {
    new mydoctoc -format null
    set result [mydoctoc format {[toc_begin TOC Test][division_start D Df][division_end][toc_end]}]
    mydoctoc destroy
    set result
} {}


# -------------------------------------------------------------------------
## Series of tests for all available backends, check their formatting.

set k 11
foreach format {
    html tmml nroff
    text wiki markdown
    null
} {
    set n 0
    foreach src [TestFilesGlob tests/toc/toc/*] {
	# Get the expected result
	set dst [localPath [file join tests toc $format [file tail $src]]]
	set map {} ; lappend map @USR@ $tcl_platform(user)
	set rem {} ; lappend rem $tcl_platform(user) @USR@
	if {$format eq "nroff"} {
		lappend map ".so man.macros\n" [fileutil::cat [localPath mpformats/man.macros]]
	}
	if {[catch {
	    set expected [string map $map [fileutil::cat $dst]]
	}]} { set expected **missing** }

	test doctoc-${format}-${k}.$n "doctoc backends, $format/[file tail $src]" {
	    new mydoctoc
	    mydoctoc configure \
		-format    $format \
		-file      .FILE.
	    if {[catch {
		set res [mydoctoc format [fileutil::cat $src]]
	    }]} {
		set res $::errorInfo
	    }
	    mydoctoc destroy
	    #fileutil::writeFile ${dst}.actual [string map $rem $res]
	    set res
	} $expected

	#fileutil::writeFile ${dst}.expected $expected
	incr n
    }
    incr k
}

# -------------------------------------------------------------------------

namespace forget ::doctools::toc::new

# -------------------------------------------------------------------------
testsuiteCleanup
return