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
|
# -*- tcl -*-
# docidx.test: tests for the doctools::idx 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 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
#
# RCS: @(#) $Id: docidx.test,v 1.8 2005/09/28 04:51:19 andreas_kupries Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import ::tcltest::*
}
# -------------------------------------------------------------------------
# Ensure we test _this_ local copy and not one installed somewhere else.
#
package forget doctools::idx
package forget textutil::expander
catch {namespace delete ::doctools::idx}
catch {namespace delete ::textutil::expander}
if {[catch {source [file join [file dirname [info script]] docidx.tcl]} msg]} {
puts "skipped [file tail [info script]]: $msg"
return
}
if {[catch {source [file join [file dirname [file dirname [file normalize [info script]]]] textutil expander.tcl]} msg]} {
puts "skipped [file tail [info script]] (textutil/expander.tcl): $msg"
return
}
package require doctools::idx
package require textutil::expander
puts "doctools::idx [package present doctools::idx]"
puts "- textutil::expander [package present textutil::expander]"
# -------------------------------------------------------------------------
namespace import ::doctools::idx::new
# search paths .............................................................
test docidx-1.0 {default search paths} {
llength $::doctools::idx::paths
} 1
test docidx-1.1 {extend package search paths} {
::doctools::idx::search [file dirname [info script]]
set res [list]
lappend res [llength $::doctools::idx::paths]
lappend res [lindex $::doctools::idx::paths 0]
set res
} [list 2 [file dirname [info script]]]
test docidx-1.2 {extend package search paths, error} {
catch {::doctools::idx::search foo} result
set result
} {doctools::idx::search: path does not exist}
# format help .............................................................
test docidx-2.0 {format help} {
string length [doctools::idx::help]
} 368
# docidx .............................................................
test docidx-3.0 {docidx errors} {
catch {new} msg
set msg
} [tcltest::wrongNumArgs "new" "name args" 0]
test docidx-3.1 {docidx errors} {
catch {new set} msg
set msg
} "command \"set\" already exists, unable to create docidx object"
test docidx-3.2 {docidx errors} {
new mydocidx
catch {new mydocidx} msg
mydocidx destroy
set msg
} "command \"mydocidx\" already exists, unable to create docidx object"
test docidx-3.3 {docidx errors} {
catch {new mydocidx -foo} msg
set msg
} {wrong # args: doctools::new name ?opt val...??}
# docidx methods ......................................................
test docidx-4.0 {docidx method errors} {
new mydocidx
catch {mydocidx} msg
mydocidx destroy
set msg
} "wrong # args: should be \"mydocidx option ?arg arg ...?\""
test docidx-4.1 {docidx errors} {
new mydocidx
catch {mydocidx foo} msg
mydocidx destroy
set msg
} "bad option \"foo\": must be cget, configure, destroy, format, map, search, warnings, parameters, or setparam"
# cget ..................................................................
test docidx-5.0 {cget errors} {
new mydocidx
catch {mydocidx cget} result
mydocidx destroy
set result
} [tcltest::wrongNumArgs "::doctools::idx::_cget" "name option" 1]
test docidx-5.1 {cget errors} {
new mydocidx
catch {mydocidx cget foo bar} result
mydocidx destroy
set result
} [tcltest::tooManyArgs "::doctools::idx::_cget" "name option"]
test docidx-5.2 {cget errors} {
new mydocidx
catch {mydocidx cget -foo} result
mydocidx destroy
set result
} {doctools::idx::_configure: Unknown option "-foo", expected -file, or -format}
foreach {na nb option default newvalue} {
3 4 -file {} foo
5 6 -format {} html
} {
test docidx-5.$na {cget query} {
new mydocidx
set res [mydocidx cget $option]
mydocidx destroy
set res
} $default ; # {}
test docidx-5.$nb {cget set & query} {
new mydocidx
mydocidx configure $option $newvalue
set res [mydocidx cget $option]
mydocidx destroy
set res
} $newvalue ; # {}
}
# configure ..................................................................
test docidx-6.0 {configure errors} {
new mydocidx
catch {mydocidx configure -foo bar -glub} result
mydocidx destroy
set result
} {wrong # args: doctools::idx::_configure name ?opt val...??}
# [tcltest::wrongNumArgs "::doctools::idx::_configure" "name ?option?|?option value...?" 1]
test docidx-6.1 {configure errors} {
new mydocidx
catch {mydocidx configure -foo} result
mydocidx destroy
set result
} {doctools::idx::_configure: Unknown option "-foo", expected -file, or -format}
test docidx-6.2 {configure retrieval} {
new mydocidx
catch {mydocidx configure} result
mydocidx destroy
set result
} {-file {} -format {}}
foreach {n option illegalvalue result} {
3 -format barf {doctools::idx::_configure: -format: Unknown format "barf"}
} {
test docidx-6.$n {configure illegal value} {
new mydocidx
catch {mydocidx configure $option $illegalvalue} result
mydocidx destroy
set result
} $result
}
foreach {na nb option default newvalue} {
4 5 -file {} foo
6 7 -format {} html
} {
test docidx-6.$na {configure query} {
new mydocidx
set res [mydocidx configure $option]
mydocidx destroy
set res
} $default ; # {}
test docidx-6.$nb {configure set & query} {
new mydocidx
mydocidx configure $option $newvalue
set res [mydocidx configure $option]
mydocidx destroy
set res
} $newvalue ; # {}
}
test docidx-6.8 {configure full retrieval} {
new mydocidx -file foo -format html
catch {mydocidx configure} result
mydocidx destroy
set result
} {-file foo -format html}
# search ..................................................................
test docidx-7.0 {search errors} {
new mydocidx
catch {mydocidx search} result
mydocidx destroy
set result
} [tcltest::wrongNumArgs "::doctools::idx::_search" "name path" 1]
test docidx-7.1 {search errors} {
new mydocidx
catch {mydocidx search foo bar} result
mydocidx destroy
set result
} [tcltest::tooManyArgs "::doctools::idx::_search" "name path"]
test docidx-7.2 {search errors} {
new mydocidx
catch {mydocidx search foo} result
mydocidx destroy
set result
} {mydocidx search: path does not exist}
test docidx-7.3 {search, initial} {
new mydocidx
set res [llength $::doctools::idx::docidxmydocidx::paths]
mydocidx destroy
set res
} 0
test docidx-7.4 {extend object search paths} {
new mydocidx
mydocidx search [file dirname [info script]]
set res [list]
lappend res [llength $::doctools::idx::docidxmydocidx::paths]
lappend res [lindex $::doctools::idx::docidxmydocidx::paths 0]
mydocidx destroy
set res
} [list 1 [file dirname [info script]]]
# format & warnings .......................................................
test docidx-8.0 {format errors} {
new mydocidx
catch {mydocidx format} result
mydocidx destroy
set result
} [tcltest::wrongNumArgs "::doctools::idx::_format" "name text" 1]
test docidx-8.1 {format errors} {
new mydocidx
catch {mydocidx format foo bar} result
mydocidx destroy
set result
} [tcltest::tooManyArgs "::doctools::idx::_format" "name text"]
test docidx-8.2 {format errors} {
new mydocidx
catch {mydocidx format foo} result
mydocidx destroy
set result
} {mydocidx: No format was specified}
test docidx-8.3 {format} {
new mydocidx -format wiki
set res [mydocidx format {[index_begin foo bar][key snafu][manpage at fubar][index_end]}]
lappend res [mydocidx warnings]
mydocidx destroy
set res
} {Index '''foo''' '''bar''' '''snafu''': at {}}
# docidx manpage syntax .......................................................
test docidx-9.0 {docidx syntax} {
new mydocidx -format null
catch {mydocidx format foo} result
mydocidx destroy
set result
} {Docidx Error in plain text at line 1, column 0:
[plain_text foo]
--> (FmtError) IDX error (idx/plaintext), "plain_text foo" : Plain text beyond whitespace is not allowed..}
namespace forget ::doctools::idx::new
::tcltest::cleanupTests
|