|
1 | 1 | <html> |
2 | | - <head> |
3 | | - <script src="../test_dist/xpath_script.js" language="JavaScript"></script> |
4 | | - </head> |
5 | | - <body onload="load_expr()"> |
6 | | - <form onsubmit="xpath_test(this);return false" action="javascript:void(0)"> |
7 | | - <select id="s" multiple="1" size="30" name="cases"></select> |
8 | | - <input type="submit" value="parse" align="top"/> |
9 | | - </form> |
10 | | - <script type="application/javascript" src="https://www.unpkg.com/xslt-processor@1.0.0/xslt-processor.js"></script> |
11 | | - <script> |
12 | | - // Copyright 2023 Design Liquido |
13 | | - // Copyright 2018 Johannes Wilm |
14 | | - // Copyright 2005 Google Inc. |
15 | | - // All Rights Reserved |
16 | | - // |
17 | | - // Tests for the XPath parser. To run the test, open the file from the |
18 | | - // file system. No server support is required. |
19 | | - // |
20 | | - // |
21 | | - // Author: Steffen Meschkat <mesch@google.com> |
22 | | - import { |
23 | | - Log |
24 | | - } from "./simplelog.js" |
25 | | - import { |
26 | | - xpathParse |
27 | | - } from "../src/xpath.js" |
28 | | - import { |
29 | | - expr |
30 | | - } from "../tests_src/xpath_unittest.js" |
31 | | - import { |
32 | | - parseTree |
33 | | - } from "../src/xpathdebug.js" |
| 2 | + <head> |
| 3 | + <script type="application/javascript" src="js/xslt-processor.js"></script> |
| 4 | + <script> |
| 5 | + // Copyright 2023 Design Liquido |
| 6 | + // Copyright 2018 Johannes Wilm |
| 7 | + // Copyright 2005 Google Inc. |
| 8 | + // All Rights Reserved |
| 9 | + // |
| 10 | + // Tests for the XPath parser. To run the test, open the file from the |
| 11 | + // file system. No server support is required. |
| 12 | + // |
| 13 | + // |
| 14 | + // Author: Steffen Meschkat <mesch@google.com> |
| 15 | + window.logging = true; |
| 16 | + window.xpathdebug = true; |
34 | 17 |
|
35 | | - window.logging = true; |
36 | | - window.xpathdebug = true; |
| 18 | + class Log { |
| 19 | + constructor() { |
| 20 | + this.lines = []; |
| 21 | + } |
37 | 22 |
|
38 | | - window.load_expr = () => { |
39 | | - const s = document.getElementById('s'); |
40 | | - for (let i = 0; i < expr.length; ++i) { |
41 | | - const o = new Option(expr[i].replace(/>/, '>').replace(/</, '<')); |
42 | | - s.options[s.options.length] = o; |
43 | | - } |
44 | | - s.selectedIndex = 0; |
45 | | - } |
| 23 | + static write(s) { |
| 24 | + this.lines.push(globalThis.XsltProcessor.xmlEscapeText(s)); |
| 25 | + this.show(); |
| 26 | + } |
46 | 27 |
|
47 | | - let log = new Log() |
| 28 | + // Writes the given XML with every tag on a new line. |
| 29 | + static writeXML(xml) { |
| 30 | + const s0 = xml.replace(/</g, '\n<'); |
| 31 | + const s1 = global.XsltProcessor.xmlEscapeText(s0); |
| 32 | + const s2 = s1.replace(/\s*\n(\s|\n)*/g, '<br/>'); |
| 33 | + this.lines.push(s2); |
| 34 | + this.show(); |
| 35 | + } |
48 | 36 |
|
49 | | - window.xpath_test = form => { |
50 | | - log.clear(); |
51 | | - try { |
52 | | - const i = form.cases.selectedIndex; |
53 | | - const options = form.cases.options; |
| 37 | + // Writes without any escaping |
| 38 | + static writeRaw(s) { |
| 39 | + this.lines.push(s); |
| 40 | + this.show(); |
| 41 | + } |
54 | 42 |
|
55 | | - const text = options[i].value; |
56 | | - log.writeRaw(`<tt><b>${text}</b></tt>`); |
| 43 | + static clear() { |
| 44 | + const l = this.div(); |
| 45 | + l.innerHTML = ''; |
| 46 | + this.lines = []; |
| 47 | + } |
57 | 48 |
|
58 | | - const expr = xpathParse(text, message => log.write(message)); |
59 | | - log.writeRaw(`<tt><b>${text}</b></tt>`); |
60 | | - log.writeRaw(`<pre>${parseTree(expr, '')}</pre>`); |
| 49 | + static show() { |
| 50 | + const l = this.div(); |
| 51 | + l.innerHTML += `${this.lines.join('<br/>')}<br/>`; |
| 52 | + this.lines = []; |
| 53 | + l.scrollTop = l.scrollHeight; |
| 54 | + } |
61 | 55 |
|
62 | | - options[i].selected = false; |
63 | | - if (i < options.length - 1) { |
64 | | - options[i + 1].selected = true; |
65 | | - } else { |
66 | | - options[0].selected = true; |
67 | | - } |
| 56 | + static div() { |
| 57 | + let l = document.getElementById('log'); |
| 58 | + if (!l) { |
| 59 | + l = document.createElement('div'); |
| 60 | + l.id = 'log'; |
| 61 | + l.style.position = 'absolute'; |
| 62 | + l.style.right = '5px'; |
| 63 | + l.style.top = '5px'; |
| 64 | + l.style.width = '250px'; |
| 65 | + l.style.height = '150px'; |
| 66 | + l.style.overflow = 'auto'; |
| 67 | + l.style.backgroundColor = '#f0f0f0'; |
| 68 | + l.style.border = '1px solid gray'; |
| 69 | + l.style.fontSize = '10px'; |
| 70 | + l.style.padding = '5px'; |
| 71 | + document.body.appendChild(l); |
| 72 | + } |
| 73 | + return l; |
| 74 | + } |
| 75 | + } |
68 | 76 |
|
69 | | - } catch (e) { |
70 | | - log.write(`EXCEPTION ${e}`); |
71 | | - } |
72 | | - } |
73 | | - </script> |
74 | | - </body> |
| 77 | + window.load_expr = () => { |
| 78 | + const s = document.getElementById('s'); |
| 79 | + const expr = ['<xsl:stylesheet>']; |
| 80 | + for (let i = 0; i < expr.length; ++i) { |
| 81 | + const o = new Option(expr[i].replace(/>/, '>').replace(/</, '<')); |
| 82 | + s.options[s.options.length] = o; |
| 83 | + } |
| 84 | + s.selectedIndex = 0; |
| 85 | + }; |
| 86 | + |
| 87 | + let log = new Log(); |
| 88 | + |
| 89 | + window.xpath_test = (form) => { |
| 90 | + log.clear(); |
| 91 | + try { |
| 92 | + const i = form.cases.selectedIndex; |
| 93 | + const options = form.cases.options; |
| 94 | + |
| 95 | + const text = options[i].value; |
| 96 | + log.writeRaw(`<tt><b>${text}</b></tt>`); |
| 97 | + |
| 98 | + const expr = xpathParse(text, (message) => log.write(message)); |
| 99 | + log.writeRaw(`<tt><b>${text}</b></tt>`); |
| 100 | + log.writeRaw(`<pre>${parseTree(expr, '')}</pre>`); |
| 101 | + |
| 102 | + options[i].selected = false; |
| 103 | + if (i < options.length - 1) { |
| 104 | + options[i + 1].selected = true; |
| 105 | + } else { |
| 106 | + options[0].selected = true; |
| 107 | + } |
| 108 | + } catch (e) { |
| 109 | + log.write(`EXCEPTION ${e}`); |
| 110 | + } |
| 111 | + }; |
| 112 | + </script> |
| 113 | + </head> |
| 114 | + <body onload="window.load_expr()"> |
| 115 | + <form onsubmit="window.xpath_test(this);return false" action="javascript:void(0)"> |
| 116 | + <select id="s" multiple="1" size="30" name="cases"></select> |
| 117 | + <input type="submit" value="parse" align="top" /> |
| 118 | + </form> |
| 119 | + </body> |
75 | 120 | </html> |
0 commit comments