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
27 public class CompileTest extends WebDriverTestCase {
28
29
30
31
32
33 @Test
34 @Alerts("456X7890")
35 public void test1() throws Exception {
36 final String initialScript = "var regularExpression = new RegExp();\n"
37 + "regularExpression.compile('[0-9]{3}x[0-9]{4}', 'i');";
38 test(initialScript, "'234X456X7890'.match(regularExpression)");
39 }
40
41
42
43
44
45 @Test
46 @Alerts("[0-9]{3}x[0-9]{4}")
47 public void test2() throws Exception {
48 final String initialScript = "var regularExpression = new RegExp();\n"
49 + "regularExpression.compile('[0-9]{3}x[0-9]{4}', 'i');";
50 test(initialScript, "regularExpression.source");
51 }
52
53
54
55
56
57 @Test
58 @Alerts("false")
59 public void test3() throws Exception {
60 final String initialScript = "var regularExpression = new RegExp();\n"
61 + "regularExpression.compile('[0-9]{3}x[0-9]{4}', 'i');";
62 test(initialScript, "regularExpression.global");
63 }
64
65
66
67
68
69 @Test
70 @Alerts("true")
71 public void test4() throws Exception {
72 final String initialScript = "var regularExpression = new RegExp();\n"
73 + "regularExpression.compile('[0-9]{3}x[0-9]{4}', 'i');";
74 test(initialScript, "regularExpression.ignoreCase");
75 }
76
77
78
79
80
81 @Test
82 @Alerts("234X456")
83 public void test5() throws Exception {
84 final String initialScript = "var regularExpression = new RegExp();\n"
85 + "regularExpression.compile('[0-9]{3}X[0-9]{3}', 'g')";
86 test(initialScript, "'234X456X7890'.match(regularExpression)");
87 }
88
89
90
91
92
93 @Test
94 @Alerts("[0-9]{3}X[0-9]{3}")
95 public void test6() throws Exception {
96 final String initialScript = "var regularExpression = new RegExp();\n"
97 + "regularExpression.compile('[0-9]{3}X[0-9]{3}', 'g')";
98 test(initialScript, "regularExpression.source");
99 }
100
101
102
103
104
105 @Test
106 @Alerts("true")
107 public void test7() throws Exception {
108 final String initialScript = "var regularExpression = new RegExp();\n"
109 + "regularExpression.compile('[0-9]{3}X[0-9]{3}', 'g')";
110 test(initialScript, "regularExpression.global");
111 }
112
113
114
115
116
117 @Test
118 @Alerts("false")
119 public void test8() throws Exception {
120 final String initialScript = "var regularExpression = new RegExp();\n"
121 + "regularExpression.compile('[0-9]{3}X[0-9]{3}', 'g')";
122 test(initialScript, "regularExpression.ignoreCase");
123 }
124
125 private void test(final String initialScript, final String script) throws Exception {
126 String html = "<html><head><script>\n"
127 + LOG_TITLE_FUNCTION;
128 if (initialScript != null) {
129 html += initialScript + ";\n";
130 }
131 html += " log(" + script + ");\n"
132 + "</script></head><body>\n"
133 + "</body></html>";
134 loadPageVerifyTitle2(html);
135 }
136 }