1/*
2 * Copyright (c) 2024 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:stringreplaceall
18 * @tc.desc:test stringreplaceall
19 * @tc.type: FUNC
20 * @tc.require: issueIATECS
21 */
22
23// case1 - string: utf8, search: not regexp, replace: no dollar
24let str1 = "Hello, world";
25let res1 = str1.replaceAll("o", "o-o");
26print(res1);
27
28// case2 - string: utf8, search: regexp, replace: no dollar
29let res2 = str1.replaceAll(/o/g, "o-o");
30print(res2);
31
32// case3 - string: utf8, search: regexp, replace: dollar
33let res3 = str1.replaceAll(/o/g, "$&-$&");
34print(res3);
35
36// case4 - string: utf8, search: not regexp, replace: dollar
37let res4 = str1.replaceAll("o", "$&-$&");
38print(res4);
39
40// case5 - string: utf8, search: not regexp, replace: function
41let res5 = str1.replaceAll("o", String);
42print(res5);
43
44// case6 - string: utf16, search: not regexp, replace: no dollar
45let str3 = "你好,世界!你好,世界!";
46let res6 = str3.replaceAll("好", "好-好");
47print(res6);
48
49// case7 - string: utf16, search: regexp, replace: no dollar
50let res7 = str3.replaceAll(/好/g, "好-好");
51print(res7);
52
53// case8 - string: utf16, search: regexp, replace: dollar
54let res8 = str3.replaceAll(/好/g, "$&-$&");
55print(res8);
56
57// case9 - string: utf16, search: not regexp, replace: dollar
58let res9 = str3.replaceAll("好", "$&-$&");
59print(res9);
60
61// case10 - string: utf16, search: not regexp, replace: function
62let res10 = str3.replaceAll("好", String);
63print(res10);
64