Path: blob/master/test/jdk/java/lang/String/CompactString/Concat.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.concat.32* @run testng/othervm -XX:+CompactStrings Concat33* @run testng/othervm -XX:-CompactStrings Concat34*/3536public class Concat extends CompactString {3738@DataProvider39public Object[][] provider() {40return new Object[][] {41new Object[] { STRING_EMPTY, "ABC", "ABC" },42new Object[] { STRING_EMPTY,43"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),44"ABC\uFF21\uFF22\uFF23DEF" },45new Object[] {46STRING_EMPTY,47"\uFF21\uFF22\uFF23".concat("ABC").concat(48"\uFF24\uFF25\uFF26"),49"\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },50new Object[] { STRING_L1,51"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),52"AABC\uFF21\uFF22\uFF23DEF" },53new Object[] {54STRING_L1,55"\uFF21\uFF22\uFF23".concat("ABC").concat(56"\uFF24\uFF25\uFF26"),57"A\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },58new Object[] { STRING_L2,59"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),60"ABABC\uFF21\uFF22\uFF23DEF" },61new Object[] {62STRING_L2,63"\uFF21\uFF22\uFF23".concat("ABC").concat(64"\uFF24\uFF25\uFF26"),65"AB\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },66new Object[] { STRING_L4,67"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),68"ABCDABC\uFF21\uFF22\uFF23DEF" },69new Object[] {70STRING_L4,71"\uFF21\uFF22\uFF23".concat("ABC").concat(72"\uFF24\uFF25\uFF26"),73"ABCD\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },74new Object[] { STRING_LLONG,75"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),76"ABCDEFGHABC\uFF21\uFF22\uFF23DEF" },77new Object[] {78STRING_LLONG,79"\uFF21\uFF22\uFF23".concat("ABC").concat(80"\uFF24\uFF25\uFF26"),81"ABCDEFGH\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },82new Object[] { STRING_U1,83"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),84"\uFF21ABC\uFF21\uFF22\uFF23DEF" },85new Object[] {86STRING_U1,87"\uFF21\uFF22\uFF23".concat("ABC").concat(88"\uFF24\uFF25\uFF26"),89"\uFF21\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },90new Object[] { STRING_U2,91"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),92"\uFF21\uFF22ABC\uFF21\uFF22\uFF23DEF" },93new Object[] {94STRING_U2,95"\uFF21\uFF22\uFF23".concat("ABC").concat(96"\uFF24\uFF25\uFF26"),97"\uFF21\uFF22\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },98new Object[] { STRING_M12,99"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),100"\uFF21AABC\uFF21\uFF22\uFF23DEF" },101new Object[] {102STRING_M12,103"\uFF21\uFF22\uFF23".concat("ABC").concat(104"\uFF24\uFF25\uFF26"),105"\uFF21A\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" },106new Object[] { STRING_M11,107"ABC".concat("\uFF21\uFF22\uFF23").concat("DEF"),108"A\uFF21ABC\uFF21\uFF22\uFF23DEF" },109new Object[] {110STRING_M11,111"\uFF21\uFF22\uFF23".concat("ABC").concat(112"\uFF24\uFF25\uFF26"),113"A\uFF21\uFF21\uFF22\uFF23ABC\uFF24\uFF25\uFF26" }, };114}115116@Test(dataProvider = "provider")117public void testConcat(String str, String anotherString, String expected) {118map.get(str)119.forEach(120(source, data) -> {121assertEquals(122data.concat(anotherString),123expected,124String.format(125"testing String(%s).concat(%s), source : %s, ",126escapeNonASCIIs(data),127escapeNonASCIIs(anotherString),128source));129});130}131}132133134