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/flags.js'.
23   *
24   * @author Ahmed Ashour
25   */
26  public class FlagsTest extends WebDriverTestCase {
27  
28      /**
29       * Tests 'aBCdEfGHijKLmno'.match(/fghijk/i).
30       * @throws Exception if the test fails
31       */
32      @Test
33      @Alerts("fGHijK")
34      public void test1() throws Exception {
35          test("'aBCdEfGHijKLmno'.match(/fghijk/i)");
36      }
37  
38      /**
39       * Tests 'aBCdEfGHijKLmno'.match(new RegExp("fghijk","i")).
40       * @throws Exception if the test fails
41       */
42      @Test
43      @Alerts("fGHijK")
44      public void test2() throws Exception {
45          test("'aBCdEfGHijKLmno'.match(new RegExp(\"fghijk\",\"i\"))");
46      }
47  
48      /**
49       * Tests 'xa xb xc xd xe xf'.match(/x./g).
50       * @throws Exception if the test fails
51       */
52      @Test
53      @Alerts("xa,xb,xc,xd,xe,xf")
54      public void test3() throws Exception {
55          test("'xa xb xc xd xe xf'.match(/x./g)");
56      }
57  
58      /**
59       * Tests 'xa xb xc xd xe xf'.match(new RegExp('x.','g')).
60       * @throws Exception if the test fails
61       */
62      @Test
63      @Alerts("xa,xb,xc,xd,xe,xf")
64      public void test4() throws Exception {
65          test("'xa xb xc xd xe xf'.match(new RegExp('x.','g'))");
66      }
67  
68      /**
69       * Tests 'xa Xb xc xd Xe xf'.match(/x./gi).
70       * @throws Exception if the test fails
71       */
72      @Test
73      @Alerts("xa,Xb,xc,xd,Xe,xf")
74      public void test5() throws Exception {
75          test("'xa Xb xc xd Xe xf'.match(/x./gi)");
76      }
77  
78      /**
79       * Tests 'xa Xb xc xd Xe xf'.match(new RegExp('x.','gi')).
80       * @throws Exception if the test fails
81       */
82      @Test
83      @Alerts("xa,Xb,xc,xd,Xe,xf")
84      public void test6() throws Exception {
85          test("'xa Xb xc xd Xe xf'.match(new RegExp('x.','gi'))");
86      }
87  
88      /**
89       * Tests 'xa Xb xc xd Xe xf'.match(/x./ig).
90       * @throws Exception if the test fails
91       */
92      @Test
93      @Alerts("xa,Xb,xc,xd,Xe,xf")
94      public void test7() throws Exception {
95          test("'xa Xb xc xd Xe xf'.match(/x./ig)");
96      }
97  
98      /**
99       * Tests 'xa Xb xc xd Xe xf'.match(new RegExp('x.','ig')).
100      * @throws Exception if the test fails
101      */
102     @Test
103     @Alerts("xa,Xb,xc,xd,Xe,xf")
104     public void test8() throws Exception {
105         test("'xa Xb xc xd Xe xf'.match(new RegExp('x.','ig'))");
106     }
107 
108     private void test(final String script) throws Exception {
109         final String html = "<html><head><script>\n"
110             + LOG_TITLE_FUNCTION
111             + "  log(" + script + ");\n"
112             + "</script></head><body>\n"
113             + "</body></html>";
114         loadPageVerifyTitle2(html);
115     }
116 }