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
|
# Features covered: comments
#
# This file contains a collection of tests for the TclXML parser.
# This file tests the parser's performance on comments.
# Sourcing this file into Tcl runs the tests and generates output
# for errors. No output means no errors were found.
#
# Copyright (c) 1998-2003 Zveno Pty Ltd.
#
# $Id: comment.test,v 1.5 2003/12/03 20:06:36 balls Exp $
package require tcltest
source [file join [tcltest::workingDirectory] tclxmlutils.tcl]
testPackage $::tcltest::parser
namespace eval ::xml::commentTest {
namespace import -force ::tcltest::*
variable SETUP {
variable result {}
variable comment {}
variable element 0
proc pcdata data {
variable result
append result $data
}
proc comment data {
variable comment
append comment $data
}
proc EStart {tagName attrList args} {
variable element
switch -- $tagName {
test -
Test {
}
default {
incr element
}
}
}
proc EStop {tagName args} {
}
set parser [xml::parser \
-elementstartcommand [namespace code EStart] \
-elementendcommand [namespace code EStop] \
-characterdatacommand [namespace code pcdata] \
-commentcommand [namespace code comment]]
}
variable CLEANUP {
catch {unset result}
catch {unset comment}
catch {unset element}
rename pcdata {}
rename comment {}
rename EStart {}
rename EStop {}
$parser free
}
test comment-1.1 {Simple comment} -setup $SETUP -body {
$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!-- This is a comment --></Test>
}
list $comment $result $element
} -cleanup $CLEANUP -result {{ This is a comment } {} 0}
test comment-1.2 {Simple comment, no white space} -setup $SETUP -body {
$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!--This is a comment--></Test>
}
list $comment $result $element
} -cleanup $CLEANUP -result {{This is a comment} {} 0}
test comment-1.3 {Simple comment, within PCDATA} -setup $SETUP -body {
$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test>surrounding <!--This is a comment--> PCDATA</Test>
}
list $comment $result $element
} -cleanup $CLEANUP -result {{This is a comment} {surrounding PCDATA} 0}
test comment-1.4 {Simple comment, no white space} -setup $SETUP -body {
$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!--comment--></Test>
}
list $comment $result $element
} -cleanup $CLEANUP -result {comment {} 0}
test comment-1.5 {comment, with nested element} -setup $SETUP -body {
$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!-- comment <!blah>--></Test>
}
list $comment $result $element
} -cleanup $CLEANUP -result {{ comment <!blah>} {} 0}
test comment-2.1 {comment with an angle bracket} -setup $SETUP -body {
$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!-- This is a > greater than sign --></Test>
}
list $comment $result $element
} -cleanup $CLEANUP -result {{ This is a > greater than sign } {} 0}
test comment-2.2 {comment with multiple angle brackets} -setup $SETUP -body {
$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!--
<Test>
<Element>
<Empty/>
</Element>
</Test>
--></Test>
}
list $comment $result $element
} -cleanup $CLEANUP -result {{
<Test>
<Element>
<Empty/>
</Element>
</Test>
} {} 0}
variable SETUP2 {
eval $SETUP
variable commentData [format {
<question title="This is <okay>, right?" />
<question title="Is <this> bogus?" />
<section title="This is a problem%s" />
} \}]
}
variable CLEANUP2 {
eval $CLEANUP
unset commentData
}
test comment-2.3 {comment with entities} -setup $SETUP2 -body {
$parser parse "<?xml version='1.0'?>
<!DOCTYPE test SYSTEM 'test.dtd'>
<test>
<author>
<organization/>
</author>
<!--${commentData}-->
</test>"
list [string equal $comment $commentData] [string trim $result] $element
} -cleanup $CLEANUP2 -result [list 1 {} 2]
cleanupTests
}
namespace delete ::xml::commentTest
return
|