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