Path: blob/master/test/jdk/java/lang/String/CompactString/RegionMatches.java
41152 views
/*1* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import org.testng.annotations.DataProvider;24import org.testng.annotations.Test;2526import static org.testng.Assert.assertEquals;2728/*29* @test30* @bug 8077559 8248655 826454431* @summary Tests Compact String. This one is for String.regionMatches.32* @run testng/othervm -XX:+CompactStrings RegionMatches33* @run testng/othervm -XX:-CompactStrings RegionMatches34*/3536public class RegionMatches extends CompactString {3738@DataProvider39public Object[][] provider() {40return new Object[][] {4142new Object[] { STRING_EMPTY, true, 0, "", 0, 0, true },43new Object[] { STRING_EMPTY, true, 0, "", 0, 1, false },44new Object[] { STRING_EMPTY, true, 0, "A", 0, 0, true },45new Object[] { STRING_EMPTY, true, 0, "", 0, 0, true },46new Object[] { STRING_EMPTY, true, 0, "", 0, 1, false },47new Object[] { STRING_L1, false, 0, "a", 0, 1, false },48new Object[] { STRING_L1, false, 0, "BA", 1, 1, true },49new Object[] { STRING_L1, false, 0, "Ba", 1, 1, false },50new Object[] { STRING_L1, true, 0, "a", 0, 1, true },51new Object[] { STRING_L1, true, 0, "BA", 1, 1, true },52new Object[] { STRING_L1, true, 0, "Ba", 1, 1, true },53new Object[] { STRING_L2, true, 1, "b", 0, 1, true },54new Object[] { STRING_L2, true, 1, "B", 0, 1, true },55new Object[] { STRING_L2, true, 0, "xaBc", 1, 2, true },56new Object[] { STRING_L2, false, 0, "AB", 0, 2, true },57new Object[] { STRING_L2, false, 0, "Ab", 0, 2, false },58new Object[] { STRING_L2, false, 1, "BAB", 2, 1, true },59new Object[] { STRING_LLONG, true, 1, "bCdEF", 0, 5, true },60new Object[] { STRING_LLONG, false, 2, "CDEFG", 0, 5, true },61new Object[] { STRING_LLONG, true, 2, "CDEFg", 0, 5, true },62new Object[] { STRING_U1, true, 0, "\uFF41", 0, 1, true },63new Object[] { STRING_U1, false, 0, "\uFF41", 0, 1, false },64new Object[] { STRING_MDUPLICATE1, true, 0, "\uFF41a\uFF41", 0,653, true },66new Object[] { STRING_MDUPLICATE1, false, 0, "\uFF21a\uFF21",670, 3, false },68new Object[] { STRING_SUPPLEMENTARY, true, 0, "\uD801\uDC28\uD801\uDC29",690, 4, true },70new Object[] { STRING_SUPPLEMENTARY, true, 1, "\uDC00\uD801",710, 2, true },72new Object[] { STRING_SUPPLEMENTARY, true, 1, "\uDC28",730, 1, false },74new Object[] { STRING_SUPPLEMENTARY, true, 4, "\uFF21", 0, 1,75true },76new Object[] { STRING_SUPPLEMENTARY, true, 5, "A", 0, 1, true },77new Object[] { STRING_SUPPLEMENTARY, true, 0, "\uD802\uDC00\uD801\uDC01\uFF21A", 0, 2, false },78new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, false, 0,79"\uD801\uDC28\uD801\uDC29", 0, 4, true },80new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 0,81"\uD801\uDC00\uD801\uDC01", 0, 4, true },82new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 1,83"\uDC28\uD801", 0, 2, true },84new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 1,85"\uDC00", 0, 1, false },86new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 1,87"\uDC00\uD801", 0, 2, false },88new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, true, 4,89"\uFF21", 0, 1, true },90new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, false, 4,91"\uFF21", 0, 1, false },92new Object[] { STRING_SUPPLEMENTARY_LOWERCASE, false, 4,93"\uFF41", 0, 1, true },94};95}9697@Test(dataProvider = "provider")98public void testRegionMatches(String str, boolean ignoreCase, int toffset,99String other, int ooffset, int len, boolean expected) {100map.get(str)101.forEach(102(source, data) -> {103assertEquals(104data.regionMatches(ignoreCase, toffset,105other, ooffset, len),106expected,107String.format(108"testing String(%s).regionMatches(%b, %d, %s, %d, %d), source : %s, ",109escapeNonASCIIs(data), ignoreCase,110toffset, escapeNonASCIIs(other),111ooffset, len, source));112});113}114}115116117