File: namespace.test

package info (click to toggle)
tclxml 3.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,080 kB
  • ctags: 876
  • sloc: ansic: 6,064; tcl: 5,116; xml: 4,642; sh: 3,112; makefile: 60
file content (108 lines) | stat: -rw-r--r-- 3,333 bytes parent folder | download | duplicates (2)
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
# Features covered:  XML Namespaces
#
# This file contains a collection of tests for the TclXML parser.
# This file tests the parser's performance on XML namespaces.
# Sourcing this file into Tcl runs the tests and generates output
# for errors.  No output means no errors were found.
#
# Copyright (c) 2000-2004 Zveno Pty Ltd.
#
# $Id: namespace.test,v 1.4 2004/02/20 09:15:52 balls Exp $

package require tcltest
source [file join [tcltest::workingDirectory] tclxmlutils.tcl]

testPackage $::tcltest::parser

namespace eval ::xml::namespaceTest {
    namespace import -force ::tcltest::*

    variable SETUP {
	variable result {}
	variable nsdecls {}

	proc keysort args {
	    array set keyvalue $args
	    set result {}
	    foreach key [lsort [array names keyvalue]] {
		lappend result $key $keyvalue($key)
	    }
	    return $result
	}

	proc EStart {tag attlist args} {
	    variable result
	    variable nsdecls

	    array set extra $args

	    catch {eval lappend nsdecls $extra(-namespacedecls)}

	    if {[info exists extra(-namespace)]} {
		lappend result $extra(-namespace)^$tag
	    } else {
		lappend result $tag
	    }
	}

	set parser [xml::parser \
		-elementstartcommand [namespace code EStart]]
    }
    variable CLEANUP {
	catch {unset result}
	catch {unset nsdecls}
	rename keysort {}
	rename EStart {}
	$parser free
    }

    test ns-1.1 {Namespace declaration} -setup $SETUP -constraints {!xml_libxml2} -body {
	$parser parse {<?xml version="1.0"?>
<Test xmlns:test="http://www.zveno.com/Schemas"></Test>
}
	list $result $nsdecls
    } -cleanup $CLEANUP -result {Test {http://www.zveno.com/Schemas test}}

    test ns-1.2 {Multiple namespace declarations} -setup $SETUP -constraints {!xml_libxml2} -body {
	$parser parse {<?xml version="1.0"?>
<Test xmlns:test="http://www.zveno.com/Schemas"
xmlns:x='urn:schema'></Test>
}
	list $result [eval keysort $nsdecls]
    } -cleanup $CLEANUP -result {Test {http://www.zveno.com/Schemas test urn:schema x}}

    test ns-1.3 {Default namespace declaration} -setup $SETUP -constraints {!xml_libxml2} -body {
	$parser parse {<?xml version="1.0"?>
<Test xmlns="http://www.zveno.com/Schemas"
xmlns:x='urn:schema'></Test>
}
	list $result [eval keysort $nsdecls]
    } -cleanup $CLEANUP -result {http://www.zveno.com/Schemas^Test {http://www.zveno.com/Schemas {} urn:schema x}}

    test ns-1.4 {Default namespace declaration w/- separate usage} -setup $SETUP -constraints {!xml_libxml2} -body {
	$parser parse {<?xml version="1.0"?>
<x:Test xmlns="http://www.zveno.com/Schemas"
xmlns:x='urn:schema'><Test/></x:Test>
}
	list $result [eval keysort $nsdecls]
    } -cleanup $CLEANUP -result {{urn:schema^Test http://www.zveno.com/Schemas^Test} {http://www.zveno.com/Schemas {} urn:schema x}}

    test ns-2.0 {Multiple namespace declarations, same prefix} -setup $SETUP -constraints {!xml_libxml2} -body {
	$parser parse {<?xml version="1.0"?>
<Test>
  <x:Test xmlns:x="http://www.zveno.com/Schemas">
    <x:y/>
  </x:Test>
  <x:Test xmlns:x='urn:schema'>
    <x:z/>
  </x:Test>
</Test>
}
	list $result [eval keysort $nsdecls]
    } -cleanup $CLEANUP -result {{Test http://www.zveno.com/Schemas^Test http://www.zveno.com/Schemas^y urn:schema^Test urn:schema^z} {http://www.zveno.com/Schemas x urn:schema x}}

    cleanupTests
}

namespace delete ::xml::namespaceTest
return