Bug #14600 » test-rexml.patch
| lib/rexml/attribute.rb | ||
|---|---|---|
| 
         # The element to which this attribute belongs 
   | 
||
| 
         attr_reader :element 
   | 
||
| 
         # Set parent equal to element  2017-11 Should Attribute have this property? 
   | 
||
| 
         def parent ; @element ; end 
   | 
||
| 
     | 
||
| 
         # The normalized value of this attribute.  That is, the attribute with 
   | 
||
| 
         # entities intact. 
   | 
||
| 
         attr_writer :normalized 
   | 
||
| test/rexml/data/test/tests.xml | ||
|---|---|---|
| 
     <?xml version="1.0" encoding="UTF-8"?> 
   | 
||
| 
     <tests xmlns:var="http://jaxen.org/test-harness/var"> 
   | 
||
| 
         <!-- test for jaxen-24 --> 
   | 
||
| 
        <document url="xml/jaxen24.xml"> 
   | 
||
| 
        <document url="jaxen24.xml"> 
   | 
||
| 
            <context select="/body/div"> 
   | 
||
| 
                <test select="preceding::*[1]" count="1"/> 
   | 
||
| 
                <valueOf select="local-name(preceding::*[1])">span</valueOf> 
   | 
||
| ... | ... | |
| 
        </document> 
   | 
||
| 
         <!-- test for jaxen-3 --> 
   | 
||
| 
       <document url="xml/simple.xml"> 
   | 
||
| 
       <document url="simple.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <valueOf select="string()">abd</valueOf> 
   | 
||
| 
         </context> 
   | 
||
| ... | ... | |
| 
         <!-- test for jaxen-3 --> 
   | 
||
| 
       <document url="xml/jaxen3.xml"> 
   | 
||
| 
       <document url="jaxen3.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="/Configuration/hostname/attrlist/hostname[. = 'CE-A'] " count="1"/> 
   | 
||
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
         <!-- parser test cases all of which should fail--> 
   | 
||
| 
       <document url="xml/numbers.xml"> 
   | 
||
| 
     <!--2017-11  <document url="numbers.xml"> --> 
   | 
||
| 
       <document> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
             <!-- repeated xpaths, jaxen-35 --> 
   | 
||
| 
           <test exception="true" select="/numbers numbers" count="0"/> 
   | 
||
| 
     | 
||
| 
             <!-- invalid xpath, jaxen-34 --> 
   | 
||
| 
           <test exception="true" select="/a/b[c > d]efg" count="0"/> 
   | 
||
| 
             <!-- invalid xpath, jaxen-27 --> 
   | 
||
| 
           <test exception="true" select="/inv/child::" count="0"/> 
   | 
||
| 
             <!-- invalid xpath, jaxen-26 --> 
   | 
||
| 
     	<!-- 
   | 
||
| 
     <!-- 
   | 
||
| 
           <test exception="true" select="/invoice/@test[abcd" count="0"/> 
   | 
||
| 
           <test exception="true" select="/invoice/@test[abcd > x" count="0"/> 
   | 
||
| 
           <test exception="true" select="string-length('a" count="0"/> 
   | 
||
| 
           <test exception="true" select="/descendant::()" count="0"/> 
   | 
||
| 
           <test exception="true" select="(1 + 1" count="0"/> 
   | 
||
| 
           --> 
   | 
||
| 
     --> 
   | 
||
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <!-- test cases for the use of underscores in names --> 
   | 
||
| 
       <document url="xml/underscore.xml"> 
   | 
||
| 
       <document url="underscore.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="/root/@a" count="1"/> 
   | 
||
| 
           <test select="/root/@_a" count="1"/> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <!-- test cases for the use of = with nodesets --> 
   | 
||
| 
       <document url="xml/web.xml"> 
   | 
||
| 
       <document url="web.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <valueOf select="/web-app/servlet/servlet-name = 'file'">true</valueOf> 
   | 
||
| 
           <valueOf select="/web-app/servlet/servlet-name = 'snoop'">true</valueOf> 
   | 
||
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/numbers.xml"> 
   | 
||
| 
       <document url="numbers.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <valueOf select="/numbers/set/nr = '-3'">true</valueOf> 
   | 
||
| 
           <valueOf select="/numbers/set/nr = -3">true</valueOf> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <!-- test basic math... --> 
   | 
||
| 
       <document url="xml/numbers.xml"> 
   | 
