# 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-2001 Zveno Pty Ltd. # # $Id: xpath.test,v 1.6 2002/06/14 12:16:24 balls Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { source [file join [pwd] [file dirname [info script]] defs.tcl] } if {[catch {package require xpath 1.0}]} { catch {puts stderr "Cannot load xpath 1.0 package"} return } # Full syntax tests test xpath-1.1 {Location path} { xpath::split child::para } {{child para {}}} test xpath-1.2 {Location path} { xpath::split child::* } {{child * {}}} test xpath-1.3 {Location path} { xpath::split child::text() } {{child {text ()} {}}} test xpath-1.4 {Location path} { xpath::split child::node() } {{child {node ()} {}}} test xpath-1.5 {Location path} { xpath::split attribute::name } {{attribute name {}}} test xpath-1.6 {Location path} { xpath::split attribute::* } {{attribute * {}}} test xpath-1.7 {Location path} { xpath::split descendant::para } {{descendant para {}}} test xpath-1.8 {Location path} { xpath::split ancestor::div } {{ancestor div {}}} test xpath-1.9 {Location path} { xpath::split ancestor-or-self::div } {{ancestor-or-self div {}}} test xpath-1.10 {Location path} { xpath::split descendant-or-self::para } {{descendant-or-self para {}}} test xpath-1.11 {Location path} { xpath::split self::para } {{self para {}}} test xpath-1.12 {Location path} { xpath::split child::chapter/descendant::para } {{child chapter {}} {descendant para {}}} test xpath-1.13 {Location path} { xpath::split child::*/child::para } {{child * {}} {child para {}}} test xpath-1.14 {Location path} { xpath::split / } {{}} test xpath-1.15 {Location path} { xpath::split /descendant::para } {{} {descendant para {}}} test xpath-1.16 {Location path} { xpath::split /descendant::olist/child::item } {{} {descendant olist {}} {child item {}}} test xpath-1.17 {Location path} { xpath::split {child::para[position()=1]} } {{child para {{= {function position {}} {number 1}}}}} test xpath-1.18 {Location path} { xpath::split {child::para[position()=last()]} } {{child para {{= {function position {}} {function last {}}}}}} test xpath-1.19 {Location path} { xpath::split {child::para[position()=last()-1]} } {{child para {{expr - = {function position {}} {function last {}} {number 1}}}}} test xpath-1.20 {Location path} { xpath::split {child::para[position()=last()>1]} } {{child para {{> = {function position {}} {function last {}} {number 1}}}}} test xpath-1.21 {Location path} { xpath::split {following-sibling::chapter[position()=1]} } {{following-sibling chapter {{= {function position {}} {number 1}}}}} test xpath-1.22 {Location path} { xpath::split {/child::doc/child::chapter[position()=5]/child::section[position()=2]} } {{} {child doc {}} {child chapter {{= {function position {}} {number 5}}}} {child section {{= {function position {}} {number 2}}}}} test xpath-1.23 {Location path} { xpath::split {child::para[attribute::type="warning"]} } {{child para {{= {path {{attribute type {}}}} {literal warning}}}}} test xpath-1.24 {Location path} { xpath::split {child::para[attribute::type='warning'][position()=5]} } {{child para {{= {path {{attribute type {}}}} {literal warning}} {= {function position {}} {number 5}}}}} test xpath-1.25 {Location path} { xpath::split {child::chapter[child::title='Introduction']} } {{child chapter {{= {path {{child title {}}}} {literal Introduction}}}}} test xpath-1.26 {Location path} { xpath::split {child::chapter[child::title]} } {{child chapter {{{path {{child title {}}}}}}}} test xpath-1.27 {Location path} { xpath::split {child::*[self::chapter or self::appendix]} } {{child * {{or {path {{self chapter {}}}} {path {{self appendix {}}}}}}}} test xpath-1.28 {Location path} { xpath::split {child::*[self::chapter/child::appendix]} } {{child * {{{path {{self chapter {}} {child appendix {}}}}}}}} # Abbreviated syntax tests test xpath-2.1 {Abbreviated location path} { xpath::split {/article/listitem[7]/itemizedlist/text()} } {{} {child article {}} {child listitem {{= {function position {}} {number 7}}}} {child itemizedlist {}} {child {text ()} {}}} test xpath-2.2 {Location step after predicate using location path} { xpath::split {/article/listitem[@Id='xyz']/itemizedlist/text()} } {{} {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} { xpath::split {//key[text()="foo"]} } {{} {descendant-or-self key {{= {path {child {text ()} {}}} {literal foo}}}}} # cleanup ::tcltest::cleanupTests return