test/jdk/java/lang/String/StripIndent.java
author jlahoda
Mon, 21 Oct 2019 15:38:26 +0200
changeset 58713 ad69fd32778e
parent 55260 cc0f117f4405
child 59037 3d2575331a41
permissions -rw-r--r--
8226585: Improve javac messages for using a preview API Summary: Avoiding deprecation for removal for APIs associated with preview features, the features are marked with an annotation, and errors/warnings are produced for them based on the annotation. Reviewed-by: erikj, mcimadamore, alanb Contributed-by: joe.darcy@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55260
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
     1
/*
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
     4
 *
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
     8
 *
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    13
 * accompanied this code).
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    14
 *
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    18
 *
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    21
 * questions.
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    22
 */
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    23
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    24
/*
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    25
 * @test
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    26
 * @bug 8223775
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    27
 * @summary This exercises String#stripIndent patterns and limits.
58713
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55260
diff changeset
    28
 * @compile --enable-preview -source 14 StripIndent.java
ad69fd32778e 8226585: Improve javac messages for using a preview API
jlahoda
parents: 55260
diff changeset
    29
 * @run main/othervm --enable-preview StripIndent
55260
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    30
 */
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    31
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    32
public class StripIndent {
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    33
    public static void main(String... arg) {
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    34
        test1();
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    35
    }
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    36
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    37
    /*
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    38
     * Case combinations.
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    39
     */
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    40
    static void test1() {
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    41
        verify("", "");
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    42
        verify("abc", "abc");
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    43
        verify("   abc", "abc");
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    44
        verify("abc   ", "abc");
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    45
        verify("   abc\n   def\n   ", "abc\ndef\n");
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    46
        verify("   abc\n   def\n", "   abc\n   def\n");
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    47
        verify("   abc\n   def", "abc\ndef");
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    48
        verify("   abc\n      def\n   ", "abc\n   def\n");
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    49
    }
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    50
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    51
    static void verify(String a, String b) {
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    52
        if (!a.stripIndent().equals(b)) {
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    53
            System.err.format("\"%s\" not equal \"%s\"%n", a, b);
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    54
            throw new RuntimeException();
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    55
        }
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    56
    }
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    57
}
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    58
cc0f117f4405 8223775: String::stripIndent (Preview)
jlaskey
parents:
diff changeset
    59