jdk

Форк
0
/
TextBlockLang.java 
131 строка · 3.5 Кб
1
/*
2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 */
23

24
/*
25
 * @test
26
 * @bug 8223967
27
 * @summary Unit tests for Text Block language changes
28
 * @compile -encoding utf8 TextBlockLang.java
29
 * @run main TextBlockLang
30
 */
31

32
public class TextBlockLang {
33
    public static void main(String... args) {
34
        test1();
35
        test2();
36
        test3();
37
    }
38

39
    /*
40
     * Test basic string functionality.
41
     */
42
    static void test1() {
43
        EQ("""
44
           """, "");
45
        EQ("""
46
            abc
47
            """, "abc\n");
48
        EQ("""
49

50
           """, "\n");
51
        EQ("""
52
            "
53
            """, "\"\n");
54
        EQ("""
55
            ""
56
            """, "\"\"\n");
57
        EQ("""
58
           \"""
59
           """, "\"\"\"\n");
60
        EQ("""
61
           "\""
62
           """, "\"\"\"\n");
63
        EQ("""
64
           ""\"
65
           """, "\"\"\"\n");
66
        EQ("""
67
            \r
68
            """, "\r\n");
69
        EQ("""
70
            \u2022
71
            """, "\u2022\n");
72
        EQ("""
73
74
            """, "\u2022\n");
75
        LENGTH("""
76
            abc
77
            """, 4);
78
    }
79

80
    /*
81
     * Test escape-S.
82
     */
83
    static void test2() {
84
        if ('\s' != ' ') {
85
            throw new RuntimeException("Failed character escape-S");
86
        }
87
        EQ("\s", " ");
88
        EQ("""
89
           \s
90
           """, " \n");
91
    }
92

93
    /*
94
     * Test escape line terminator.
95
     */
96
    static void test3() {
97
        EQ("""
98
           abc \
99
           """, "abc ");
100
        EQ("\\\n".translateEscapes(), "");
101
        EQ("\\\r\n".translateEscapes(), "");
102
        EQ("\\\r".translateEscapes(), "");
103
    }
104

105
    /*
106
     * Raise an exception if the string is not the expected length.
107
     */
108
    static void LENGTH(String string, int length) {
109
        if (string == null || string.length() != length) {
110
            System.err.println("Failed LENGTH");
111
            System.err.println(string + " " + length);
112
            throw new RuntimeException("Failed LENGTH");
113
        }
114
    }
115

116
    /*
117
     * Raise an exception if the two input strings are not equal.
118
     */
119
    static void EQ(String input, String expected) {
120
        if (input == null || expected == null || !expected.equals(input)) {
121
            System.err.println("Failed EQ");
122
            System.err.println();
123
            System.err.println("Input:");
124
            System.err.println(input.replaceAll(" ", "."));
125
            System.err.println();
126
            System.err.println("Expected:");
127
            System.err.println(expected.replaceAll(" ", "."));
128
            throw new RuntimeException();
129
        }
130
    }
131
}
132

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.