||
| 
       <document url="numbers.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <valueOf select="(8 * 2 + 1) = 17">true</valueOf> 
   | 
||
| 
           <valueOf select="(1 + 8 * 2) = 17">true</valueOf> 
   | 
||
| ... | ... | |
| 
           <valueOf select="1 = 2 = 2">false</valueOf> 
   | 
||
| 
             <!--  2!=(3!=1) => 2!=1 => true, (2!=3)!=1 => 1!=1 => false --> 
   | 
||
| 
           <valueOf select="2 != 3 != 1">false</valueOf> 
   | 
||
| 
             <!-- 3 > (2 > 1) is true --> 
   | 
||
| 
     <!-- 2017-11 
   | 
||
| 
              3 > (2 > 1) is true 
   | 
||
| 
           <valueOf select="3 > 2 > 1">false</valueOf> 
   | 
||
| 
             <!-- 3 >= (2 >= 2) is true --> 
   | 
||
| 
              3 >= (2 >= 2) is true 
   | 
||
| 
           <valueOf select="3 >= 2 >= 2">false</valueOf> 
   | 
||
| 
             <!-- 1 < (2 < 3) is false --> 
   | 
||
| 
              1 < (2 < 3) is false 
   | 
||
| 
           <valueOf select="1 < 2 < 3">true</valueOf> 
   | 
||
| 
             <!-- 0 <= (2 <= 3) is true --> 
   | 
||
| 
              0 <= (2 <= 3) is true 
   | 
||
| 
           <valueOf select="2 <= 2 <= 3">true</valueOf> 
   | 
||
| 
     --> 
   | 
||
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <!-- test cases for preceding axis with different node types --> 
   | 
||
| 
       <document url="xml/pi2.xml"> 
   | 
||
| 
       <document url="pi2.xml"> 
   | 
||
| 
         <context select="/a/c"> 
   | 
||
| 
           <test select="//processing-instruction()" count="1"/> 
   | 
||
| 
           <test select="preceding-sibling::*" count="1"/> 
   | 
||
| ... | ... | |
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/id.xml"> 
   | 
||
| 
       <document url="id.xml"> 
   | 
||
| 
         <context select="/" 
   | 
||
| 
     	     var:foobar="foobar" 
   | 
||
| 
     	     var:foo="foo"> 
   | 
||
| ... | ... | |
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/id.xml"> 
   | 
||
| 
       <document url="id.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <!-- attributes have a parent: their element --> 
   | 
||
| 
           <test select="/foo/@id/parent::foo" count="1"/> 
   | 
||
| ... | ... | |
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/pi.xml"> 
   | 
||
| 
       <document url="pi.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="//processing-instruction()" count="3"/> 
   | 
||
| 
           <test select="//processing-instruction('cheese')" count="2"/> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <!-- test evaluate() extension function --> 
   | 
||
| 
       <document url="xml/evaluate.xml"> 
   | 
||
| 
       <document url="evaluate.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="evaluate('//jumps/*')" count="3"/> 
   | 
||
| 
           <test select="evaluate('//jumps/object/dog')" count="1"/> 
   | 
||
| ... | ... | |
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
     | 
||
| 
       <document url="xml/numbers.xml"> 
   | 
||
| 
       <document url="numbers.xml"> 
   | 
||
| 
         <context select="/numbers/set[1]"> 
   | 
||
| 
           <test select="*[-3 = .]" count="1"/> 
   | 
||
| 
           <valueOf select="54 < *">true</valueOf> 
   | 
||
| ... | ... | |
| 
       <!-- test sibling axes --> 
   | 
||
| 
       <document url="xml/axis.xml"> 
   | 
||
| 
       <document url="axis.xml"> 
   | 
||
| 
         <context select="/root"> 
   | 
||
| 
           <test select="preceding-sibling::*" count="0"/> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <document url="xml/web.xml"> 
   | 
||
| 
       <document url="web.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <valueOf select="/web-app/servlet[1]/servlet-name">snoop</valueOf> 
   | 
||
| ... | ... | |
| 
       <!-- test name --> 
   | 
||
| 
       <document url="xml/web.xml"> 
   | 
||
| 
       <document url="web.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
     | 
||
| 
           <test select="*" count="1"> 
   | 
||
| ... | ... | |
| 
     	<valueOf select="name()">web-app</valueOf> 
   | 
||
| 
           </test> 
   | 
||
| 
           <test select="child::*" count="1"> 
   | 
||
| 
     	<valueOf select="name()">web-app</valueOf> 
   | 
