1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.regexp.mozilla.js1_2;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.annotation.Alerts;
19 import org.junit.jupiter.api.Test;
20
21
22
23
24
25
26 public class HexadecimalTest extends WebDriverTestCase {
27
28
29
30
31
32 @Test
33 @Alerts("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
34 public void test1() throws Exception {
35 final String initialScript = "testPattern = '\\\\x41\\\\x42\\\\x43\\\\x44\\\\x45\\\\x46\\\\x47\\\\x48\\\\x49"
36 + "\\\\x4A\\\\x4B\\\\x4C\\\\x4D\\\\x4E\\\\x4F\\\\x50\\\\x51\\\\x52\\\\x53\\\\x54\\\\x55\\\\x56\\\\x57"
37 + "\\\\x58\\\\x59\\\\x5A';"
38 + "var testString = '12345ABCDEFGHIJKLMNOPQRSTUVWXYZ67890';";
39 test(initialScript, "testString.match(new RegExp(testPattern))");
40 }
41
42
43
44
45
46 @Test
47 @Alerts("abcdefghijklmnopqrstuvwxyz")
48 public void test2() throws Exception {
49 final String initialScript = "var testPattern = '\\\\x61\\\\x62\\\\x63\\\\x64\\\\x65\\\\x66\\\\x67\\\\x68"
50 + "\\\\x69\\\\x6A\\\\x6B\\\\x6C\\\\x6D\\\\x6E\\\\x6F\\\\x70\\\\x71\\\\x72\\\\x73\\\\x74\\\\x75\\\\x76"
51 + "\\\\x77\\\\x78\\\\x79\\\\x7A';"
52 + "var testString = '12345AabcdefghijklmnopqrstuvwxyzZ67890';";
53 test(initialScript, "testString.match(new RegExp(testPattern))");
54 }
55
56
57
58
59
60 @Test
61 @Alerts(" !\"#$%&'()*+,-./0123")
62 public void test3() throws Exception {
63 final String initialScript = "var testPattern = '\\\\x20\\\\x21\\\\x22\\\\x23\\\\x24\\\\x25\\\\x26\\\\x27"
64 + "\\\\x28\\\\x29\\\\x2A\\\\x2B\\\\x2C\\\\x2D\\\\x2E\\\\x2F\\\\x30\\\\x31\\\\x32\\\\x33';"
65 + "var testString = 'abc !\"#$%&\\'()*+,-./0123ZBC';";
66 test(initialScript, "testString.match(new RegExp(testPattern))");
67 }
68
69
70
71
72
73 @Test
74 @Alerts("456789:;<=>?@")
75 public void test4() throws Exception {
76 final String initialScript = "var testPattern = '\\\\x34\\\\x35\\\\x36\\\\x37\\\\x38\\\\x39\\\\x3A\\\\x3B"
77 + "\\\\x3C\\\\x3D\\\\x3E\\\\x3F\\\\x40';"
78 + "var testString = '123456789:;<=>?@ABC';";
79 test(initialScript, "testString.match(new RegExp(testPattern))");
80 }
81
82
83
84
85
86 @Test
87 @Alerts("{|}~")
88 public void test5() throws Exception {
89 final String initialScript = "var testPattern = '\\\\x7B\\\\x7C\\\\x7D\\\\x7E';"
90 + "var testString = '1234{|}~ABC';";
91 test(initialScript, "testString.match(new RegExp(testPattern))");
92 }
93
94
95
96
97
98 @Test
99 @Alerts("FOUND")
100 public void test6() throws Exception {
101 test("'canthisbeFOUND'.match(new RegExp('[A-\\\\x5A]+'))");
102 }
103
104
105
106
107
108 @Test
109 @Alerts("canthisbe")
110 public void test7() throws Exception {
111 test("'canthisbeFOUND'.match(new RegExp('[\\\\x61-\\\\x7A]+'))");
112 }
113
114
115
116
117
118 @Test
119 @Alerts("canthisbe")
120 public void test8() throws Exception {
121 test("'canthisbeFOUND'.match(/[\\x61-\\x7A]+/)");
122 }
123
124 private void test(final String script) throws Exception {
125 test(null, script);
126 }
127
128 private void test(final String initialScript, final String script) throws Exception {
129 String html = "<html><head>\n"
130 + "</head><body>\n"
131 + LOG_TEXTAREA
132 + "<script>\n"
133 + LOG_TEXTAREA_FUNCTION;
134 if (initialScript != null) {
135 html += initialScript + ";\n";
136 }
137 html += " log(" + script + ");\n"
138 + "</script>\n"
139 + "</body></html>";
140 loadPageVerifyTextArea2(html);
141 }
142 }