Path: blob/master/test/jdk/java/lang/String/CompactString/SubString.java
41152 views
/*1* Copyright (c) 2015, 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 807755931* @summary Tests Compact String. This one is for String.subString.32* @run testng/othervm -XX:+CompactStrings SubString33* @run testng/othervm -XX:-CompactStrings SubString34*/3536public class SubString extends CompactString {3738@DataProvider39public Object[][] provider() {40return new Object[][] {4142new Object[] { STRING_EMPTY, 0, 0, "" },43new Object[] { STRING_L1, 0, 1, "A" },44new Object[] { STRING_L1, 1, 1, "" },45new Object[] { STRING_L2, 0, 2, "AB" },46new Object[] { STRING_L2, 1, 2, "B" },47new Object[] { STRING_LLONG, 0, 8, "ABCDEFGH" },48new Object[] { STRING_LLONG, 7, 8, "H" },49new Object[] { STRING_LLONG, 8, 8, "" },50new Object[] { STRING_LLONG, 3, 7, "DEFG" },51new Object[] { STRING_U1, 0, 1, "\uFF21" },52new Object[] { STRING_U1, 1, 1, "" },53new Object[] { STRING_U1, 0, 0, "" },54new Object[] { STRING_U2, 0, 2, "\uFF21\uFF22" },55new Object[] { STRING_U2, 1, 2, "\uFF22" },56new Object[] { STRING_U2, 2, 2, "" },57new Object[] { STRING_U2, 0, 2, "\uFF21\uFF22" },58new Object[] { STRING_U2, 1, 2, "\uFF22" },59new Object[] { STRING_M12, 1, 2, "A" },60new Object[] { STRING_M11, 0, 1, "A" },61new Object[] { STRING_M11, 1, 2, "\uFF21" },62new Object[] { STRING_UDUPLICATE, 1, 5,63"\uFF22\uFF21\uFF22\uFF21" },64new Object[] { STRING_MDUPLICATE1, 9, 10, "A" },65new Object[] { STRING_MDUPLICATE1, 7, 8, "A" }, };66}6768@Test(dataProvider = "provider")69public void testSubstring(String str, int beginIndex, int endIndex,70String expected) {71map.get(str)72.forEach(73(source, data) -> {74assertEquals(75data.substring(beginIndex, endIndex),76expected,77String.format(78"testing String(%s).substring(%d, %d), source : %s, ",79escapeNonASCIIs(data), beginIndex,80endIndex, source));81});82}83}848586