||
| 
             <valueOf select="name()">web-app</valueOf> 
   | 
||
| 
           </test> 
   | 
||
| 
           <test select="/*" count="1"> 
   | 
||
| 
     	<valueOf select="name()">web-app</valueOf> 
   | 
||
| 
           </test> 
   | 
||
| 
           <test select="/child::node()" count="1"> 
   | 
||
| 
     	<valueOf select="name(.)">web-app</valueOf> 
   | 
||
| 
             <valueOf select="name()">web-app</valueOf> 
   | 
||
| 
           </test> 
   | 
||
| 
     <!-- 2017-11 
   | 
||
| 
           <test select="child::node()" count="1"> 
   | 
||
| 
     	<valueOf select="name(.)">web-app</valueOf> 
   | 
||
| 
             <valueOf select="name(.)">web-app</valueOf> 
   | 
||
| 
           </test> 
   | 
||
| 
     --> 
   | 
||
| 
           <!-- empty names --> 
   | 
||
| 
           <valueOf select="name()"></valueOf> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <!-- test predicates --> 
   | 
||
| 
       <document url="xml/nitf.xml"> 
   | 
||
| 
       <document url="nitf.xml"> 
   | 
||
| 
         <context select="/nitf/head/docdata"> 
   | 
||
| 
           <test select="doc-id[@regsrc='AP' and @id-string='D76UIMO80']" count="1"/> 
   | 
||
| 
         </context> 
   | 
||
| 
         <context select="/nitf/head"> 
   | 
||
| 
           <test select="meta[@name='ap-cycle']" count="1"/> 
   | 
||
| 
           <test select="meta[@content='AP']" count="1"/> 
   | 
||
| 
           <test select="meta[@name and @content]" count="8"/> 
   | 
||
| 
           <test select="meta[@content]" count="8"/> 
   | 
||
| 
           <test select="meta[@name]" count="8"/> 
   | 
||
| 
     <!-- 2017-11      <test select="meta[@name or @content]" count="8"/>  --> 
   | 
||
| 
     <!-- 2017-11      <test select="meta[@name and @content]" count="8"/> --> 
   | 
||
| 
           <test select="meta[@name='ap-cycle' and @content='AP']" count="1"/> 
   | 
||
| 
           <test select="meta[@name != 'ap-cycle']" count="7"/> 
   | 
||
| 
         </context> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="/nitf/head/meta[@name='ap-cycle']" count="1"/> 
   | 
||
| 
           <test select="/nitf/head/meta[@content='AP']" count="1"/> 
   | 
||
| 
           <test select="/nitf/head/meta[@name and @content]" count="8"/> 
   | 
||
| 
     <!-- 2017-11      <test select="/nitf/head/meta[@name and @content]" count="8"/> --> 
   | 
||
| 
           <test select="/nitf/head/meta[@name='ap-cycle' and @content='AP']" count="1"/> 
   | 
||
| 
           <test select="/nitf/head/meta[@name != 'ap-cycle']" count="7"/> 
   | 
||
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/moreover.xml"> 
   | 
||
| 
       <document url="moreover.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="/child::node()" count="1"/> 
   | 
||
| 
     <!-- 2017-11      <test select="/child::node()" count="1"/>  --> 
   | 
||
| 
           <test select="/*" count="1"/> 
   | 
||
| 
           <test select="/*/article" count="20"/> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <!-- test other node types--> 
   | 
||
| 
       <document url="xml/contents.xml"> 
   | 
||
| 
       <document url="contents.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="processing-instruction()" count="3"/> 
   | 
||
| 
           <test select="/processing-instruction()" count="3"/> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <!-- test positioning --> 
   | 
||
| 
       <document url="xml/fibo.xml"> 
   | 
