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