File: parse

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 (130 lines) | stat: -rw-r--r-- 4,898 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
# -*- tcl -*-
# doctoc_parse.testsuite:  tests for the doctoc parser.
#
# Copyright (c) 2009 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
#
# RCS: @(#) $Id: parse,v 1.1 2009/04/18 21:14:21 andreas_kupries Exp $

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

source [tcllibPath doctools2base/tests/common]
set mytestdir tests/data

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

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

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-parse-${stkimpl}-${setimpl}-${impl}-20.$k.$n "doctools::toc::parse text, $label$section, ok" -setup {
	    # Define a few basic variables and include search paths for
	    # use by the test
	    doctools::toc::parse var load {fox dog lazy jump}
	    doctools::toc::parse include set [TestFilesGlob $mytestdir]
	} -body {
	    doctools::toc::structure print \
		[doctools::toc::parse text $data]
	} -cleanup {
	    doctools::toc::parse include clear
	    doctools::toc::parse var unset *
	} -result $expected
    }

    TestFilesProcess $mytestdir ok doctoc$section serial-print -> n label input data expected {
	test doctools-toc-parse-${stkimpl}-${setimpl}-${impl}-21.$k.$n "doctools::toc::parse file, $label$section, ok" -setup {
	    # Define a few basic variables and include search paths for
	    # use by the test
	    doctools::toc::parse var load {fox dog lazy jump}
	    doctools::toc::parse include set [TestFilesGlob $mytestdir]
	} -body {
	    doctools::toc::structure print \
		[doctools::toc::parse file $input]
	} -cleanup {
	    doctools::toc::parse include clear
	    doctools::toc::parse var unset *
	} -result $expected
    }
}

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

# We test the error messages and codes thrown by the parser for a
# variety of failure possibilities.

TestFilesProcess $mytestdir fail doctoc emsg -> n label input data expected {
    test doctools-toc-parse-${stkimpl}-${setimpl}-${impl}-22.$n "doctools::toc::parse, $label, error message" -setup {
	# Define a few basic variables and include search paths for
	# use by the test
	doctools::toc::parse var load {fox dog lazy jump}
	doctools::toc::parse include set [TestFilesGlob $mytestdir]
    } -body {
	doctools::toc::parse text $data
    } -cleanup {
	doctools::toc::parse include clear
	doctools::toc::parse var unset *
    } -returnCodes error -result $expected
}

TestFilesProcess $mytestdir fail doctoc ecode -> n label input data expected {
    test doctools-toc-parse-${stkimpl}-${setimpl}-${impl}-23.$n "doctools::toc::parse, $label, error code" -setup {
	# Define a few basic variables and include search paths for
	# use by the test
	doctools::toc::parse var load {fox dog lazy jump}
	doctools::toc::parse include set [TestFilesGlob $mytestdir]
    } -body {
	# Catch and rethrow using the error code as new message.
	catch { doctools::toc::parse text $data }
	set ::errorCode
    } -cleanup {
	doctools::toc::parse include clear
	doctools::toc::parse var unset *
    } -result $expected
}

TestFilesProcess $mytestdir fail doctoc emsg -> n label input data expected {
    test doctools-toc-parse-${stkimpl}-${setimpl}-${impl}-24.$n "doctools::toc::parse file, $label, error message" -setup {
	# Define a few basic variables and include search paths for
	# use by the test
	doctools::toc::parse var load {fox dog lazy jump}
	doctools::toc::parse include set [TestFilesGlob $mytestdir]
    } -body {
	catch { [doctools::toc::parse file $input] } msg
	string map [list "\"$input\" " {}] $msg
    } -cleanup {
	doctools::toc::parse include clear
	doctools::toc::parse var unset *
    } -result $expected
}

TestFilesProcess $mytestdir fail doctoc ecode -> n label input data expected {
    test doctools-toc-parse-${stkimpl}-${setimpl}-${impl}-25.$n "doctools::toc::parse file, $label, error code" -setup {
	# Define a few basic variables and include search paths for
	# use by the test
	doctools::toc::parse var load {fox dog lazy jump}
	doctools::toc::parse include set [TestFilesGlob $mytestdir]
    } -body {
	# Catch and rethrow using the error code as new message.
	catch { doctools::toc::parse file $input }
	string map [list $input {{}}] $::errorCode
    } -cleanup {
	doctools::toc::parse include clear
	doctools::toc::parse var unset *
    } -result $expected
}

# -------------------------------------------------------------------------
unset mytestdir n label input data expected
return