Bug 1942639 - Propagate --filter argument from desktop_unittest.py to runreftest...
[gecko.git] / dom / xslt / tests / mochitest / test_exslt.html
blob739d1c1988ada1ea8b6e07c281e2addc375be3a9
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 Test EXSLT extensions
5 http://www.exslt.org/
6 -->
7 <head>
8 <title>Test for EXSLT extensions</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <p id="display"></p>
14 <div id="content" style="display: none"></div>
15 <pre id="test">
16 <script type="application/javascript">
17 let tests = [
19 descr: "Testing common:node-set",
20 expr: "common:node-set($tree)",
21 useCopyOf: true,
22 expResult: "<abc>def</abc>",
25 descr: "Testing common:object-type(string)",
26 expr: "common:object-type($string)",
27 expResult: "string",
30 descr: "Testing common:object-type(number)",
31 expr: "common:object-type($number)",
32 expResult: "number",
35 descr: "Testing common:object-type(boolean)",
36 expr: "common:object-type($boolean)",
37 expResult: "boolean",
40 descr: "Testing common:object-type(node-set)",
41 expr: "common:object-type($node-set)",
42 expResult: "node-set",
45 descr: "Testing common:object-type(tree)",
46 expr: "common:object-type($tree)",
47 expResult: "RTF",
50 descr: "Testing math:max",
51 expr: "math:max(root/numbers/number)",
52 expResult: "11",
55 descr: "Testing math:min",
56 expr: "math:min(root/numbers/number)",
57 expResult: "4",
60 descr: "Testing math:highest",
61 expr: "math:highest(root/numbers/number)/@id",
62 expResult: "eleven",
65 descr: "Testing math:lowest",
66 expr: "math:lowest(root/numbers/number)/@id",
67 expResult: "four",
70 descr: "Testing regexp:test",
71 expr: "regexp:test('XSLT is great', 'XSLT', '')",
72 expResult: "true",
75 descr: "Testing regexp:match",
76 expr: "regexp:match('XSLT is great', 'XSL.', '')[1]",
77 expResult: "XSLT",
80 descr: "Testing regexp:replace",
81 expr: "regexp:replace('Food is great', 'Fo.d', '', 'XSLT')",
82 expResult: "XSLT is great",
85 descr: "Testing sets:difference",
86 expr: "sets:difference($i, $e)",
87 useCopyOf: true,
88 expResult: "<city name=\"Paris\" country=\"France\"></city><city name=\"Madrid\" country=\"Spain\"></city><city name=\"Calais\" country=\"France\"></city>",
91 descr: "Testing sets:distinct",
92 expr: "strings:concat(sets:distinct(//@country))",
93 expResult: "FranceSpainAustriaGermany",
96 descr: "Testing sets:hasSameNode",
97 expr: "sets:has-same-node($i, $e)",
98 expResult: "true",
101 descr: "Testing sets:hasSameNode",
102 expr: "sets:has-same-node($i, $o)",
103 expResult: "false",
106 descr: "Testing sets:intersection",
107 expr: "sets:intersection($i, $e)",
108 useCopyOf: true,
109 expResult: "<city name=\"Vienna\" country=\"Austria\"></city><city name=\"Berlin\" country=\"Germany\"></city>",
112 descr: "Testing sets:leading",
113 expr: "sets:leading($i, $e)",
114 useCopyOf: true,
115 expResult: "<city name=\"Paris\" country=\"France\"></city><city name=\"Madrid\" country=\"Spain\"></city>",
118 descr: "Testing sets:leading",
119 expr: "sets:leading($i, $o)",
120 useCopyOf: true,
121 expResult: "",
124 descr: "Testing sets:leading",
125 expr: "sets:leading($i, $empty)",
126 useCopyOf: true,
127 expResult: "<city name=\"Paris\" country=\"France\"></city><city name=\"Madrid\" country=\"Spain\"></city><city name=\"Vienna\" country=\"Austria\"></city><city name=\"Calais\" country=\"France\"></city><city name=\"Berlin\" country=\"Germany\"></city>",
130 descr: "Testing sets:trailing",
131 expr: "sets:trailing($i, $e)",
132 useCopyOf: true,
133 expResult: "<city name=\"Calais\" country=\"France\"></city><city name=\"Berlin\" country=\"Germany\"></city>",
136 descr: "Testing sets:trailing",
137 expr: "sets:trailing($i, $o)",
138 useCopyOf: true,
139 expResult: "",
142 descr: "Testing sets:trailing",
143 expr: "sets:trailing($i, $empty)",
144 useCopyOf: true,
145 expResult: "<city name=\"Paris\" country=\"France\"></city><city name=\"Madrid\" country=\"Spain\"></city><city name=\"Vienna\" country=\"Austria\"></city><city name=\"Calais\" country=\"France\"></city><city name=\"Berlin\" country=\"Germany\"></city>",
148 descr: "Testing strings:concat",
149 expr: "strings:concat(root/numbers/number/@id)",
150 expResult: "seveneleveneightfour",
153 descr: "Testing strings:split",
154 expr: "strings:split('a, simple, list', ', ')",
155 useCopyOf: true,
156 expResult: "<token>a</token><token>simple</token><token>list</token>",
159 descr: "Testing strings:split",
160 expr: "strings:split('date math str')",
161 useCopyOf: true,
162 expResult: "<token>date</token><token>math</token><token>str</token>",
165 descr: "Testing strings:split",
166 expr: "strings:split('foo', '')",
167 useCopyOf: true,
168 expResult: "<token>f</token><token>o</token><token>o</token>",
171 descr: "Testing strings:tokenize",
172 expr: "strings:tokenize('2001-06-03T11:40:23', '-T:')",
173 useCopyOf: true,
174 expResult: "<token>2001</token><token>06</token><token>03</token><token>11</token><token>40</token><token>23</token>",
177 descr: "Testing strings:tokenize",
178 expr: "strings:tokenize('date math str')",
179 useCopyOf: true,
180 expResult: "<token>date</token><token>math</token><token>str</token>",
183 descr: "Testing strings:tokenize",
184 expr: "strings:tokenize('foo', '')",
185 useCopyOf: true,
186 expResult: "<token>f</token><token>o</token><token>o</token>",
190 let style =
191 `<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
192 xmlns:common="http://exslt.org/common"
193 xmlns:math="http://exslt.org/math"
194 xmlns:regexp="http://exslt.org/regular-expressions"
195 xmlns:sets="http://exslt.org/sets"
196 xmlns:strings="http://exslt.org/strings">
197 <xsl:output method="html"/>
198 <xsl:variable name="tree"><abc>def</abc></xsl:variable>
199 <xsl:variable name="string" select="'abc'"/>
200 <xsl:variable name="number" select="123"/>
201 <xsl:variable name="boolean" select="true()"/>
202 <xsl:variable name="node-set" select="//*"/>
203 <xsl:variable name="i" select="/root/sets/city[contains(@name, 'i')]" />
204 <xsl:variable name="e" select="/root/sets/city[contains(@name, 'e')]" />
205 <xsl:variable name="o" select="/root/sets/city[contains(@name, 'o')]" />
206 <xsl:variable name="empty" select="/root/sets/city[contains(@name, 'x')]" />
207 <xsl:template match="/">
208 ${tests.map(({expr, useCopyOf}, i) => `<div id="${i}"><xsl:${useCopyOf ? "copy-of" : "value-of"} select="${expr}"/></div>`).join("\n")}
209 </xsl:template>
210 </xsl:stylesheet>`;
212 let styleDoc = new DOMParser().parseFromString(style, "text/xml");
214 let data = `<root>
215 <numbers>
216 <number id="seven">7</number>
217 <number id="eleven">11</number>
218 <number id="eight">8</number>
219 <number id="four">4</number>
220 </numbers>
221 <sets>
222 <city name="Paris" country="France" />
223 <city name="Madrid" country="Spain" />
224 <city name="Vienna" country="Austria" />
225 <city name="Barcelona" country="Spain" />
226 <city name="Salzburg" country="Austria" />
227 <city name="Bonn" country="Germany" />
228 <city name="Lyon" country="France" />
229 <city name="Hannover" country="Germany" />
230 <city name="Calais" country="France" />
231 <city name="Berlin" country="Germany" />
232 </sets>
233 </root>`;
234 let originalDoc = new DOMParser().parseFromString(data, "text/xml");
236 let processor = new XSLTProcessor();
237 processor.importStylesheet(styleDoc);
239 let fragment = processor.transformToFragment(originalDoc, document);
241 tests.forEach(({descr, expResult}, i) => {
242 let result = fragment.getElementById(i);
243 is(result.innerHTML, expResult, descr);
246 </script>
247 </pre>
248 </body>
249 </html>