test/jdk/java/lang/String/CompactString/StartsWith.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 33663 jdk/test/java/lang/String/CompactString/StartsWith.java@2cd62a4bd471
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     1
/*
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     4
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     8
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    13
 * accompanied this code).
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    14
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    18
 *
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    21
 * questions.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    22
 */
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    23
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    24
import org.testng.annotations.DataProvider;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    25
import org.testng.annotations.Test;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    26
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    27
import static org.testng.Assert.assertEquals;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    28
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    29
/*
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    30
 * @test
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    31
 * @bug 8077559
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    32
 * @summary Tests Compact String. This one is for String.startsWith.
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    33
 * @run testng/othervm -XX:+CompactStrings StartsWith
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    34
 * @run testng/othervm -XX:-CompactStrings StartsWith
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    35
 */
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    36
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    37
public class StartsWith extends CompactString {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    38
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    39
    @DataProvider
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    40
    public Object[][] provider() {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    41
        return new Object[][] {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    42
                new Object[] {STRING_EMPTY, "", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    43
                new Object[] {STRING_EMPTY, "A", 0, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    44
                new Object[] {STRING_EMPTY, "", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    45
                new Object[] {STRING_EMPTY, "", -1, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    46
                new Object[] {STRING_L1, "A", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    47
                new Object[] {STRING_L1, "A", -1, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    48
                new Object[] {STRING_L1, "A", 1, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    49
                new Object[] {STRING_L2, "B", 1, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    50
                new Object[] {STRING_L2, "B", 0, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    51
                new Object[] {STRING_L2, "A", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    52
                new Object[] {STRING_L2, "AB", 1, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    53
                new Object[] {STRING_L4, "ABC", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    54
                new Object[] {STRING_LLONG, "ABCDEFGH", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    55
                new Object[] {STRING_LLONG, "ABCDE", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    56
                new Object[] {STRING_LLONG, "CDE", 0, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    57
                new Object[] {STRING_LLONG, "FG", 5, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    58
                new Object[] {STRING_U1, "\uFF21", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    59
                new Object[] {STRING_U1, "", 1, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    60
                new Object[] {STRING_U1, "\uFF21", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    61
                new Object[] {STRING_U1, "A", 0, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    62
                new Object[] {STRING_U2, "\uFF21\uFF22", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    63
                new Object[] {STRING_U2, "\uFF21", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    64
                new Object[] {STRING_U2, "\uFF22", 0, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    65
                new Object[] {STRING_U2, "", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    66
                new Object[] {STRING_M12, "\uFF21", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    67
                new Object[] {STRING_M12, "\uFF21A", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    68
                new Object[] {STRING_M12, "A", 0, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    69
                new Object[] {STRING_M12, "\uFF21A", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    70
                new Object[] {STRING_M12, "A", 1, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    71
                new Object[] {STRING_M11, "A", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    72
                new Object[] {STRING_M11, "A\uFF21", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    73
                new Object[] {STRING_M11, "A\uFF21", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    74
                new Object[] {STRING_M11, "\uFF21", 1, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    75
                new Object[] {STRING_UDUPLICATE,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    76
                        "\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22",
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    77
                        0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    78
                new Object[] {STRING_UDUPLICATE,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    79
                        "\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    80
                new Object[] {STRING_UDUPLICATE,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    81
                        "\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22", 2, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    82
                new Object[] {STRING_UDUPLICATE,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    83
                        "\uFF21\uFF22\uFF21\uFF22\uFF21\uFF22", 5, false},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    84
                new Object[] {STRING_MDUPLICATE1,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    85
                        "\uFF21A\uFF21A\uFF21A\uFF21A\uFF21A", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    86
                new Object[] {STRING_MDUPLICATE1,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    87
                        "\uFF21A\uFF21A\uFF21A\uFF21A\uFF21", 0, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    88
                new Object[] {STRING_MDUPLICATE1, "A\uFF21A\uFF21A\uFF21A", 1, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    89
                new Object[] {STRING_SUPPLEMENTARY, "\uDC01\uFF21", 3, true},
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    90
        };
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    91
    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    92
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    93
    @Test(dataProvider = "provider")
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    94
    public void testStartsWith(String str, String prefix, int toffset,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    95
            boolean expected) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    96
        map.get(str)
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    97
                .forEach(
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    98
                        (source, data) -> {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
    99
                            assertEquals(
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   100
                                    data.startsWith(prefix, toffset),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   101
                                    expected,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   102
                                    String.format(
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   103
                                            "testing String(%s).startsWith(%s, %d), source : %s, ",
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   104
                                            escapeNonASCIIs(data),
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   105
                                            escapeNonASCIIs(prefix), toffset,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   106
                                            source));
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   107
                        });
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   108
    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents:
diff changeset
   109
}