• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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
16/*
17 * @tc.name:builtins
18 * @tc.desc:test builtins regexp
19 * @tc.type: FUNC
20 * @tc.require: issueI5NO8G
21 */
22print("builtins regexp start");
23
24// Test1 - Regexp backward
25const url = 'https://designcloud.uiplus.huawei.com/tool//materialServer/upload/images/20210608_5V0J5lVh4xVNYx0AUE.jpg';
26const data = url.match(/(?<=\/)\w+(.jpg)$/);
27print(data);
28
29// Test 2 - RegExp $1 .. $9 is read only
30try{
31    RegExp.$1 = "b";
32    print(RegExp.$1);
33} catch(error) {
34    print("RegExp $1 is read-only");
35}
36
37// Test 3 - RegExp $1 .. $9 match the lastest successful results
38var reg = /t(e)(st(\d?))/g;
39const str = "test1test2";
40const array = [...str.matchAll(reg)];
41print(RegExp.$2);
42
43// Test 4 - RegExp $1..$9 reset all and refill the results
44"abc".match(/(a)/);
45print(RegExp.$1);
46print(RegExp.$2);
47
48// Test 5 - RegExp $10 is undefined
49print(RegExp.$10);
50
51// Test 6 - RegExp cache
52var pattern = /[A-Z]{3}/g;
53var testStr = "AAAA";
54var res1 = testStr.match(pattern);
55print(res1[0]);
56res1[0] = "BB";
57var res2 = testStr.match(pattern);
58print(res2[0]);
59res2[0] = "C";
60var res3 = testStr.match(pattern);
61print(res3[0]);
62
63// Test 7 - Word Boundary test
64var reg7 = /\/(?:\B)/gm;
65var str7 = "/";
66print(reg7.test(str7));
67
68print("builtins regexp end");
69