scxml 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/README +0 -0
  2. data/lib/scxml.rb +86 -0
  3. data/lib/scxml/document.rb +165 -0
  4. data/lib/scxml/element.rb +219 -0
  5. data/lib/scxml/xpath.rb +142 -0
  6. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate01.out +2 -0
  7. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate02.out +2 -0
  8. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate03.out +2 -0
  9. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate04.out +2 -0
  10. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate12.out +4 -0
  11. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate13.out +2 -0
  12. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate41.out +2 -0
  13. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate42.out +2 -0
  14. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate45.out +2 -0
  15. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate51.out +2 -0
  16. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate52.out +2 -0
  17. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate56.out +2 -0
  18. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate57.out +5 -0
  19. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/predicate/predicate58.out +11 -0
  20. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select01.out +2 -0
  21. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select02.out +4 -0
  22. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select03.out +2 -0
  23. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select04.out +14 -0
  24. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select12.out +2 -0
  25. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select13.out +13 -0
  26. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select41.out +5 -0
  27. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select42.out +5 -0
  28. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select45.out +5 -0
  29. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select51.out +5 -0
  30. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select52.out +3 -0
  31. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select56.out +7 -0
  32. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select57.out +7 -0
  33. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select58.out +5 -0
  34. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select60.out +5 -0
  35. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select62.out +2 -0
  36. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select63.out +2 -0
  37. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select76.out +2 -0
  38. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select81.out +10 -0
  39. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select82.out +2 -0
  40. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select83.out +7 -0
  41. data/test/scxml/Xalan_Conformance_Tests/REF_OUT/select/select84.out +8 -0
  42. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate01.txt +8 -0
  43. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate01.xml +7 -0
  44. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate01.xsl +18 -0
  45. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate02.txt +8 -0
  46. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate02.xml +7 -0
  47. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate02.xsl +18 -0
  48. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate04.txt +8 -0
  49. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate04.xml +7 -0
  50. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate04.xsl +18 -0
  51. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate07.txt +9 -0
  52. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate07.xml +7 -0
  53. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate07.xsl +20 -0
  54. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate08.txt +9 -0
  55. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate08.xml +7 -0
  56. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate08.xsl +20 -0
  57. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate10.txt +8 -0
  58. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate10.xml +7 -0
  59. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate10.xsl +20 -0
  60. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate14.txt +9 -0
  61. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate14.xml +9 -0
  62. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate14.xsl +20 -0
  63. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate15.txt +9 -0
  64. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate15.xml +9 -0
  65. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate15.xsl +20 -0
  66. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate16.txt +9 -0
  67. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate16.xml +9 -0
  68. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate16.xsl +20 -0
  69. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate17.txt +9 -0
  70. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate17.xml +11 -0
  71. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate17.xsl +20 -0
  72. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate36.txt +8 -0
  73. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate36.xml +7 -0
  74. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate36.xsl +20 -0
  75. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate48.txt +8 -0
  76. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate48.xml +21 -0
  77. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate48.xsl +22 -0
  78. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate49.txt +8 -0
  79. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate49.xml +21 -0
  80. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate49.xsl +22 -0
  81. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate50.txt +8 -0
  82. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate50.xml +21 -0
  83. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate50.xsl +22 -0
  84. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate51.txt +8 -0
  85. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate51.xml +21 -0
  86. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate51.xsl +22 -0
  87. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate52.txt +8 -0
  88. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate52.xml +21 -0
  89. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate52.xsl +22 -0
  90. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate53.txt +8 -0
  91. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate53.xml +21 -0
  92. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate53.xsl +22 -0
  93. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate54.txt +7 -0
  94. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate54.xml +21 -0
  95. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate54.xsl +21 -0
  96. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate55.txt +8 -0
  97. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate55.xml +21 -0
  98. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate55.xsl +22 -0
  99. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate56.txt +8 -0
  100. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate56.xml +21 -0
  101. data/test/scxml/Xalan_Conformance_Tests/predicate/predicate56.xsl +22 -0
  102. data/test/scxml/Xalan_Conformance_Tests/predicate/prepare.rb +34 -0
  103. data/test/scxml/Xalan_Conformance_Tests/select/prepare.rb +34 -0
  104. data/test/scxml/Xalan_Conformance_Tests/select/select01.txt +7 -0
  105. data/test/scxml/Xalan_Conformance_Tests/select/select01.xml +9 -0
  106. data/test/scxml/Xalan_Conformance_Tests/select/select01.xsl +19 -0
  107. data/test/scxml/Xalan_Conformance_Tests/select/select02.txt +7 -0
  108. data/test/scxml/Xalan_Conformance_Tests/select/select02.xml +4 -0
  109. data/test/scxml/Xalan_Conformance_Tests/select/select02.xsl +17 -0
  110. data/test/scxml/Xalan_Conformance_Tests/select/select03.txt +8 -0
  111. data/test/scxml/Xalan_Conformance_Tests/select/select03.xml +13 -0
  112. data/test/scxml/Xalan_Conformance_Tests/select/select03.xsl +19 -0
  113. data/test/scxml/Xalan_Conformance_Tests/select/select04.txt +12 -0
  114. data/test/scxml/Xalan_Conformance_Tests/select/select04.xml +12 -0
  115. data/test/scxml/Xalan_Conformance_Tests/select/select04.xsl +35 -0
  116. data/test/scxml/Xalan_Conformance_Tests/select/select12.txt +7 -0
  117. data/test/scxml/Xalan_Conformance_Tests/select/select12.xml +9 -0
  118. data/test/scxml/Xalan_Conformance_Tests/select/select12.xsl +19 -0
  119. data/test/scxml/Xalan_Conformance_Tests/select/select13.txt +13 -0
  120. data/test/scxml/Xalan_Conformance_Tests/select/select13.xml +18 -0
  121. data/test/scxml/Xalan_Conformance_Tests/select/select13.xsl +33 -0
  122. data/test/scxml/Xalan_Conformance_Tests/select/select41.txt +7 -0
  123. data/test/scxml/Xalan_Conformance_Tests/select/select41.xml +9 -0
  124. data/test/scxml/Xalan_Conformance_Tests/select/select41.xsl +23 -0
  125. data/test/scxml/Xalan_Conformance_Tests/select/select42.txt +8 -0
  126. data/test/scxml/Xalan_Conformance_Tests/select/select42.xml +9 -0
  127. data/test/scxml/Xalan_Conformance_Tests/select/select42.xsl +26 -0
  128. data/test/scxml/Xalan_Conformance_Tests/select/select45.txt +7 -0
  129. data/test/scxml/Xalan_Conformance_Tests/select/select45.xml +24 -0
  130. data/test/scxml/Xalan_Conformance_Tests/select/select45.xsl +25 -0
  131. data/test/scxml/Xalan_Conformance_Tests/select/select51.txt +7 -0
  132. data/test/scxml/Xalan_Conformance_Tests/select/select51.xml +24 -0
  133. data/test/scxml/Xalan_Conformance_Tests/select/select51.xsl +25 -0
  134. data/test/scxml/Xalan_Conformance_Tests/select/select52.txt +6 -0
  135. data/test/scxml/Xalan_Conformance_Tests/select/select52.xml +6 -0
  136. data/test/scxml/Xalan_Conformance_Tests/select/select52.xsl +23 -0
  137. data/test/scxml/Xalan_Conformance_Tests/select/select56.txt +7 -0
  138. data/test/scxml/Xalan_Conformance_Tests/select/select56.xml +29 -0
  139. data/test/scxml/Xalan_Conformance_Tests/select/select56.xsl +25 -0
  140. data/test/scxml/Xalan_Conformance_Tests/select/select57.txt +7 -0
  141. data/test/scxml/Xalan_Conformance_Tests/select/select57.xml +29 -0
  142. data/test/scxml/Xalan_Conformance_Tests/select/select57.xsl +25 -0
  143. data/test/scxml/Xalan_Conformance_Tests/select/select58.txt +7 -0
  144. data/test/scxml/Xalan_Conformance_Tests/select/select58.xml +17 -0
  145. data/test/scxml/Xalan_Conformance_Tests/select/select58.xsl +25 -0
  146. data/test/scxml/Xalan_Conformance_Tests/select/select60.txt +6 -0
  147. data/test/scxml/Xalan_Conformance_Tests/select/select60.xml +9 -0
  148. data/test/scxml/Xalan_Conformance_Tests/select/select60.xsl +25 -0
  149. data/test/scxml/Xalan_Conformance_Tests/select/select62.txt +6 -0
  150. data/test/scxml/Xalan_Conformance_Tests/select/select62.xml +5 -0
  151. data/test/scxml/Xalan_Conformance_Tests/select/select62.xsl +22 -0
  152. data/test/scxml/Xalan_Conformance_Tests/select/select63.txt +7 -0
  153. data/test/scxml/Xalan_Conformance_Tests/select/select63.xml +10 -0
  154. data/test/scxml/Xalan_Conformance_Tests/select/select63.xsl +19 -0
  155. data/test/scxml/Xalan_Conformance_Tests/select/select76.txt +7 -0
  156. data/test/scxml/Xalan_Conformance_Tests/select/select76.xml +6 -0
  157. data/test/scxml/Xalan_Conformance_Tests/select/select76.xsl +17 -0
  158. data/test/scxml/Xalan_Conformance_Tests/select/select81.txt +9 -0
  159. data/test/scxml/Xalan_Conformance_Tests/select/select81.xml +6 -0
  160. data/test/scxml/Xalan_Conformance_Tests/select/select81.xsl +24 -0
  161. data/test/scxml/Xalan_Conformance_Tests/select/select82.txt +9 -0
  162. data/test/scxml/Xalan_Conformance_Tests/select/select82.xml +5 -0
  163. data/test/scxml/Xalan_Conformance_Tests/select/select82.xsl +28 -0
  164. data/test/scxml/Xalan_Conformance_Tests/select/select83.txt +10 -0
  165. data/test/scxml/Xalan_Conformance_Tests/select/select83.xml +10 -0
  166. data/test/scxml/Xalan_Conformance_Tests/select/select83.xsl +32 -0
  167. data/test/scxml/Xalan_Conformance_Tests/select/select84.txt +11 -0
  168. data/test/scxml/Xalan_Conformance_Tests/select/select84.xml +10 -0
  169. data/test/scxml/Xalan_Conformance_Tests/select/select84.xsl +33 -0
  170. data/test/scxml/document_test.rb +231 -0
  171. data/test/scxml/element_test.rb +552 -0
  172. data/test/scxml_test_helper.rb +73 -0
  173. data/test/scxml_test_suite.rb +2 -0
  174. metadata +241 -0
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0"?>
2
+ <Q level="0">bad0
3
+ <Q level="1">bad1
4
+ <Q level="2">bad2</Q>
5
+ </Q>
6
+ </Q>
@@ -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,9 @@
1
+ # FileName: select81
2
+ # Document: http://www.w3.org/TR/xpath
3
+ # DocVersion: 19991116
4
+ # Section: 2.5
5
+ # Creator: Joe Kesselman
6
+ # Purpose: Try absolute path when current node is in middle of tree
7
+ /para/font[@color='green']
8
+ ..//text()
9
+ //text()
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0"?>
2
+ <para>
3
+ <font color='red'>Hello</font>
4
+ <font color='green'>There</font>
5
+ <font color='blue'>World</font>
6
+ </para>
@@ -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,9 @@
1
+ # FileName: select82
2
+ # Document: http://www.w3.org/TR/xpath
3
+ # DocVersion: 19991116
4
+ # Section: 2.5
5
+ # Creator: David Marston
6
+ # Purpose: Test //* to get all elements
7
+ /doc/b/bb/bbb
8
+ //*" mode="list
9
+ name()
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0"?>
2
+ <doc>1<a>in-a</a>2<!-- upper comment -->
3
+ <b>3<bb>4<bbb>5</bbb>6</bb>7</b>
4
+ <!-- lower comment -->8<c>in-c</c>9
5
+ </doc>
@@ -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,10 @@
1
+ # FileName: select83
2
+ # Document: http://www.w3.org/TR/xpath
3
+ # DocVersion: 19991116
4
+ # Section: 2.5
5
+ # Creator: David Marston
6
+ # Purpose: Test //@x to get all attributes of a certain name
7
+ /doc/b/bb/bbb
8
+ //@x
9
+ name(..)
10
+ .
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0"?>
2
+ <doc x="on-doc">
3
+ <a x="on-a">in-a</a>
4
+ <b x="on-b">
5
+ <bb NO="on-bb">
6
+ <bbb x="on-bbb"/>
7
+ </bb>
8
+ </b>
9
+ <c x="on-c">in-c</c>
10
+ </doc>
@@ -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,11 @@
1
+ # FileName: select84
2
+ # Document: http://www.w3.org/TR/xpath
3
+ # DocVersion: 19991116
4
+ # Section: 2.5
5
+ # Creator: David Marston
6
+ # Purpose: Test //@* to get all attributes in the tree
7
+ /doc/b/bb/bbb
8
+ //@*
9
+ name(..)
10
+ .
11
+ name(.)
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0"?>
2
+ <doc d="on-doc">
3
+ <a aa="on-a">in-a</a>
4
+ <b x="on-b">
5
+ <bb y="on-bb">
6
+ <bbb z="on-bbb"/>
7
+ </bb>
8
+ </b>
9
+ <c cc="on-c">in-c</c>
10
+ </doc>
@@ -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