1#------------------------------------------------------------------------------
2# file: rexml_test.rb
3# desc: test's REXML's XML/XPath implementation
4# auth: Philip J Grabner <grabner>at<uberdev>dot<org>
5# date: 2006/08/17
6# copy: (C) CopyLoose 2006 Bib Development Team <bib-devel>at<uberdev>dot<org>
7#------------------------------------------------------------------------------
8
9require 'test/unit'
10require 'rexml/document'
11
12class Ticket80 < Test::Unit::TestCase
13
14  @@xmlstr = '<?xml version="1.0"?>
15<root xmlns="urn:some-xml-ns" xmlns:other="urn:some-other-xml-ns">
16 <l1-foo>
17  <l2 value="foo-01"/>
18  <l2 value="foo-02"/>
19  <l2 value="foo-03"/>
20 </l1-foo>
21 <other:l1>
22  <l2 value="no-show"/>
23 </other:l1>
24 <l1-bar>
25  <l2 value="bar-01"/>
26  <l2 value="bar-02"/>
27 </l1-bar>
28</root>'
29
30  #----------------------------------------------------------------------------
31  def test_xpathNamespacedChildWildcard
32    # tests the "prefix:*" node test syntax
33    out = Array.new
34    REXML::XPath.each( REXML::Document.new(@@xmlstr),
35                       '/ns:root/ns:*/ns:l2/@value',
36                       { 'ns' => 'urn:some-xml-ns' } ) do |node| out.push node.value ; end
37    chk = [ 'foo-01', 'foo-02', 'foo-03', 'bar-01', 'bar-02' ]
38    assert_equal chk, out
39  end
40
41  #----------------------------------------------------------------------------
42  def test_xpathNamespacedChildWildcardWorkaround
43    # tests a workaround for the "prefix:*" node test syntax
44    out = Array.new
45    REXML::XPath.each( REXML::Document.new(@@xmlstr),
46                       '/ns:root/*[namespace-uri()="urn:some-xml-ns"]/ns:l2/@value',
47                       { 'ns' => 'urn:some-xml-ns' } ) do |node| out.push node.value ; end
48    chk = [ 'foo-01', 'foo-02', 'foo-03', 'bar-01', 'bar-02' ]
49    assert_equal chk, out
50  end
51
52end
53
54#------------------------------------------------------------------------------
55# end of rexml_test.rb
56#------------------------------------------------------------------------------
57