1/*
2 * Copyright (c) 2023 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:storeicbyname
18 * @tc.desc:test storeicbyname
19 * @tc.type: FUNC
20 * @tc.require: issueI7UTOA
21 */
22
23var r = /./;
24var coercibleValue = {
25    length: 1,
26    groups: {length : 1.1},
27};
28r.exec = function() {
29    return coercibleValue;
30};
31let a = r[Symbol.replace]('', '[$<length>]');
32print(a)
33
34let lineString1 = "这是一段lineString,A1这是替换的字符串A2"
35let treeString1 = "这是一段treeString,".concat("B1这是替换的字符串B2")
36let slicedString = "这是一段slicedString,C1这是要替换的字符串C2,xxxxxxxx".slice(0, 30);
37
38var re1 = /[ABC]/;
39var re2 = /[ABC]/g;
40
41var res1 = lineString1.replace(re1, "X");
42var res2 = lineString1.replace(re2, "X");
43var res3 = treeString1.replace(re1, "X");
44var res4 = treeString1.replace(re2, "X");
45var res5 = slicedString.replace(re1, "X");
46var res6 = slicedString.replace(re2, "X");
47
48print(res1)
49print(res2)
50print(res3)
51print(res4)
52print(res5)
53print(res6)
54
55let lineString2 = "aaaaAbbbbBccccCaaaabbbbcccc"
56
57function func1() {
58    return "xxxxxxx".concat("yyyyyyyyy")
59}
60var res = lineString2.replace(re2, func1);
61print(res)
62
63function func2() {
64    return "xxxxxxx".concat("xxxxxxx")
65}
66res = lineString2.replace(re2, func2);
67print(res)
68
69function func3() {
70    return "xxxxxxxxxxxxxx".concat("yyyyyyyy")
71}
72res = lineString2.replace(re2, func3);
73print(res)
74
75function func4() {
76    return "xxxxxxxxxxxxxx".concat("y")
77}
78res = lineString2.replace(re2, func4);
79print(res)
80
81function func5() {
82    return "哈哈哈哈哈哈哈".concat("嘻嘻嘻嘻嘻嘻嘻嘻嘻")
83}
84res = lineString2.replace(re2, func5);
85print(res)
86
87function func6() {
88    return "哈哈哈哈哈哈哈".concat("哈哈哈哈哈哈哈")
89}
90res = lineString2.replace(re2, func6);
91print(res)
92
93function func7() {
94    return "哈哈哈哈哈哈哈哈哈".concat("嘻嘻嘻嘻嘻嘻嘻")
95}
96res = lineString2.replace(re2, func7);
97print(res)
98
99function func8() {
100    return "哈哈哈哈哈哈哈哈哈".concat("嘻")
101}
102res = lineString2.replace(re2, func8);
103print(res)
104
105let v5 = String.fromCharCode(0).replaceAll(/(?<a>.)/ug);
106print("undefinedss".replace(undefined,v5));
107print("undefinedss".replaceAll(undefined,v5));