jdk-24/jdk/test/java/lang/String/CompactString/CompareTo.java
Tobias Hartmann 4ed5b73f3d 8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.

Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:42:11 +01:00

95 lines
4.2 KiB
Java

/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
/*
* @test
* @bug 8077559
* @summary Tests Compact String. This one is for String.compareTo.
* @run testng/othervm -XX:+CompactStrings CompareTo
* @run testng/othervm -XX:-CompactStrings CompareTo
*/
public class CompareTo extends CompactString {
@DataProvider
public Object[][] provider() {
return new Object[][] {
new Object[] { STRING_EMPTY, "A", -1 },
new Object[] { STRING_EMPTY, "\uFF21", -1 },
new Object[] { STRING_L1, "AB", -1 },
new Object[] { STRING_L1, "A", 0 },
new Object[] { STRING_L1, "a", -32 },
new Object[] { STRING_L1, "\uFF21", -65248 },
new Object[] { STRING_L2, "AB", 0 },
new Object[] { STRING_L2, "Ab", -32 },
new Object[] { STRING_L2, "AA", 1 },
new Object[] { STRING_L2, "\uFF21", -65248 },
new Object[] { STRING_L2, "A\uFF21", -65247 },
new Object[] { STRING_L4, "ABC", 1 },
new Object[] { STRING_L4, "AB", 2 },
new Object[] { STRING_L4, "ABcD", -32 },
new Object[] { STRING_L4, "ABCD\uFF21\uFF21", -2 },
new Object[] { STRING_L4, "ABCD\uFF21", -1 },
new Object[] { STRING_LLONG, "ABCDEFG\uFF21", -65241 },
new Object[] { STRING_LLONG, "AB", 6 },
new Object[] { STRING_LLONG, "ABCD", 4 },
new Object[] { STRING_LLONG, "ABCDEFGH\uFF21\uFF21", -2 },
new Object[] { STRING_U1, "\uFF21", 0 },
new Object[] { STRING_U1, "\uFF22", -1 },
new Object[] { STRING_U1, "\uFF21\uFF22", -1 },
new Object[] { STRING_U1, "A", 65248 },
new Object[] { STRING_U2, "\uFF21\uFF22", 0 },
new Object[] { STRING_U2, "\uFF22", -1 },
new Object[] { STRING_U2, "\uFF21\uFF21", 1 },
new Object[] { STRING_U2, "A", 65248 },
new Object[] { STRING_M12, "\uFF21A", 0 },
new Object[] { STRING_M12, "A\uFF21", 65248 },
new Object[] { STRING_M12, "\uFF21\uFF21", -65248 },
new Object[] { STRING_M11, "A\uFF21", 0 },
new Object[] { STRING_M11, "\uFF21A", -65248 },
new Object[] { STRING_M11, "AA", 65248 }, };
}
@Test(dataProvider = "provider")
public void testCompareTo(String str, String anotherString, int expected) {
map.get(str)
.forEach(
(source, data) -> {
assertEquals(
data.compareTo(anotherString),
expected,
String.format(
"testing String(%s).compareTo(%s), source : %s, ",
escapeNonASCIIs(data),
escapeNonASCIIs(anotherString),
source));
});
}
}