||
| 
       <document url="fibo.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="/*/fibonacci[position() < 10]" count="9"/> 
   | 
||
| 
           <valueOf select="sum(//fibonacci)">196417</valueOf> 
   | 
||
| ... | ... | |
| 
       <!-- test Axes --> 
   | 
||
| 
       <document url="xml/web.xml"> 
   | 
||
| 
       <document url="web.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="descendant-or-self::*" count="19"/> 
   | 
||
| 
           <test select="descendant::*" count="19"/> 
   | 
||
| ... | ... | |
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/much_ado.xml"> 
   | 
||
| 
       <document url="much_ado.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="/descendant::ACT" count="5"/> 
   | 
||
| 
           <test select="descendant::ACT" count="5"/> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <!-- test axis node ordering --> 
   | 
||
| 
       <document url="xml/web.xml"> 
   | 
||
| 
       <document url="web.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <!-- Reported as Jira issue JAXEN-24 --> 
   | 
||
| 
           <test select="//servlet-mapping/preceding::*[1][name()='description']" count="1"/> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
     | 
||
| 
       <!-- test document function --> 
   | 
||
| 
       <document url="xml/text.xml"> 
   | 
||
| 
       <document url="text.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="document('xml/web.xml')" count="1"> 
   | 
||
| 
     	<valueOf select="/web-app/servlet[1]/servlet-name">snoop</valueOf> 
   | 
||
| 
     	<valueOf select="/web-app/servlet[1]/servlet-name/text()">snoop</valueOf> 
   | 
||
| 
     <!-- 2107-11 
   | 
||
| 
           <test select="document('data/web.xml')" count="1"> 
   | 
||
| 
             <valueOf select="/web-app/servlet[1]/servlet-name">snoop</valueOf> 
   | 
||
| 
             <valueOf select="/web-app/servlet[1]/servlet-name/text()">snoop</valueOf> 
   | 
||
| 
           </test> 
   | 
||
| 
           <valueOf select="document('xml/web.xml')/web-app/servlet[1]/servlet-name">snoop</valueOf> 
   | 
||
| 
     --> 
   | 
||
| 
           <valueOf select="document('data/web.xml')/web-app/servlet[1]/servlet-name">snoop</valueOf> 
   | 
||
| 
         </context> 
   | 
||
| 
         <!-- Test to check if the context changes when an extension function is used. 
   | 
||
| 
         First test is an example, second is the actual test. 
   | 
||
| 
         --> 
   | 
||
| 
         <context select="/foo/bar/cheese[1]"> 
   | 
||
| 
           <valueOf select="concat(./@id,'foo',@id)">3foo3</valueOf> 
   | 
||
| 
           <valueOf select="concat(./@id,document('xml/web.xml')/web-app/servlet[1]/servlet-name,./@id)">3snoop3</valueOf> 
   | 
||
| 
           <valueOf select="concat(./@id,document('data/web.xml')/web-app/servlet[1]/servlet-name,./@id)">3snoop3</valueOf> 
   | 
||
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/message.xml"> 
   | 
||
| 
       <document url="message.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <valueOf select="/message/body/data/items/item[name/text()='parentinfo']/value">Pruefgebiete</valueOf> 
   | 
||
| 
           <valueOf select="document('xml/message.xml')/message/body/data/items/item[name/text()='parentinfo']/value">Pruefgebiete</valueOf> 
   | 
||
| 
           <valueOf select="document('data/message.xml')/message/body/data/items/item[name/text()='parentinfo']/value">Pruefgebiete</valueOf> 
   | 
||
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/simple.xml"> 
   | 
||
| 
       <document url="simple.xml"> 
   | 
||
| 
         <!-- test behaviour of AbsoluteLocationPath --> 
   | 
||
| 
         <context select="/root/a"> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <!-- test cases for String extension functions --> 
   | 
||
| 
       <document url="xml/web.xml"> 
   | 
||
| 
       <document url="web.xml"> 
   | 
||
| 
         <context select="/web-app/servlet[1]"> 
   | 
||
| 
           <valueOf select="upper-case( servlet-class )">SNOOPSERVLET</valueOf> 
   | 
||
| 
           <valueOf select="lower-case( servlet-class )">snoopservlet</valueOf> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <!-- test cases for the lang() function --> 
   | 
||
| 
       <document url="xml/lang.xml"> 
   | 
||
| 
       <document url="lang.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="/e1/e2[lang('hr')]" count="0"/> 
   | 
||
| 
           <test select="/e1/e2/e3[lang('en')]" count="1"/> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <!-- test namespace --> 
   | 
||
| 
       <document url="xml/namespaces.xml"> 
   | 
||
| 
       <document url="namespaces.xml"> 
   | 
||
| 
         <context select="/" 
   | 
||
| 
     	     xmlns:foo="http://fooNamespace/" 
   | 
||
| 
     	     xmlns:voo="http://fooNamespace/" 
   | 
||
| 
     	     xmlns:bar="http://barNamespace/" 
   | 
||
| 
     	     xmlns:alias="http://fooNamespace/"> 
   | 
||
| 
            xmlns:foo="http://fooNamespace/" 
   | 
||
| 
            xmlns:voo="http://fooNamespace/" 
   | 
||
| 
            xmlns:bar="http://barNamespace/" 
   | 
||
| 
            xmlns:alias="http://fooNamespace/"> 
   | 
||
| 
           <test select="/*" count="1"/> 
   | 
||
| 
           <test select="/foo:a" count="1"/> 
   | 
||
| 
           <test select="/foo:a/b" count="1"/> 
   | 
||
| ... | ... | |
| 
       </document> 
   | 
||
| 
       <document url="xml/defaultNamespace.xml"> 
   | 
||
| 
       <document url="defaultNamespace.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <!-- NOTE: /a/b/c selects elements in no namespace only! --> 
   | 
||
| 
           <test select="/a/b/c" count="0"/> 
   | 
||
| ... | ... | |
| 
           <test select="/x:a/x:b/x:c" count="0" exception="true"/> 
   | 
||
| 
           --> 
   | 
||
| 
         </context> 
   | 
||
| 
         <context select="/" 
   | 
||
| 
     	     xmlns:dummy="http://dummyNamespace/"> 
   | 
||
| 
         <context select="/" xmlns:dummy="http://dummyNamespace/"> 
   | 
||
| 
           <test select="/dummy:a/dummy:b/dummy:c" count="1"/> 
   | 
||
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/text.xml"> 
   | 
||
| 
       <document url="text.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <test select="/foo/bar/text()" count="3"/> 
   | 
||
| 
           <valueOf select="normalize-space(/foo/bar/text())">baz</valueOf> 
   | 
||
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/testNamespaces.xml"> 
   | 
||
| 
       <document url="testNamespaces.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <!-- the root is not an element, so no namespaces --> 
   | 
||
| 
           <test select="namespace::*" count="0" debug="off"/> 
   | 
||
| 
           <test select="/namespace::*" count="0" debug="off"/> 
   | 
||
| 
     <!-- 2017-11 
   | 
||
| 
           <test select="/Template/Application1/namespace::*" count="3" debug="off"/> 
   | 
||
| 
           <test select="/Template/Application2/namespace::*" count="3" debug="off"/> 
   | 
||
| 
           <test select="//namespace::*" count="25" debug="off"/> 
   | 
||
| 
     --> 
   | 
||
| 
         </context> 
   | 
||
| 
         <!-- 
   | 
||
| ... | ... | |
| 
         </context> 
   | 
||
| 
       --> 
   | 
||
| 
       </document> 
   | 
||
| 
       <document url="xml/testNamespaces.xml"> 
   | 
||
| 
     <!-- 2017-11 
   | 
||
| 
       <document url="testNamespaces.xml"> 
   | 
||
| 
         <context select="/"> 
   | 
||
| 
           <!-- namespace nodes have their element as their parent --> 
   | 
||
| 
           namespace nodes have their element as their parent 
   | 
||
| 
           <test select="/Template/namespace::xml/parent::Template" count="1"/> 
   | 
||
| 
         </context> 
   | 
||
| 
         <!-- namespace nodes can also be used as context nodes --> 
   | 
||
| 
         namespace nodes can also be used as context nodes 
   | 
||
| 
         <context select="/Template/namespace::xml"> 
   | 
||
| 
           <test select="parent::Template" count="1"/> 
   | 
||
| 
         </context> 
   | 
||
| 
       </document> 
   | 
||
| 
     --> 
   | 
||
| 
     </tests> 
   | 
||
| test/rexml/test_jaxen.rb | ||
|---|---|---|
| 
     # frozen_string_literal: false 
   | 
||
| 
     # frozen_string_literal: true 
   | 
||
| 
     require_relative 'rexml_test_utils' 
   | 
||
| 
     require "rexml/document" 
   | 
||
| ... | ... | |
| 
         include REXMLTestUtils 
   | 
||
| 
         include REXML 
   | 
||
| 
         def test_axis ; test("axis") ; end 
   | 
||
| 
         def test_basic ; test("basic") ; end 
   | 
||
| 
         def test_basicupdate ; test("basicupdate") ; end 
   | 
||
| 
         def test_contents ; test("contents") ; end 
   | 
||
| 
         def initialize(name) 
   | 
||
| 
           super 
   | 
||
| 
           @fname = nil 
   | 
||
| 
           @test_doc = File.open(File.join(__dir__, "data/test/tests.xml")) do |file| 
   | 
||
| 
             Document.new(file) 
   | 
||
| 
           end 
   | 
||
| 
         end 
   | 
||
| 
         # 3 commented out tests do not have a matching /tests/document node in tests.xml 
   | 
||
| 
     | 
||
| 
         def test_axis             ; test("axis")             ; end 
   | 
||
| 
     #    def test_basic            ; test("basic")            ; end 
   | 
||
| 
     #    def test_basicupdate      ; test("basicupdate")      ; end 
   | 
||
| 
         def test_contents         ; test("contents")         ; end 
   | 
||
| 
         def test_defaultNamespace ; test("defaultNamespace") ; end 
   | 
||
| 
         def test_fibo ; test("fibo") ; end 
   | 
||
| 
         def test_id ; test("id") ; end 
   | 
||
| 
         def test_jaxen24 ; test("jaxen24") ; end 
   | 
||
| 
         def test_lang ; test("lang") ; end 
   | 
||
| 
         def test_message ; test("message") ; end 
   | 
||
| 
         def test_moreover ; test("moreover") ; end 
   | 
||
| 
         def test_much_ado ; test("much_ado") ; end 
   | 
||
| 
         def test_namespaces ; test("namespaces") ; end 
   | 
||
| 
         def test_nitf ; test("nitf") ; end 
   | 
||
| 
         def test_numbers ; test("numbers") ; end 
   | 
||
| 
         def test_pi ; test("pi") ; end 
   | 
||
| 
         def test_pi2 ; test("pi2") ; end 
   | 
||
| 
         def test_simple ; test("simple") ; end 
   | 
||
| 
         def test_testNamespaces ; test("testNamespaces") ; end 
   | 
||
| 
         def test_text ; test("text") ; end 
   | 
||
| 
         def test_underscore ; test("underscore") ; end 
   | 
||
| 
         def test_web ; test("web") ; end 
   | 
||
| 
         def test_web2 ; test("web2") ; end 
   | 
||
| 
         def test_fibo             ; test("fibo")             ; end 
   | 
||
| 
         def test_id               ; test("id")               ; end 
   | 
||
| 
         def test_jaxen24          ; test("jaxen24")          ; end 
   | 
||
| 
         def test_lang             ; test("lang")             ; end 
   | 
||
| 
         def test_message          ; test("message")          ; end 
   | 
||
| 
         def test_moreover         ; test("moreover")         ; end 
   | 
||
| 
         def test_much_ado         ; test("much_ado")         ; end 
   | 
||
| 
         def test_namespaces       ; test("namespaces")       ; end 
   | 
||
| 
         def test_nitf             ; test("nitf")             ; end 
   | 
||
| 
         def test_numbers          ; test("numbers")          ; end 
   | 
||
| 
         def test_pi               ; test("pi")               ; end 
   | 
||
| 
         def test_pi2              ; test("pi2")              ; end 
   | 
||
| 
         def test_simple           ; test("simple")           ; end 
   | 
||
| 
         def test_testNamespaces   ; test("testNamespaces")   ; end 
   | 
||
| 
         def test_text             ; test("text")             ; end 
   | 
||
| 
         def test_underscore       ; test("underscore")       ; end 
   | 
||
| 
         def test_web              ; test("web")              ; end 
   | 
||
| 
     #    def test_web2             ; test("web2")             ; end 
   | 
||
| 
         private 
   | 
||
| 
         def test( fname ) 
   | 
||
| 
     #      Dir.entries( xml_dir ).each { |fname| 
   | 
||
| 
     #        if fname =~ /\.xml$/ 
   | 
||
| 
               doc = File.open(fixture_path(fname+".xml")) do |file| 
   | 
||
| 
                 Document.new(file) 
   | 
||
| 
               end 
   | 
||
| 
               XPath.each( doc, "/tests/document" ) {|e| handleDocument(e)} 
   | 
||
| 
     #        end 
   | 
||
| 
     #      } 
   | 
||
| 
           @fname = fname 
   | 
||
| 
           testDoc = File.open(fixture_path("#{fname}.xml")) { |file| Document.new(file) } 
   | 
||
| 
           XPath.each( @test_doc, "/tests/document[@url='#{fname}.xml']" ) {|e| handleDocument(e, testDoc) } 
   | 
||
| 
         end 
   | 
||
| 
         # processes a tests/document node 
   | 
||
| 
         def handleDocument(docElement, testDoc) 
   | 
||
| 
           XPath.each( docElement, "context") { |e| handleContext(testDoc, e) } 
   | 
||
| 
         end 
   | 
||
| 
         # processes a tests/document/context node 
   | 
||
| 
         def handleContext( testDoc, ctxElement) 
   | 
||
| 
           testCtx = XPath.match( testDoc, ctxElement.attributes["select"] )[0] 
   | 
||
| 
           namespaces = {} 
   | 
||
| 
           namespaces = ctxElement.namespaces 
   | 
||
| 
           if testCtx.class == Element 
   | 
||
| 
             testCtx.prefixes.each { |pre| handleNamespace( testCtx, pre, namespaces ) } 
   | 
||
| 
           end 
   | 
||
| 
           variables = {} 
   | 
||
| 
           XPath.each( ctxElement, "@*[namespace-uri() = 'http://jaxen.org/test-harness/var']") { |attrib| handleVariable(testCtx, variables, attrib) } 
   | 
||
| 
           XPath.each( ctxElement, "valueOf") { |e| handleValueOf(testCtx, variables, namespaces, e) } 
   | 
||
| 
           XPath.each( ctxElement, "test[not(@exception) or (@exception != 'true') ]") { |e| handleNominalTest(testCtx,variables, namespaces, e) } 
   | 
||
| 
           XPath.each( ctxElement, "test[@exception = 'true']") { |e| handleExceptionalTest(testCtx,variables, namespaces, e) } 
   | 
||
| 
           XPath.each( ctxElement, "@*[namespace-uri() = 'http://jaxen.org/test-harness/var']") { |attrib| 
   | 
||
| 
             handleVariable(testCtx, variables, attrib) } 
   | 
||
| 
           XPath.each( ctxElement, "valueOf") { |e| 
   | 
||
| 
             handleValueOf(testCtx, variables, namespaces, e) } 
   | 
||
| 
           XPath.each( ctxElement, "test[not(@exception) or (@exception != 'true') ]") { |e| 
   | 
||
| 
             handleNominalTest(testCtx,variables, namespaces, e) } 
   | 
||
| 
           XPath.each( ctxElement, "test[@exception = 'true']") { |e| 
   | 
||
| 
             handleExceptionalTest(testCtx, variables, namespaces, e ) } 
   | 
||
| 
         end 
   | 
||
| 
         # processes a tests/document/context/valueOf or tests/document/context/test/valueOf node 
   | 
||
| 
         def handleValueOf(ctx,variables, namespaces, valueOfElement) 
   | 
||
| 
           expected = valueOfElement.text 
   | 
||
| 
           got = XPath.match( ctx, valueOfElement.attributes["select"], namespaces, variables )[0] 
   | 
||
| 
           assert_true( (got.nil? && expected.nil?) || !got.nil? ) 
   | 
||
| 
           # 2017-11 Below change just for absolute path, may not be needed 
   | 
||
| 
           xpath_select = valueOfElement.attributes["select"] 
   | 
||
| 
           xpath_select.sub!(/document\('data\//, "document('#{File.join(__dir__, 'data')}/") 
   | 
||
| 
           match = XPath.match( ctx, xpath_select, namespaces, variables ) 
   | 
||
| 
           got = match.is_a?(Array) ? match[0] : match 
   | 
||
| 
           assert( (got.nil? && expected.nil?) || !got.nil? ) 
   | 
||
| 
           case got.class 
   | 
||
| 
           when Element 
   | 
||
| 
             assert_equal( got.class, Element ) 
   | 
||
| ... | ... | |
| 
           when Integer 
   | 
||
| 
             assert_equal( exected.to_f, got ) 
   | 
||
| 
           when String 
   | 
||
| 
             # normalize values for comparison 
   | 
||
| 
             got = "" if got == nil or got == "" 
   | 
||
| 
             expected = "" if expected == nil or expected == "" 
   | 
||
| 
             assert_equal( expected, got ) 
   | 
||
| 
           else 
   | 
||
| 
             assert_fail( "Wassup?" ) 
   | 
||
| 
             assert_equal( expected || "", got || "") 
   | 
||
| 
     #      else 
   | 
||
| 
     #        refute( true, got.class.to_s ) unless String === got 
   | 
||
| 
           end 
   | 
||
| 
         end 
   | 
||
| 
         # processes a tests/document/context/test node ( where @exception is false or doesn't exist ) 
   | 
||
| 
         def handleNominalTest(ctx, variables, namespaces, testElement) 
   | 
||
| 
           expected = testElement.attributes["count"] 
   | 
||
| 
           got = XPath.match( ctx, testElement.attributes["select"], namespaces, variables ) 
   | 
||
| 
           xpath = testElement.attributes["select"] 
   | 
||
| 
           got = XPath.match( ctx, xpath, namespaces, variables ) 
   | 
||
| 
           # might be a test with no count attribute, but nested valueOf elements 
   | 
||
| 
           assert( expected == got.size.to_s ) if !expected.nil? 
   | 
||
| 
           msg = "Count XPath #{xpath}  #{@fname}.xml" 
   | 
||
| 
           assert_equal(expected, got.size.to_s, msg ) if !expected.nil? 
   | 
||
| 
           XPath.each( testElement, "valueOf") { |e| 
   | 
||
| 
             handleValueOf(got, variables, namespaces, e) 
   | 
||
| ... | ... | |
| 
         # processes a tests/document/context/test node ( where @exception is true ) 
   | 
||
| 
         def handleExceptionalTest(ctx, variables, namespaces, testElement) 
   | 
||
| 
           assert_raise( Exception ) { 
   | 
||
| 
             XPath.match( ctx, testElement.attributes["select"], namespaces, variables ) 
   | 
||
| 
           } 
   | 
||
| 
         end 
   | 
||
| 
         # processes a tests/document node 
   | 
||
| 
         def handleDocument(docElement) 
   | 
||
| 
           puts "- Processing document: #{docElement.attributes['url']}" 
   | 
||
| 
           testFile = File.new( docElement.attributes["url"] ) 
   | 
||
| 
           testDoc = Document.new testFile 
   | 
||
| 
           XPath.each( docElement, "context") { |e| handleContext(testDoc, e) } 
   | 
||
| 
           select = testElement.attributes["select"] 
   | 
||
| 
           match = XPath.match( ctx, select, namespaces, variables ) 
   | 
||
| 
           assert_raise( Exception, select ) { match } 
   | 
||
| 
         end 
   | 
||
| 
         # processes a variable definition in a namespace like <test var:foo="bar"> 
   | 
||
| 
         def handleVariable( ctx, variables, attrib ) 
   | 
||
| 
           puts "--- Found attribute: #{attrib.name}" 
   | 
||
| 
           # STDERR.puts "--- Found attribute: #{attrib.name}" 
   | 
||
| 
           variables[attrib.name] = attrib.value 
   | 
||
| 
         end 
   | 
||
| 
         # processes a namespace definition like <test xmlns:foo="fiz:bang:bam"> 
   | 
||
| 
         def handleNamespace( ctx, prefix, namespaces ) 
   | 
||
| 
           puts "--- Found namespace: #{prefix}" 
   | 
||
| 
           # STDERR.puts "--- Found namespace: #{prefix}" 
   | 
||
| 
           namespaces[prefix] = ctx.namespaces[prefix] 
   | 
||
| 
         end 
   | 
||
| test/rexml/test_listener.rb | ||
|---|---|---|
| 
     require 'rexml/streamlistener' 
   | 
||
| 
     module REXMLTests 
   | 
||
| 
       class BaseTester < Test::Unit::TestCase 
   | 
||
| 
       class REXMLTester < Test::Unit::TestCase 
   | 
||
| 
         include REXMLTestUtils 
   | 
||
| 
         def setup 
   | 
||
| 
           @listener = MyREXMLListener.new 
   | 
||
| 
         end 
   | 
||
| 
         def test_character_reference_2 
   | 
||
| 
           t6 = %Q{<string>
</string>} 
   | 
||
| 
           assert_equal( t6.strip, REXML::Document.new(t6).to_s ) 
   | 
||
| 
         end 
   | 
||
| 
         def test_empty 
   | 
||
| 
           return unless defined? @listener 
   | 
||
| 
           # Empty. 
   | 
||
| ... | ... | |
| 
           @text << text 
   | 
||
| 
         end 
   | 
||
| 
       end 
   | 
||
| 
       class REXMLTester < BaseTester 
   | 
||
| 
         def setup 
   | 
||
| 
           @listener = MyREXMLListener.new 
   | 
||
| 
         end 
   | 
||
| 
         def test_character_reference_2 
   | 
||
| 
           t6 = %Q{<string>
</string>} 
   | 
||
| 
           assert_equal( t6.strip, REXML::Document.new(t6).to_s ) 
   | 
||
| 
         end 
   | 
||
| 
       end 
   | 
||
| 
     end 
   | 
||