1## 
2## This is the file `docstrip.test',
3## generated with the SAK utility
4## (sak docstrip/regen).
5## 
6## The original source files were:
7## 
8## tcldocstrip.dtx  (with options: `test')
9## 
10## In other words:
11## **************************************
12## * This Source is not the True Source *
13## **************************************
14## the true source is the file from which this one was generated.
15##
16source [file join [file dirname [file dirname [file join [pwd] [info script]]]] devtools testutilities.tcl]
17testsNeedTcl     8.4
18testsNeedTcltest 1.0
19testing {useLocal docstrip.tcl docstrip}
20set docstrip_sources_dir [localPath {}]
21tcltest::testConstraint docstripSourcesAvailable [expr {[
22   file exists [file join $docstrip_sources_dir docstrip.tcl]
23] && [
24   file exists [file join $docstrip_sources_dir tcldocstrip.dtx]
25]}]
26tcltest::test docstrip-1.1 {code/comment line distinction} -body {
27   docstrip::extract [join {
28     {% comment}
29     {% more comment !"#$%&/(}
30     {some command}
31     { % blah $blah "Not a comment."}
32     {% abc; this is comment}
33     {# def; this is code}
34     {ghi}
35     {% jkl}
36   } \n] {}
37} -result [
38   join {
39     {some command}
40     { % blah $blah "Not a comment."}
41     {# def; this is code}
42     {ghi} ""
43   } \n
44]
45tcltest::test docstrip-1.2 {blocks and nesting} -body {
46   set text [join {
47      {begin}
48      {%<*foo>}
49      {1}
50      {%<*bar>}
51      {2}
52      {%</bar>}
53      {%<*!bar>}
54      {3}
55      {%</!bar>}
56      {4}
57      {%</foo>}
58      {5}
59      {%<*bar>}
60      {6}
61      {%</bar>}
62      {end}
63   } \n]
64   set res [docstrip::extract $text foo]
65   append res [docstrip::extract $text {foo bar}]
66   append res [docstrip::extract $text bar]
67} -result [
68   join {
69      {begin}
70      {1}
71      {3}
72      {4}
73      {5}
74      {end}
75      {begin}
76      {1}
77      {2}
78      {4}
79      {5}
80      {6}
81      {end}
82      {begin}
83      {5}
84      {6}
85      {end} ""
86   } \n
87]
88tcltest::test docstrip-1.3 {plusminus guards and metacomments} -body {
89   set text [join {
90      {begin}
91      {%<foo> foo}
92      {%<+foo>plusfoo}
93      {%<-foo>minusfoo}
94      {middle}
95      {%% some metacomment}
96      {%<*foo>}
97      {%%another metacomment}
98      {%</foo>}
99      {end}
100   } \n]
101   set res [docstrip::extract $text foo -metaprefix {# }]
102   append res [docstrip::extract $text bar -metaprefix {#}]
103} -result [
104   join {
105      {begin}
106      { foo}
107      {plusfoo}
108      {middle}
109      {#  some metacomment}
110      {# another metacomment}
111      {end}
112      {begin}
113      {minusfoo}
114      {middle}
115      {# some metacomment}
116      {end} ""
117   } \n
118]
119tcltest::test docstrip-1.4 {verbatim mode} -body {
120   set text [join {
121      {begin}
122      {%<*myblock>}
123      {some stupid()}
124      {   #computer<program>}
125      {%<<QQQ-98765}
126      {% These three lines are copied verbatim (including percents}
127      {%% even if -metaprefix is something different than %%).}
128      {%</myblock>}
129      {%QQQ-98765}
130      {   using*strange@programming<language>}
131      {%</myblock>}
132      {end}
133   } \n]
134   set res [docstrip::extract $text myblock -metaprefix {# }]
135   append res [docstrip::extract $text {}]
136} -result [
137   join {
138      {begin}
139      {some stupid()}
140      {   #computer<program>}
141      {% These three lines are copied verbatim (including percents}
142      {%% even if -metaprefix is something different than %%).}
143      {%</myblock>}
144      {   using*strange@programming<language>}
145      {end}
146      {begin}
147      {end} ""
148   } \n
149]
150tcltest::test docstrip-1.5 {annotation} -body {
151   set text [join {
152      {begin}
153      {%<*myblock>}
154      {some stupid()}
155      {%<foo>   #computer<program>}
156      {%<<QQQ-98765}
157      {% These three lines are copied verbatim (including percents}
158      {%% even if -metaprefix is something different than %%).}
159      {%</myblock>}
160      {%QQQ-98765}
161      {   using*strange@programming<language>}
162      {%</myblock>}
163      {%%end}
164   } \n]
165   docstrip::extract $text {myblock foo} -metaprefix {# } -annotate 3
166} -result [
167   join {
168      {begin} {. "" ""} 1 {}
169      {some stupid()} {. "" ""} 3 myblock
170      {   #computer<program>} {+ %<foo> {}} 4 myblock
171      {% These three lines are copied verbatim (including percents}
172        {V "" ""} 6 myblock
173      {%% even if -metaprefix is something different than %%).}
174        {V "" ""} 7 myblock
175      {%</myblock>} {V "" ""} 8 myblock
176      {   using*strange@programming<language>} {. "" ""} 10 myblock
177      {# end} {M %% {# }} 12 {}
178      ""
179   } \n
180]
181tcltest::test docstrip-2.1 {have docstrip extract itself} -constraints {
182   docstripSourcesAvailable
183} -body {
184   # First read in the ready-stripped file, but gobble the preamble and
185   # postamble, as those are a bit messy to reproduce.
186   set F [open [file join $docstrip_sources_dir docstrip.tcl] r]
187   regsub -all -- {(^|\n)#[^\n]*} [read $F] {} stripped
188   close $F
189   # Then read the master source and strip it manually.
190   set F [open [file join $docstrip_sources_dir tcldocstrip.dtx] r]
191   set source [read $F]
192   close $F
193   set stripped2 [docstrip::extract $source pkg -metaprefix ##]
194   # Finally compare the two.
195   if {[string trim $stripped \n] ne [string trim $stripped2 \n]} then {
196      error "$strippped\n ne \n$stripped2"
197   }
198}
199tcltest::test docstrip-2.2 {soucefrom} -setup {
200   set dtxname [tcltest::makeFile [join {
201      {% Just a minor test file.}
202      {puts A}
203      {%<*bar>}
204      {puts B}
205      {%<*foo>}
206      {puts [info exists baz]}
207      {set baz 1}
208      {%</foo>}
209      {%<-foo>return}
210      {%</bar>}
211      {puts $baz}
212      {puts [file tail [info script]]}
213      {%<*!foo>}
214      {puts C}
215      "%% Tricky comment; guess what comes next\\"
216      {%</!foo>}
217      {incr baz}
218      {puts "baz=$baz"}
219   } \n] te27st01.dtx]
220} -body {
221   set baz 0
222   puts [info script]
223   docstrip::sourcefrom $dtxname {foo bar}
224   puts [info script]
225   docstrip::sourcefrom $dtxname {}
226   docstrip::sourcefrom $dtxname {bar}
227   puts $baz
228} -cleanup {
229   tcltest::removeFile $dtxname
230} -output [join [list\
231   [info script]\
232   {A} {B} {1} {1} {te27st01.dtx} {baz=2}\
233   [info script]\
234   {A} {2} {te27st01.dtx} {C} {baz=2}\
235   {A} {B}\
236   {2} ""
237] \n]
238testsuiteCleanup
239## 
240## 
241## End of file `docstrip.test'.