1# Features covered:  Processing Instructions
2#
3# This file tests the parser's performance on Processing Instructions.
4# Sourcing this file into Tcl runs the tests and generates output
5# for errors.  No output means no errors were found.
6#
7# Copyright (c) 1998-2000 Zveno Pty Ltd.
8#
9# $Id: pi.test,v 1.4 2002/07/28 23:20:37 rolf Exp $
10
11source [file join [file dir [info script]] loadtdom.tcl]
12
13catch {unset result}
14proc PI {target data args} {
15    lappend ::result $target $data
16}
17
18test pi-1.1 {PI} {
19    set ::result {}
20
21    catch {rename xml::pi-1.1 {}}
22    set parser [xml::parser pi-1.1 \
23	-processinginstructioncommand PI]
24    $parser parse {<?xml version="1.0"?>
25<!DOCTYPE Test>
26<Test><?Test This is a processing instruction?></Test>
27}
28    set ::result
29} {Test {This is a processing instruction}}
30
31test pi-1.2 {PI: missing trailing ?} {
32    set ::result {}
33
34    catch {rename xml::pi-1.2 {}}
35    set parser [xml::parser pi-1.2 \
36	-processinginstructioncommand PI]
37    set returncode [catch {$parser parse {<?xml version="1.0"?>
38<!DOCTYPE Test>
39<Test><?Test This is a syntax error></Test>
40}} msg]
41
42    list $returncode [regexp {error "unclosed token" at.+} $msg]
43} {1 1}
44
45test pi-2.1 {PI with special characters} {
46    set ::result {}
47
48    catch {rename xml::pi-2.1 {}}
49    set parser [xml::parser pi-2.1 \
50	-processinginstructioncommand PI]
51    $parser parse {<?xml version="1.0"?>
52<!DOCTYPE Test>
53<Test><?Test [if !VMLRender]?></Test>
54}
55    set ::result
56} {Test {[if !VMLRender]}}
57
58foreach parser [info commands pi-*] {
59    $parser free
60}
61
62# cleanup
63::tcltest::cleanupTests
64return
65