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 assert_equal(e instanceof TypeError, true); 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(''); 36assert_equal(res1.length,17) 37assert_equal(res1.length == res2.length,true); 38assert_equal(res1[0] == res2[0],true); 39let res3 = longString.split(''); 40let res4 = longString.split(''); 41assert_equal(res3.length,1200) 42assert_equal(res3.length == res4.length,true); 43assert_equal(res3[0] == res4[0],true); 44let res5 = shortTwoBytesString.split(''); 45let res6 = shortTwoBytesString.split(''); 46assert_equal(res5.length,9) 47assert_equal(res5.length == res6.length,true); 48assert_equal(res5[0] == res6[0],true); 49let res7 = longTwoBytesString.split(''); 50let res8 = longTwoBytesString.split(''); 51assert_equal(res7.length,1000) 52assert_equal(res7.length == res8.length,true); 53assert_equal(res7[0] == res8[0],true); 54let res9 = shortString.split('a'); 55let res10 = shortString.split('a'); 56assert_equal(res9.length,10) 57assert_equal(res9.length == res10.length,true); 58assert_equal(res9[0] == res10[0],true); 59let res11 = longString.split('a'); 60let res12 = longString.split('a'); 61assert_equal(res11.length,201) 62assert_equal(res11.length == res12.length,true); 63assert_equal(res11[0] == res12[0],true); 64let res13 = shortTwoBytesString.split('\u0429'); 65let res14 = shortTwoBytesString.split('\u0429'); 66assert_equal(res13.length,7) 67assert_equal(res13.length == res14.length,true); 68assert_equal(res13[0] == res14[0],true); 69let res15 = longTwoBytesString.split('\u0429'); 70let res16 = longTwoBytesString.split('\u0429'); 71assert_equal(res15.length,201) 72assert_equal(res15.length == res16.length,true); 73assert_equal(res15[0] == res16[0],true); 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("") 84 85let str = "dcidmcdififf"; 86for (let i = 0; i < 10; i++) { 87 str.split('d'); 88} 89let resSplit = str.split('d'); 90print(resSplit,["","ci","mc","ififf"]); 91 92test_end();