File: xpath.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 (124 lines) | stat: -rw-r--r-- 5,500 bytes parent folder | download | duplicates (5)
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
# Features covered:  XPath
#
# This file contains a collection of tests for the XPath parser.
# 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: xpath.test,v 1.7 2003/12/03 20:06:37 balls Exp $

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

testPackage xpath

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

    # Full syntax tests

    test xpath-1.1 {Location path} -body {
	xpath::split child::para
    } -result {{child para {}}}
    test xpath-1.2 {Location path} -body {
	xpath::split child::*
    } -result {{child * {}}}
    test xpath-1.3 {Location path} -body {
	xpath::split child::text()
    } -result {{child {text ()} {}}}
    test xpath-1.4 {Location path} -body {
	xpath::split child::node()
    } -result {{child {node ()} {}}}
    test xpath-1.5 {Location path} -body {
	xpath::split attribute::name
    } -result {{attribute name {}}}
    test xpath-1.6 {Location path} -body {
	xpath::split attribute::*
    } -result {{attribute * {}}}
    test xpath-1.7 {Location path} -body {
	xpath::split descendant::para
    } -result {{descendant para {}}}
    test xpath-1.8 {Location path} -body {
	xpath::split ancestor::div
    } -result {{ancestor div {}}}
    test xpath-1.9 {Location path} -body {
	xpath::split ancestor-or-self::div
    } -result {{ancestor-or-self div {}}}
    test xpath-1.10 {Location path} -body {
	xpath::split descendant-or-self::para
    } -result {{descendant-or-self para {}}}
    test xpath-1.11 {Location path} -body {
	xpath::split self::para
    } -result {{self para {}}}
    test xpath-1.12 {Location path} -body {
	xpath::split child::chapter/descendant::para
    } -result {{child chapter {}} {descendant para {}}}
    test xpath-1.13 {Location path} -body {
	xpath::split child::*/child::para
    } -result {{child * {}} {child para {}}}
    test xpath-1.14 {Location path} -body {
	xpath::split /
    } -result {{}}
    test xpath-1.15 {Location path} -body {
	xpath::split /descendant::para
    } -result {{} {descendant para {}}}
    test xpath-1.16 {Location path} -body {
	xpath::split /descendant::olist/child::item
    } -result {{} {descendant olist {}} {child item {}}}
    test xpath-1.17 {Location path} -body {
	xpath::split {child::para[position()=1]}
    } -result {{child para {{= {function position {}} {number 1}}}}}
    test xpath-1.18 {Location path} -body {
	xpath::split {child::para[position()=last()]}
    } -result {{child para {{= {function position {}} {function last {}}}}}}
    test xpath-1.19 {Location path} -body {
	xpath::split {child::para[position()=last()-1]}
    } -result {{child para {{expr - = {function position {}} {function last {}} {number 1}}}}}
    test xpath-1.20 {Location path} -body {
	xpath::split {child::para[position()=last()>1]}
    } -result {{child para {{> = {function position {}} {function last {}} {number 1}}}}}
    test xpath-1.21 {Location path} -body {
	xpath::split {following-sibling::chapter[position()=1]}
    } -result {{following-sibling chapter {{= {function position {}} {number 1}}}}}
    test xpath-1.22 {Location path} -body {
	xpath::split {/child::doc/child::chapter[position()=5]/child::section[position()=2]}
    } -result {{} {child doc {}} {child chapter {{= {function position {}} {number 5}}}} {child section {{= {function position {}} {number 2}}}}}
    test xpath-1.23 {Location path} -body {
	xpath::split {child::para[attribute::type="warning"]}
    } -result {{child para {{= {path {{attribute type {}}}} {literal warning}}}}}
    test xpath-1.24 {Location path} -body {
	xpath::split {child::para[attribute::type='warning'][position()=5]}
    } -result {{child para {{= {path {{attribute type {}}}} {literal warning}} {= {function position {}} {number 5}}}}}
    test xpath-1.25 {Location path} -body {
	xpath::split {child::chapter[child::title='Introduction']}
    } -result {{child chapter {{= {path {{child title {}}}} {literal Introduction}}}}}
    test xpath-1.26 {Location path} -body {
	xpath::split {child::chapter[child::title]}
    } -result {{child chapter {{{path {{child title {}}}}}}}}
    test xpath-1.27 {Location path} -body {
	xpath::split {child::*[self::chapter or 
self::appendix]}
    } -result {{child * {{or {path {{self chapter {}}}} {path {{self appendix {}}}}}}}}
    test xpath-1.28 {Location path} -body {
	xpath::split {child::*[self::chapter/child::appendix]}
    } -result {{child * {{{path {{self chapter {}} {child appendix {}}}}}}}}

    # Abbreviated syntax tests

    test xpath-2.1 {Abbreviated location path} -body {
	xpath::split {/article/listitem[7]/itemizedlist/text()}
    } -result {{} {child article {}} {child listitem {{= {function position {}} {number 7}}}} {child itemizedlist {}} {child {text ()} {}}}
    test xpath-2.2 {Location step after predicate using location path} -body {
	xpath::split {/article/listitem[@Id='xyz']/itemizedlist/text()}
    } -result {{} {child article {}} {child listitem {{= {path {{attribute Id {}}}} {literal xyz}}}} {child itemizedlist {}} {child {text ()} {}}}
    # Test for bug #568354 contributed by Marshall Rose
    test xpath-2.3 {Location step with node type test in predicate} -body {
	xpath::split {//key[text()="foo"]}
    } -result {{} {descendant-or-self key {{= {path {child {text ()} {}}} {literal foo}}}}}

    cleanupTests
}

namespace delete ::xml::xpathTest
return