1# Features covered: Processing Instructions 2# 3# This file contains a collection of tests for the TclXML parser. 4# This file tests the parser's performance on Processing Instructions. 5# Sourcing this file into Tcl runs the tests and generates output 6# for errors. No output means no errors were found. 7# 8# Copyright (c) 1998-2000 Zveno Pty Ltd. 9# 10# $Id: pi.test,v 1.5 2001/02/12 11:10:10 balls Exp $ 11 12if {[lsearch [namespace children] ::tcltest] == -1} { 13 source [file join [pwd] [file dirname [info script]] defs.tcl] 14} 15 16if { ![llength [info commands ::xml::parser]] } { 17 catch {puts stderr "You havent loaded a valid parser class before running this test"} 18 return 19} 20 21catch {unset result} 22proc PI {target data args} { 23 lappend ::result $target $data 24} 25 26test pi-1.1 {PI} { 27 set ::result {} 28 29 catch {rename xml::pi-1.1 {}} 30 set parser [xml::parser pi-1.1 \ 31 -processinginstructioncommand PI] 32 $parser parse {<?xml version="1.0"?> 33<!DOCTYPE Test> 34<Test><?Test This is a processing instruction?></Test> 35} 36 set ::result 37} {Test {This is a processing instruction}} 38 39test pi-1.2 {PI: missing trailing ?} { 40 set ::result {} 41 42 catch {rename xml::pi-1.2 {}} 43 set parser [xml::parser pi-1.2 \ 44 -processinginstructioncommand PI] 45 set returncode [catch {$parser parse {<?xml version="1.0"?> 46<!DOCTYPE Test> 47<Test><?Test This is a syntax error></Test> 48}} msg] 49 50 list $returncode [regexp {PI: expected '\?' character.+} $msg] 51} {1 1} 52 53# Test Tcl special characters in PI data. 54# NB. Tets had to modified since the PI target must be 55# an XML Name (reported by rolf@pointsman.de) 56 57test pi-2.1 {PI with special characters} { 58 set ::result {} 59 60 catch {rename xml::pi-2.1 {}} 61 set parser [xml::parser pi-2.1 \ 62 -processinginstructioncommand PI] 63 $parser parse {<?xml version="1.0"?> 64<!DOCTYPE Test> 65<Test><?if [!VMLRender]?></Test> 66} 67 set ::result 68} {if {[!VMLRender]}} 69 70test pi-2.2 {PI target with special characters} { 71 set ::result {} 72 73 catch {rename xml::pi-2.2 {}} 74 set parser [xml::parser pi-2.2 \ 75 -processinginstructioncommand PI] 76 set err [catch { 77 $parser parse {<?xml version="1.0"?> 78<!DOCTYPE Test> 79<Test><?[if !VMLRender]?></Test> 80} 81 } msg] 82 list $err [regexp {illegal character.*in processing instruction target} $msg] 83} {1 1} 84test pi-2.3 {PI target with "xml"} { 85 set ::result {} 86 87 catch {rename xml::pi-2.3 {}} 88 set parser [xml::parser pi-2.3 \ 89 -processinginstructioncommand PI] 90 set err [catch { 91 $parser parse {<?xml version="1.0"?> 92<!DOCTYPE Test> 93<Test><?abxMLcl illegal?></Test> 94} 95 } msg] 96 list $err [regexp {characters "xml" not permitted} $msg] 97} {1 1} 98 99# cleanup 100::tcltest::cleanupTests 101return 102