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:split 18 * @tc.desc:test String.split 19 * @tc.type: FUNC 20 * @tc.require: issueI8SXEG 21 */ 22 23try { 24 ("X").split("00QP", -32297n); 25} catch (e) { 26 print(e); 27} 28 29// Test String.prototype.split and cache 30const shortString = "ababaabcdefaaaaab"; 31const shortTwoBytesString = "\u0429\u0428\u0428\u0429\u0429\u0428\u0429\u0429\u0429"; 32const longString = new Array(200).fill("abcdef").join(''); 33const longTwoBytesString = new Array(200).fill("\u0426\u0427\u0428\u0429\u0430").join(''); 34let res1 = shortString.split(''); 35let res2 = shortString.split(''); 36print(res1.length) 37print(res1.length == res2.length); 38print(res1[0] == res2[0]); 39let res3 = longString.split(''); 40let res4 = longString.split(''); 41print(res3.length) 42print(res3.length == res4.length); 43print(res3[0] == res4[0]); 44let res5 = shortTwoBytesString.split(''); 45let res6 = shortTwoBytesString.split(''); 46print(res5.length) 47print(res5.length == res6.length); 48print(res5[0] == res6[0]); 49let res7 = longTwoBytesString.split(''); 50let res8 = longTwoBytesString.split(''); 51print(res7.length) 52print(res7.length == res8.length); 53print(res7[0] == res8[0]); 54let res9 = shortString.split('a'); 55let res10 = shortString.split('a'); 56print(res9.length) 57print(res9.length == res10.length); 58print(res9[0] == res10[0]); 59let res11 = longString.split('a'); 60let res12 = longString.split('a'); 61print(res11.length) 62print(res11.length == res12.length); 63print(res11[0] == res12[0]); 64let res13 = shortTwoBytesString.split('\u0429'); 65let res14 = shortTwoBytesString.split('\u0429'); 66print(res13.length) 67print(res13.length == res14.length); 68print(res13[0] == res14[0]); 69let res15 = longTwoBytesString.split('\u0429'); 70let res16 = longTwoBytesString.split('\u0429'); 71print(res15.length) 72print(res15.length == res16.length); 73print(res15[0] == res16[0]); 74 75// Test split string is tree string 76var a = "12345678910" 77var b = "12345678910" 78var c = a.concat(b); 79c.split("") 80 81// Test split string is sliced string 82var d = a.slice(4) 83d.split("")