• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://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
16const str = "SheSellsSeashellsByTheSeashoreTheShellsSheSellsAreSurelySeashells";
17const regex = /She/;
18
19// 1. RegExp.prototype.test()
20let test_res1 = regex.test(str);
21let test_res2 = regex.test(str);
22assert_equal(test_res1, test_res2);
23
24// 2. RegExp.prototype.exec()
25let exec_res1 = regex.exec(str);
26let exec_res2 = regex.exec(str);
27assert_equal(exec_res1, exec_res2);
28
29// 3. String.prototype.match()
30const match_res1 = str.match(regex);
31const match_res2 = str.match(regex);
32assert_equal(match_res1, match_res2);
33
34// 4. String.prototype.replace()
35const replace_res1 = str.replace(regex, "He");
36const replace_res2 = str.replace(regex, "He");
37assert_equal(replace_res1, replace_res2);
38
39// 5. String.prototype.search()
40const search_res1 = str.search(regex);
41const search_res2 = str.search(regex);
42assert_equal(search_res1, search_res2);
43
44// 6. String.prototype.split()
45const split_res1 = str.split(regex);
46const split_res2 = str.split(regex);
47assert_equal(split_res1, split_res2);
48
49test_end();
50