Path: blob/master/test/jdk/java/lang/String/CompactString/OffsetByCodePoints.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.offsetByCodePoints.32* @run testng/othervm -XX:+CompactStrings OffsetByCodePoints33* @run testng/othervm -XX:-CompactStrings OffsetByCodePoints34*/3536public class OffsetByCodePoints extends CompactString {3738@DataProvider39public Object[][] provider() {40return new Object[][] {4142new Object[] { STRING_SUPPLEMENTARY, 0, 1, 2 },43new Object[] { STRING_SUPPLEMENTARY, 0, 3, 5 },44new Object[] { STRING_SUPPLEMENTARY, 1, 1, 2 },45new Object[] { STRING_SUPPLEMENTARY, 1, 3, 5 },46new Object[] { STRING_SUPPLEMENTARY, 2, 1, 4 },47new Object[] { STRING_SUPPLEMENTARY, 2, 2, 5 },48new Object[] { STRING_SUPPLEMENTARY, 2, 3, 6 },49new Object[] { STRING_SUPPLEMENTARY, 3, 1, 4 },50new Object[] { STRING_SUPPLEMENTARY, 3, 2, 5 },51new Object[] { STRING_SUPPLEMENTARY, 3, 3, 6 }, };52}5354@Test(dataProvider = "provider")55public void testOffsetByCodePoints(String str, int index,56int codePointOffset, int expected) {57map.get(str)58.forEach(59(source, data) -> {60assertEquals(61data.offsetByCodePoints(index,62codePointOffset),63expected,64String.format(65"testing String(%s).offsetByCodePoints(%d, %d), source : %s, ",66escapeNonASCIIs(data), index,67codePointOffset, source));68});69}70}717273