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 ParenthesesTest extends WebDriverTestCase {
27
28
29
30
31
32 @Test
33 @Alerts("abc,abc")
34 public void test1() throws Exception {
35 test("'abc'.match(new RegExp('(abc)'))");
36 }
37
38
39
40
41
42 @Test
43 @Alerts("abcdefg,bc,ef")
44 public void test2() throws Exception {
45 test("'abcdefg'.match(new RegExp('a(bc)d(ef)g'))");
46 }
47
48
49
50
51
52 @Test
53 @Alerts("abcdefg,abc,defg")
54 public void test3() throws Exception {
55 test("'abcdefg'.match(new RegExp('(.{3})(.{4})'))");
56 }
57
58
59
60
61
62 @Test
63 @Alerts("aabcdaa,aa")
64 public void test4() throws Exception {
65 test("'aabcdaabcd'.match(new RegExp('(aa)bcd\\\\1'))");
66 }
67
68
69
70
71
72 @Test
73 @Alerts("aabcdaa,aa")
74 public void test5() throws Exception {
75 test("'aabcdaabcd'.match(new RegExp('(aa).+\\\\1'))");
76 }
77
78
79
80
81
82 @Test
83 @Alerts("aabcdaa,aa")
84 public void test6() throws Exception {
85 test("'aabcdaabcd'.match(new RegExp('(.{2}).+\\\\1'))");
86 }
87
88
89
90
91
92 @Test
93 @Alerts("123456123456,123,456")
94 public void test7() throws Exception {
95 test("'123456123456'.match(new RegExp('(\\\\d{3})(\\\\d{3})\\\\1\\\\2'))");
96 }
97
98
99
100
101
102 @Test
103 @Alerts("abcdefg,bcdefg,de")
104 public void test8() throws Exception {
105 test("'abcdefg'.match(new RegExp('a(..(..)..)'))");
106 }
107
108
109
110
111
112 @Test
113 @Alerts("abcdefg,bcdefg,de")
114 public void test9() throws Exception {
115 test("'abcdefg'.match(/a(..(..)..)/)");
116 }
117
118
119
120
121
122 @Test
123 @Alerts("abcdef,abc,bc,c,def,ef,f")
124 public void test10() throws Exception {
125 test("'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))");
126 }
127
128
129
130
131
132 @Test
133 @Alerts("abcdefbcef,abc,bc,c,def,ef,f")
134 public void test11() throws Exception {
135 test("'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\\\2\\\\5'))");
136 }
137
138
139
140
141
142 @Test
143 @Alerts("abcd,")
144 public void test12() throws Exception {
145 test("'abcd'.match(new RegExp('a(.?)b\\\\1c\\\\1d\\\\1'))");
146 }
147
148
149
150
151
152 @Test
153 @Alerts("abcd,")
154 public void test13() throws Exception {
155 test("'abcd'.match(/a(.?)b\\1c\\1d\\1/)");
156 }
157
158 private void test(final String script) throws Exception {
159 final String html = "<html><head><script>\n"
160 + LOG_TITLE_FUNCTION
161 + " log(" + script + ");\n"
162 + "</script></head><body>\n"
163 + "</body></html>";
164 loadPageVerifyTitle2(html);
165 }
166 }