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 OctalTest extends WebDriverTestCase {
30
31
32
33
34
35 @Test
36 @Alerts("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
37 public void test1() throws Exception {
38 final String initialScript = "var testPattern = '\\\\101\\\\102\\\\103\\\\104\\\\105\\\\106\\\\107\\\\110"
39 + "\\\\111\\\\112\\\\113\\\\114\\\\115\\\\116\\\\117\\\\120\\\\121\\\\122\\\\123\\\\124\\\\125\\\\126"
40 + "\\\\127\\\\130\\\\131\\\\132';"
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 = '\\\\141\\\\142\\\\143\\\\144\\\\145\\\\146\\\\147\\\\150"
53 + "\\\\151\\\\152\\\\153\\\\154\\\\155\\\\156\\\\157\\\\160\\\\161\\\\162\\\\163\\\\164\\\\165\\\\166"
54 + "\\\\167\\\\170\\\\171\\\\172';"
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 = '\\\\40\\\\41\\\\42\\\\43\\\\44\\\\45\\\\46\\\\47\\\\50"
67 + "\\\\51\\\\52\\\\53\\\\54\\\\55\\\\56\\\\57\\\\60\\\\61\\\\62\\\\63';"
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 = '\\\\64\\\\65\\\\66\\\\67\\\\70\\\\71\\\\72\\\\73\\\\74\\\\75"
80 + "\\\\76\\\\77\\\\100';"
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 = '\\\\173\\\\174\\\\175\\\\176';"
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-\\\\132]+'))");
105 }
106
107
108
109
110
111 @Test
112 @Alerts("canthisbe")
113 public void test7() throws Exception {
114 test("'canthisbeFOUND'.match(new RegExp('[\\\\141-\\\\172]+'))");
115 }
116
117
118
119
120
121 @Test
122 @Alerts("canthisbe")
123 public void test8() throws Exception {
124 test("'canthisbeFOUND'.match(/[\\141-\\172]+/)");
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 }