scxml 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +0 -0
- data/lib/scxml.rb +86 -0
- data/lib/scxml/document.rb +165 -0
- data/lib/scxml/element.rb +219 -0
- data/lib/scxml/xpath.rb +142 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate01.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate02.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate03.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate04.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate12.out +4 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate13.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate41.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate42.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate45.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate51.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate52.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate56.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate57.out +5 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate58.out +11 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select01.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select02.out +4 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select03.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select04.out +14 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select12.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select13.out +13 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select41.out +5 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select42.out +5 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select45.out +5 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select51.out +5 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select52.out +3 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select56.out +7 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select57.out +7 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select58.out +5 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select60.out +5 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select62.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select63.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select76.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select81.out +10 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select82.out +2 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select83.out +7 -0
- data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select84.out +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate01.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate01.xml +7 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate01.xsl +18 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate02.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate02.xml +7 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate02.xsl +18 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate04.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate04.xml +7 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate04.xsl +18 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate07.txt +9 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate07.xml +7 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate07.xsl +20 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate08.txt +9 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate08.xml +7 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate08.xsl +20 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate10.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate10.xml +7 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate10.xsl +20 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate14.txt +9 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate14.xml +9 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate14.xsl +20 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate15.txt +9 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate15.xml +9 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate15.xsl +20 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate16.txt +9 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate16.xml +9 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate16.xsl +20 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate17.txt +9 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate17.xml +11 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate17.xsl +20 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate36.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate36.xml +7 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate36.xsl +20 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate48.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate48.xml +21 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate48.xsl +22 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate49.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate49.xml +21 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate49.xsl +22 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate50.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate50.xml +21 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate50.xsl +22 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate51.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate51.xml +21 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate51.xsl +22 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate52.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate52.xml +21 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate52.xsl +22 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate53.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate53.xml +21 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate53.xsl +22 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate54.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate54.xml +21 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate54.xsl +21 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate55.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate55.xml +21 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate55.xsl +22 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate56.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate56.xml +21 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/predicate56.xsl +22 -0
- data/test/scxml/Xalan_Conformance_Tests/predicate/prepare.rb +34 -0
- data/test/scxml/Xalan_Conformance_Tests/select/prepare.rb +34 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select01.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select01.xml +9 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select01.xsl +19 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select02.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select02.xml +4 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select02.xsl +17 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select03.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select03.xml +13 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select03.xsl +19 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select04.txt +12 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select04.xml +12 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select04.xsl +35 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select12.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select12.xml +9 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select12.xsl +19 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select13.txt +13 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select13.xml +18 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select13.xsl +33 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select41.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select41.xml +9 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select41.xsl +23 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select42.txt +8 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select42.xml +9 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select42.xsl +26 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select45.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select45.xml +24 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select45.xsl +25 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select51.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select51.xml +24 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select51.xsl +25 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select52.txt +6 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select52.xml +6 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select52.xsl +23 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select56.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select56.xml +29 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select56.xsl +25 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select57.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select57.xml +29 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select57.xsl +25 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select58.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select58.xml +17 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select58.xsl +25 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select60.txt +6 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select60.xml +9 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select60.xsl +25 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select62.txt +6 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select62.xml +5 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select62.xsl +22 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select63.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select63.xml +10 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select63.xsl +19 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select76.txt +7 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select76.xml +6 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select76.xsl +17 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select81.txt +9 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select81.xml +6 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select81.xsl +24 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select82.txt +9 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select82.xml +5 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select82.xsl +28 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select83.txt +10 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select83.xml +10 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select83.xsl +32 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select84.txt +11 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select84.xml +10 -0
- data/test/scxml/Xalan_Conformance_Tests/select/select84.xsl +33 -0
- data/test/scxml/document_test.rb +231 -0
- data/test/scxml/element_test.rb +552 -0
- data/test/scxml_test_helper.rb +73 -0
- data/test/scxml_test_suite.rb +2 -0
- metadata +241 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
3
|
+
|
4
|
+
<!-- FileName: select76 -->
|
5
|
+
<!-- Document: http://www.w3.org/TR/xslt -->
|
6
|
+
<!-- DocVersion: 19991116 -->
|
7
|
+
<!-- Section: 5.2 -->
|
8
|
+
<!-- Creator: David Marston -->
|
9
|
+
<!-- Purpose: Try /{name} to match the document element. -->
|
10
|
+
|
11
|
+
<xsl:template match="/Q">
|
12
|
+
<out>
|
13
|
+
<xsl:value-of select="@level"/>
|
14
|
+
</out>
|
15
|
+
</xsl:template>
|
16
|
+
|
17
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
3
|
+
|
4
|
+
<!-- FileName: select81 -->
|
5
|
+
<!-- Document: http://www.w3.org/TR/xpath -->
|
6
|
+
<!-- DocVersion: 19991116 -->
|
7
|
+
<!-- Section: 2.5 -->
|
8
|
+
<!-- Creator: Joe Kesselman -->
|
9
|
+
<!-- Purpose: Try absolute path when current node is in middle of tree -->
|
10
|
+
|
11
|
+
<xsl:output method="xml" indent="no" encoding="UTF-8"/>
|
12
|
+
|
13
|
+
<xsl:template match="/">
|
14
|
+
<out>
|
15
|
+
<xsl:apply-templates select="/para/font[@color='green']" />
|
16
|
+
</out>
|
17
|
+
</xsl:template>
|
18
|
+
|
19
|
+
<xsl:template match="font">
|
20
|
+
<rel><xsl:apply-templates select="..//text()" /></rel>
|
21
|
+
<abs><xsl:apply-templates select="//text()" /></abs>
|
22
|
+
</xsl:template>
|
23
|
+
|
24
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
3
|
+
|
4
|
+
<!-- FileName: select82 -->
|
5
|
+
<!-- Document: http://www.w3.org/TR/xpath -->
|
6
|
+
<!-- DocVersion: 19991116 -->
|
7
|
+
<!-- Section: 2.5 -->
|
8
|
+
<!-- Creator: David Marston -->
|
9
|
+
<!-- Purpose: Test //* to get all elements -->
|
10
|
+
|
11
|
+
<xsl:output method="xml" indent="no" encoding="UTF-8"/>
|
12
|
+
|
13
|
+
<xsl:template match="/">
|
14
|
+
<out>
|
15
|
+
<xsl:apply-templates select="/doc/b/bb/bbb" />
|
16
|
+
</out>
|
17
|
+
</xsl:template>
|
18
|
+
|
19
|
+
<xsl:template match="bbb">
|
20
|
+
<list><xsl:apply-templates select="//*" mode="list"/></list>
|
21
|
+
</xsl:template>
|
22
|
+
|
23
|
+
<xsl:template match="*" mode="list">
|
24
|
+
<xsl:value-of select="name()" />
|
25
|
+
<xsl:text>|</xsl:text>
|
26
|
+
</xsl:template>
|
27
|
+
|
28
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
3
|
+
|
4
|
+
<!-- FileName: select83 -->
|
5
|
+
<!-- Document: http://www.w3.org/TR/xpath -->
|
6
|
+
<!-- DocVersion: 19991116 -->
|
7
|
+
<!-- Section: 2.5 -->
|
8
|
+
<!-- Creator: David Marston -->
|
9
|
+
<!-- Purpose: Test //@x to get all attributes of a certain name -->
|
10
|
+
|
11
|
+
<xsl:output method="xml" indent="no" encoding="UTF-8"/>
|
12
|
+
|
13
|
+
<xsl:template match="/">
|
14
|
+
<out>
|
15
|
+
<xsl:apply-templates select="/doc/b/bb/bbb" />
|
16
|
+
</out>
|
17
|
+
</xsl:template>
|
18
|
+
|
19
|
+
<xsl:template match="bbb">
|
20
|
+
<list><xsl:apply-templates select="//@x"/></list>
|
21
|
+
</xsl:template>
|
22
|
+
|
23
|
+
<xsl:template match="@x">
|
24
|
+
<xsl:text>
|
25
|
+
Node </xsl:text>
|
26
|
+
<xsl:value-of select="name(..)" />
|
27
|
+
<xsl:text> has </xsl:text>
|
28
|
+
<xsl:value-of select="." />
|
29
|
+
<xsl:text> in @x</xsl:text>
|
30
|
+
</xsl:template>
|
31
|
+
|
32
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
3
|
+
|
4
|
+
<!-- FileName: select84 -->
|
5
|
+
<!-- Document: http://www.w3.org/TR/xpath -->
|
6
|
+
<!-- DocVersion: 19991116 -->
|
7
|
+
<!-- Section: 2.5 -->
|
8
|
+
<!-- Creator: David Marston -->
|
9
|
+
<!-- Purpose: Test //@* to get all attributes in the tree -->
|
10
|
+
|
11
|
+
<xsl:output method="xml" indent="no" encoding="UTF-8"/>
|
12
|
+
|
13
|
+
<xsl:template match="/">
|
14
|
+
<out>
|
15
|
+
<xsl:apply-templates select="/doc/b/bb/bbb" />
|
16
|
+
</out>
|
17
|
+
</xsl:template>
|
18
|
+
|
19
|
+
<xsl:template match="bbb">
|
20
|
+
<list><xsl:apply-templates select="//@*"/></list>
|
21
|
+
</xsl:template>
|
22
|
+
|
23
|
+
<xsl:template match="@*">
|
24
|
+
<xsl:text>
|
25
|
+
Node </xsl:text>
|
26
|
+
<xsl:value-of select="name(..)" />
|
27
|
+
<xsl:text> has </xsl:text>
|
28
|
+
<xsl:value-of select="." />
|
29
|
+
<xsl:text> in @</xsl:text>
|
30
|
+
<xsl:value-of select="name(.)" />
|
31
|
+
</xsl:template>
|
32
|
+
|
33
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,231 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../scxml_test_helper')
|
2
|
+
|
3
|
+
class DocumentTest < Test::Unit::TestCase
|
4
|
+
include SCXML
|
5
|
+
include Benchmark
|
6
|
+
|
7
|
+
#
|
8
|
+
# initialization tests
|
9
|
+
#
|
10
|
+
|
11
|
+
def test_initialize
|
12
|
+
cases = [
|
13
|
+
"<root></root>",
|
14
|
+
"<root><inner></inner></root>",
|
15
|
+
"\n<root>\n <inner>\n a\n </inner>\n</root>\n"]
|
16
|
+
|
17
|
+
cases.each do |str|
|
18
|
+
doc = Document.new(str)
|
19
|
+
assert_equal str, doc.string
|
20
|
+
assert_equal 'root', doc.root.name, "#{doc.string} => #{doc.content_range}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_initialize_with_blank_string
|
25
|
+
doc = Document.new('')
|
26
|
+
assert_equal '', doc.content
|
27
|
+
assert_equal nil, doc.root.name
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_initialize_removing_whitespace
|
31
|
+
cases = {
|
32
|
+
"\n<root>\n <inner>\n a\n </inner>\n</root>\n" => "<root><inner>a</inner></root>"}
|
33
|
+
|
34
|
+
cases.each_pair do |str, expected|
|
35
|
+
doc = Document.new(str, :remove_whitespace => true)
|
36
|
+
assert_equal expected, doc.content
|
37
|
+
assert_equal 'root', doc.root.name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
#
|
43
|
+
# content tests
|
44
|
+
#
|
45
|
+
|
46
|
+
def test_content
|
47
|
+
cases = {
|
48
|
+
%Q{<?xml version="1.0"?>\n<doc>\n</doc>.\n} => "<doc>\n</doc>",
|
49
|
+
%Q{<?xml version="1.0"?>\n<doc/>\n} => "<doc/>",
|
50
|
+
%Q{<doc><a></a></doc>} => "<doc><a></a></doc>",
|
51
|
+
%Q{<doc><a/></doc>} => "<doc><a/></doc>",
|
52
|
+
%Q{} => ""}
|
53
|
+
|
54
|
+
cases.each_pair do |string, expected|
|
55
|
+
doc = Document.new(string)
|
56
|
+
assert_equal expected, doc.content,"#{doc.string} => #{doc.content_range}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# nodes test
|
62
|
+
#
|
63
|
+
|
64
|
+
def test_node_names
|
65
|
+
cases = {
|
66
|
+
%Q{<?xml version="1.0"?>\n<doc>\n</doc>\n} => ['doc'],
|
67
|
+
%Q{<doc><a></a></doc>} => ['doc', 'a'],
|
68
|
+
# test results unique when in sequence
|
69
|
+
%Q{<doc><a></a><a></a></doc>} => ['doc', 'a'],
|
70
|
+
# test results unique when nested
|
71
|
+
%Q{<doc><a><a></a></a></doc>} => ['doc', 'a']}
|
72
|
+
|
73
|
+
cases.each_pair do |string, expected|
|
74
|
+
doc = Document.new(string)
|
75
|
+
assert_equal expected, doc.node_names, string
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# tableize tests
|
81
|
+
#
|
82
|
+
|
83
|
+
def table_xml
|
84
|
+
input = ""
|
85
|
+
x = Builder::XmlMarkup.new :target => input
|
86
|
+
x.root {
|
87
|
+
x.headers {
|
88
|
+
0.upto(2) { |j| x.header("header #{j}") }
|
89
|
+
}
|
90
|
+
x.rows {
|
91
|
+
0.upto(2) { |i|
|
92
|
+
x.row('i'=>i) {
|
93
|
+
x.cols {
|
94
|
+
0.upto(2) { |j| x.col("#{i}#{j}", 'j'=>j) }
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
input
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_tableize
|
104
|
+
doc = Document.new(table_xml)
|
105
|
+
table = doc.tableize(:row => '//row', :col => 'cols/col')
|
106
|
+
|
107
|
+
expected = "00\t01\t02\n" + "10\t11\t12\n" + "20\t21\t22\n"
|
108
|
+
assert_equal expected, table
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_tableize_with_index
|
112
|
+
doc = Document.new(table_xml)
|
113
|
+
table = doc.tableize(:row => '//row', :col => 'cols/col', :index => true)
|
114
|
+
|
115
|
+
expected = "0\t00\t01\t02\n" + "1\t10\t11\t12\n" + "2\t20\t21\t22\n"
|
116
|
+
assert_equal expected, table
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_tableize_with_headers
|
120
|
+
doc = Document.new(table_xml)
|
121
|
+
table = doc.tableize(
|
122
|
+
:row => '//row',
|
123
|
+
:col => 'cols/col',
|
124
|
+
:header_row => '/root/headers',
|
125
|
+
:header_col => 'header')
|
126
|
+
|
127
|
+
expected = "header 0\theader 1\theader 2\n" + "00\t01\t02\n" + "10\t11\t12\n" + "20\t21\t22\n"
|
128
|
+
assert_equal expected, table
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_tableize_with_block
|
132
|
+
doc = Document.new(table_xml)
|
133
|
+
table = doc.tableize(
|
134
|
+
:row => '//row',
|
135
|
+
:col => 'cols/col',
|
136
|
+
:header_row => '/root/headers',
|
137
|
+
:header_col => 'header') do |row, cols|
|
138
|
+
if row.name == 'headers'
|
139
|
+
cols.collect {|col| col.content}
|
140
|
+
else
|
141
|
+
cols.collect {|col| "col #{col.attributes['j']}"}
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
expected = "header 0\theader 1\theader 2\n" + "col 0\tcol 1\tcol 2\n" + "col 0\tcol 1\tcol 2\n" + "col 0\tcol 1\tcol 2\n"
|
146
|
+
assert_equal expected, table
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# Xalan tests
|
151
|
+
#
|
152
|
+
|
153
|
+
def ds
|
154
|
+
@ds ||= Prosperity::DirectoryStructure.new(
|
155
|
+
File.join( File.dirname(__FILE__), 'Xalan_Conformance_Tests' ),
|
156
|
+
:predicate => 'predicate',
|
157
|
+
:select => 'select',
|
158
|
+
:result => 'REF_OUT')
|
159
|
+
end
|
160
|
+
|
161
|
+
def xalan_base(type, n)
|
162
|
+
"#{type}#{n < 10 ? 0 : ''}#{n}"
|
163
|
+
end
|
164
|
+
|
165
|
+
def xalan_root
|
166
|
+
File.join(File.dirname(__FILE__), 'Xalan_Conformance_Tests')
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_file(type, base)
|
170
|
+
File.join(xalan_root, type, base +'.txt')
|
171
|
+
end
|
172
|
+
|
173
|
+
def xml_file(type, base)
|
174
|
+
File.join(xalan_root, type, base +'.xml')
|
175
|
+
end
|
176
|
+
|
177
|
+
def expected_file(type, base)
|
178
|
+
File.join(xalan_root, 'REF_OUT', type, base +'.out')
|
179
|
+
end
|
180
|
+
|
181
|
+
def xalan_test(type, n, &block)
|
182
|
+
base = xalan_base(type, n)
|
183
|
+
statements = File.read(test_file(type, base)).split(/\r?\n/).select {|line| line =~ /^[^#]/}
|
184
|
+
xml = File.read(xml_file(type, base))
|
185
|
+
|
186
|
+
result = yield(xml, *statements)
|
187
|
+
expected = File.read(expected_file(type, base))
|
188
|
+
|
189
|
+
assert_equal expected.strip, result.strip, "#{base} => [#{statements.join(',')}]"
|
190
|
+
#%Q{<?xml version="1.0" encoding="UTF-8"?>}
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_xalan_select
|
194
|
+
# THESE TESTS ARE INCOMPLETELY IMPLEMENTED
|
195
|
+
# only the cases named below are actually run.
|
196
|
+
select_cases = [1]#[1, 2, 3, 4, 12, 13, 41, 42, 45, 51, 52, 56, 57, 58, 60, 62, 63, 76, 81, 83, 82, 84]
|
197
|
+
|
198
|
+
select_cases.each do |n|
|
199
|
+
xalan_test('select', n) do |xml, xpath|
|
200
|
+
doc = Document.new(xml)
|
201
|
+
selected = doc.select(xpath)
|
202
|
+
|
203
|
+
result = ""
|
204
|
+
xml = Builder::XmlMarkup.new( :target => result, :indent => 2 )
|
205
|
+
xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
|
206
|
+
|
207
|
+
if selected.length > 1
|
208
|
+
xml.out do
|
209
|
+
selected.each do |s|
|
210
|
+
if s.kind_of?(Element)
|
211
|
+
xml.tag!(s.name, s.content, s.attributes)
|
212
|
+
else
|
213
|
+
xml << s.to_s
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
else
|
218
|
+
s = selected.first
|
219
|
+
if s.kind_of?(Element)
|
220
|
+
xml.out do
|
221
|
+
xml.tag!(s.name, s.content, s.attributes)
|
222
|
+
end
|
223
|
+
else
|
224
|
+
xml.out( s.to_s )
|
225
|
+
end
|
226
|
+
end
|
227
|
+
result
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|