View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
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   * Tests originally in '/js/src/tests/js1_2/regexp/interval.js'.
23   *
24   * @author Ahmed Ashour
25   */
26  public class IntervalTest extends WebDriverTestCase {
27  
28      /**
29       * Tests 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2}c')).
30       * @throws Exception if the test fails
31       */
32      @Test
33      @Alerts("bbc")
34      public void test1() throws Exception {
35          test("'aaabbbbcccddeeeefffff'.match(new RegExp('b{2}c'))");
36      }
37  
38      /**
39       * Tests 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8}')).
40       * @throws Exception if the test fails
41       */
42      @Test
43      @Alerts("null")
44      public void test2() throws Exception {
45          test("'aaabbbbcccddeeeefffff'.match(new RegExp('b{8}'))");
46      }
47  
48      /**
49       * Tests 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,}c')).
50       * @throws Exception if the test fails
51       */
52      @Test
53      @Alerts("bbbbc")
54      public void test3() throws Exception {
55          test("'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,}c'))");
56      }
57  
58      /**
59       * Tests 'aaabbbbcccddeeeefffff'.match(new RegExp('b{8,}c')).
60       * @throws Exception if the test fails
61       */
62      @Test
63      @Alerts("null")
64      public void test4() throws Exception {
65          test("'aaabbbbcccddeeeefffff'.match(new RegExp('b{8,}c'))");
66      }
67  
68      /**
69       * Tests 'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,3}c')).
70       * @throws Exception if the test fails
71       */
72      @Test
73      @Alerts("bbbc")
74      public void test5() throws Exception {
75          test("'aaabbbbcccddeeeefffff'.match(new RegExp('b{2,3}c'))");
76      }
77  
78      /**
79       * Tests 'aaabbbbcccddeeeefffff'.match(new RegExp('b{42,93}c')).
80       * @throws Exception if the test fails
81       */
82      @Test
83      @Alerts("null")
84      public void test6() throws Exception {
85          test("'aaabbbbcccddeeeefffff'.match(new RegExp('b{42,93}c'))");
86      }
87  
88      /**
89       * Tests 'aaabbbbcccddeeeefffff'.match(new RegExp('b{0,93}c')).
90       * @throws Exception if the test fails
91       */
92      @Test
93      @Alerts("bbbbc")
94      public void test7() throws Exception {
95          test("'aaabbbbcccddeeeefffff'.match(new RegExp('b{0,93}c'))");
96      }
97  
98      /**
99       * Tests 'aaabbbbcccddeeeefffff'.match(new RegExp('bx{0,93}c')).
100      * @throws Exception if the test fails
101      */
102     @Test
103     @Alerts("bc")
104     public void test8() throws Exception {
105         test("'aaabbbbcccddeeeefffff'.match(new RegExp('bx{0,93}c'))");
106     }
107 
108     /**
109      * Tests 'weirwerdf'.match(new RegExp('.{0,93}')).
110      * @throws Exception if the test fails
111      */
112     @Test
113     @Alerts("weirwerdf")
114     public void test9() throws Exception {
115         test("'weirwerdf'.match(new RegExp('.{0,93}'))");
116     }
117 
118     /**
119      * Tests 'wqe456646dsff'.match(new RegExp('\\d{1,}')).
120      * @throws Exception if the test fails
121      */
122     @Test
123     @Alerts("456646")
124     public void test10() throws Exception {
125         test("'wqe456646dsff'.match(new RegExp('\\\\d{1,}'))");
126     }
127 
128     /**
129      * Tests '123123'.match(new RegExp('(123){1,}')).
130      * @throws Exception if the test fails
131      */
132     @Test
133     @Alerts("123123,123")
134     public void test11() throws Exception {
135         test("'123123'.match(new RegExp('(123){1,}'))");
136     }
137 
138     /**
139      * Tests '123123x123'.match(new RegExp('(123){1,}x\\1')).
140      * @throws Exception if the test fails
141      */
142     @Test
143     @Alerts("123123x123,123")
144     public void test12() throws Exception {
145         test("'123123x123'.match(new RegExp('(123){1,}x\\\\1'))");
146     }
147 
148     /**
149      * Tests '123123x123'.match(/(123){1,}x\1/).
150      * @throws Exception if the test fails
151      */
152     @Test
153     @Alerts("123123x123,123")
154     public void test13() throws Exception {
155         test("'123123x123'.match(/(123){1,}x\\1/)");
156     }
157 
158     /**
159      * Tests 'xxxxxxx'.match(new RegExp('x{1,2}x{1,}')).
160      * @throws Exception if the test fails
161      */
162     @Test
163     @Alerts("xxxxxxx")
164     public void test14() throws Exception {
165         test("'xxxxxxx'.match(new RegExp('x{1,2}x{1,}'))");
166     }
167 
168     /**
169      * Tests 'xxxxxxx'.match(/x{1,2}x{1,}/).
170      * @throws Exception if the test fails
171      */
172     @Test
173     @Alerts("xxxxxxx")
174     public void test15() throws Exception {
175         test("'xxxxxxx'.match(/x{1,2}x{1,}/)");
176     }
177 
178     private void test(final String script) throws Exception {
179         final String html = "<html><head><script>\n"
180             + LOG_TITLE_FUNCTION
181             + "  log(" + script + ");\n"
182             + "</script></head><body>\n"
183             + "</body></html>";
184         loadPageVerifyTitle2(html);
185     }
186 }