File: container

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 (379 lines) | stat: -rw-r--r-- 12,459 bytes parent folder | download | duplicates (6)
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# -*- tcl -*-
# doctoc.testsuite:  tests for the doctoc management.
#
# Copyright (c) 2009 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
#
# RCS: @(#) $Id: container,v 1.2 2009/11/15 05:50:03 andreas_kupries Exp $

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

set mytestdir tests/data

# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# I. Handling regular serialization of indices, import and export.
#    Import serialization, then re-export.

TestFilesProcess $mytestdir ok serial serial-print -> n label input data expected {
    test doctools-toc-${impl}-40.$n "doctools::toc deserialize serial, $label, ok" -setup {
	doctools::toc I
    } -body {
	I deserialize = $data
	I invalidate
	doctools::toc::structure print [I serialize]
    } -cleanup {
	I destroy
    } -result $expected
}

# Testing the errors thrown for invalid serializations, at the level
# of toc objects. Underneath are the doctools::toc::structure
# commands, so we can and are re-using the test cases which were
# written for them.

foreach {n badserial expected} {
    0 {}
    {error in serialization: dictionary too short, expected exactly one key}
    1 {FOO {}}
    {error in serialization: bad type tag "FOO"}
    2 {doctools::toc {}}
    {error in serialization: dictionary too short, expected exactly three keys}
    3 {doctools::toc {a . b . c .}}
    {error in serialization: missing expected key "label"}
    4 {doctools::toc {label . b . c .}}
    {error in serialization: missing expected key "title"}
    5 {doctools::toc {label . title . c .}}
    {error in serialization: missing expected key "items"}
    7 {doctools::toc {items {{}} label . title .}}
    {error in serialization: element list wrong, need exactly 2}
    8 {doctools::toc {items {{FOO {}}} label . title .}}
    {error in serialization: bad element tag "FOO"}
    9 {doctools::toc {items {{reference {}}} label . title .}}
    {error in serialization: dictionary too short, expected exactly three keys}
    10 {doctools::toc {items {
	{reference {a . b . c .}}} label . title .}}
    {error in serialization: missing expected key "id"}
    11 {doctools::toc {items {
	{reference {id . b . c .}}} label . title .}}
    {error in serialization: missing expected key "label"}
    12 {doctools::toc {items {
	{reference {id . label . c .}}} label . title .}}
    {error in serialization: missing expected key "desc"}
    14 {doctools::toc {items {
	{division {}}} label . title .}}
    {error in serialization: dictionary too short, expected two or three keys}
    15 {doctools::toc {items {
	{division {a . b .}}} label . title .}}
    {error in serialization: missing expected key "label"}
    16 {doctools::toc {items {
	{division {label . b .}}} label . title .}}
    {error in serialization: missing expected key "items"}
    19 {doctools::toc {items {
	{reference {desc . id . label .}}
	{reference {desc . id . label .}}} label . title .}}
    {error in serialization: duplicate labels}
    20 {doctools::toc {items {
	{division {id . items {} label .}}
	{division {id . items {} label .}}} label . title .}}
    {error in serialization: duplicate labels}
    21 {doctools::toc {items {
	{division {id . items {} label .}}
        {reference {desc . id . label .}}} label . title .}}
    {error in serialization: duplicate labels}
} {
    test doctools-toc-${impl}-41.$n "doctools::toc deserialize, error" -setup {
	doctools::toc I
    } -body {
	I deserialize = $badserial
    } -cleanup {
	I destroy
    } -returnCodes error -result $expected
}

foreach {n noncanonserial expected} {
    6 {doctools::toc {label . title . items {}}}
    {doctools::toc {items {} label . title .}}
    13 {doctools::toc {items {
	{reference {id . label . desc .}}} label . title .}}
    {doctools::toc {items {{reference {desc . id . label .}}} label . title .}}
    17 {doctools::toc {items {
	{division {label . items {}}}} label . title .}}
    {doctools::toc {items {{division {items {} label .}}} label . title .}}
    18 {doctools::toc {items {
	{division {items {} label . id .}}} label . title .}}
    {doctools::toc {items {{division {id . items {} label .}}} label . title .}}
} {
    test doctools-toc-${impl}-42.$n "doctools::toc deserialize, regular to canonical" -setup {
	doctools::toc I
	I deserialize = $noncanonserial
    } -body {
	I serialize
    } -cleanup {
	I destroy
    } -result $expected
}

# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# II. Handling doctoc markup as serialization format, import and export.

# Checking that the various forms of doctoc markup as generated by the
# export plugin doctools::toc(::export::doctoc) are valid input for
# the doctoc import plugin. Actually testing that using an import
# manager from the toc is working.

foreach {k section} {
    0 {}
    1 -ultracompact
    2 -compact
    3 -indented
    4 -aligned
    5 -indalign
} {
    TestFilesProcess $mytestdir ok doctoc$section serial-print -> n label input data expected {
	test doctools-toc-${impl}-50.$k.$n "doctools::toc deserialize = doctoc, $label$section, ok" -setup {
	    doctools::toc I
	    doctools::toc::import IN
	    I importer IN
	} -body {
	    I deserialize = $data doctoc
	    doctools::toc::structure print [I serialize]
	} -cleanup {
	    I destroy
	    IN destroy
	} -result $expected
    }
}

# We test the error messages and codes thrown during import for a
# variety of failure possibilities

TestFilesProcess $mytestdir fail doctoc emsg -> n label input data expected {
    test doctools-toc-${impl}-51.$n "doctools::toc deserialize = doctoc, $label, error message" -setup {
	# Basic variables and include search paths for use by the tests
	doctools::toc::import IN
	IN config set fox dog
	IN config set lazy jump
	IN include add [TestFilesGlob $mytestdir]
	doctools::toc I
	I importer IN
    } -body {
	I deserialize = $data doctoc
    } -cleanup {
	I destroy
	IN destroy
    } -returnCodes error -result $expected
}

TestFilesProcess $mytestdir fail doctoc ecode -> n label input data expected {
    test doctools-toc-${impl}-52.$n "doctools::toc deserialize = doctoc, $label, error code" -setup {
	# Basic variables and include search paths for use by the tests
	doctools::toc::import IN
	IN config set fox dog
	IN config set lazy jump
	IN include add [TestFilesGlob $mytestdir]
	doctools::toc I
	I importer IN
    } -body {
	catch { I deserialize = $data doctoc }
	set ::errorCode
    } -cleanup {
	I destroy
	IN destroy
    } -result $expected
}

# Testing the export of doctoc markup through attached exporter management, for all possible configurations.

foreach {k nl in al section} {
    0 0 0 0 -ultracompact
    1 1 0 0 -compact
    2 1 1 0 -indented
    3 1 0 1 -aligned
    4 1 1 1 -indalign
    5 0 1 0 -indented
    6 0 0 1 -aligned
    7 0 1 1 -indalign
} {
    TestFilesProcess $mytestdir ok serial doctoc$section -> n label input data expected {
	test doctools-toc-${impl}-53.$k.$n "doctools::toc serialize doctoc, ${label}$section, ok" -setup {
	    doctools::toc::export OUT
	    OUT config set newlines $nl
	    OUT config set indented $in
	    OUT config set aligned  $al
	    doctools::toc I
	    I exporter OUT
	} -body {
	    I deserialize = $data
	    stripcomments [I serialize doctoc]
	} -cleanup {
	    I destroy
	    OUT destroy
	} -result $expected
    }
}

# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# III. Handling text markup as serialization format, export only

TestFilesProcess $mytestdir ok serial text -> n label input data expected {
    test doctools-toc-${impl}-54.$n "doctools::toc serialize text, $label, ok" -setup {
	doctools::toc::export OUT
	doctools::toc I
	I exporter OUT
    } -body {
	I deserialize = $data
	I serialize text
    } -cleanup {
	I destroy
	OUT destroy
    } -result $expected
}

# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# IV. Handling json markup as serialization format, import and export.

# We are checking that the various forms of json markup, as can be
# generated by doctools::toc(::export(::json)) are valid input to the
# json parser.
#
# section {} holds the non-canonical input we have to accept and make
# canonical to higher layers.

foreach {k section} {
    0 {}
    1 -ultracompact
    2 -indented
    3 -indalign
} {
    TestFilesProcess $mytestdir ok json$section serial-print -> n label input data expected {
	test doctools-toc-${impl}-55.$k.$n "doctools::toc deserialize = json, $label$section, ok" -setup {
	    doctools::toc::import IN
	    doctools::toc I
	    I importer IN
	} -body {
	    I deserialize = $data json
	    doctools::toc::structure print [I serialize]
	} -cleanup {
	    I destroy
	    IN destroy
	} -result $expected
    }
}

TestFilesProcess $mytestdir fail json json-emsg -> n label input data expected {
    test doctools-toc-${impl}-56.$n "doctools::toc deserialize = json, $label, error message" -setup {
	doctools::toc::import IN
	doctools::toc I
	I importer IN
    } -body {
	I deserialize = $data json
    } -cleanup {
	I destroy
	IN destroy
    } -returnCodes error -result $expected
}

foreach {k in al section} {
    0 0 0 -ultracompact
    1 1 0 -indented
    2 0 1 -indalign
    3 1 1 -indalign
} {
    TestFilesProcess $mytestdir ok serial json$section -> n label input data expected {
	test doctools-toc-${impl}-57.$k.$n "doctools::toc serialize json, $label$section, ok" -setup {
	    doctools::toc::export OUT
	    OUT config set indented $in
	    OUT config set aligned  $al
	    doctools::toc I
	    I exporter OUT
	} -body {
	    I deserialize = $data
	    I serialize json
	} -cleanup {
	    I destroy
	    OUT destroy
	} -result $expected
    }
}

# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# V. Handling html markup as serialization format, export only

foreach {k nl in section} {
    0 0 0 -ultracompact
    1 0 1 -indented
    2 1 0 -compact
    3 1 1 -indented
} {
    TestFilesProcess $mytestdir ok serial html$section -> n label input data expected {
	test doctools-toc-${impl}-58.$k.$n "doctools::toc serialize html, $label$section, ok" -setup {
	    doctools::toc::export OUT
	    OUT config set newlines $nl
	    OUT config set indented $in
	    OUT config set user _dummy_
	    doctools::toc I
	    I exporter OUT
	} -body {
	    I deserialize = $data
	    striphtmlcomments [I serialize html] 3
	} -cleanup {
	    I destroy
	    OUT destroy
	} -result $expected
    }
}

# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# VI. Handling wiki markup as serialization format, export only

TestFilesProcess $mytestdir ok serial wiki -> n label input data expected {
    test doctools-toc-${impl}-59.$n "doctools::toc serialize wiki, $label, ok" -setup {
	doctools::toc::export OUT
	doctools::toc I
	I exporter OUT
    } -body {
	I deserialize = $data
	I serialize wiki
    } -cleanup {
	I destroy
	OUT destroy
    } -result $expected
}

# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# VII. Handling nroff markup as serialization format, export only

foreach {k inline section} {
    0 0 -external
    1 1 -inlined
} {
    TestFilesProcess $mytestdir ok serial nroff$section -> n label input data expected {
	test doctools-toc-${impl}-60.$k.$n "doctools::toc serialize nroff, $label$section, ok" -setup {
	    doctools::toc::export OUT
	    OUT config set inline $inline
	    doctools::toc I
	    I exporter OUT
	} -body {
	    I deserialize = $data
	    stripnroffcomments [stripmanmacros [I serialize nroff]]
	} -cleanup {
	    I destroy
	    OUT destroy
	} -result $expected
    }
}

# -------------------------------------------------------------------------
return

# TODO :: Test the merging of indices (copy from toc_structure.test)

# -------------------------------------------------------------------------
return