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 --enable-preview -source ${jdk.version} -encoding utf8 TextBlockLang.java 29 * @run main/othervm --enable-preview TextBlockLang 30 */ 31 32 public class TextBlockLang { main(String... args)33 public static void main(String... args) { 34 test1(); 35 } 36 37 /* 38 * Test basic string functionality. 39 */ test1()40 static void test1() { 41 EQ(""" 42 """, ""); 43 EQ(""" 44 abc 45 """, "abc\n"); 46 EQ(""" 47 48 """, "\n"); 49 EQ(""" 50 " 51 """, "\"\n"); 52 EQ(""" 53 "" 54 """, "\"\"\n"); 55 EQ(""" 56 \""" 57 """, "\"\"\"\n"); 58 EQ(""" 59 "\"" 60 """, "\"\"\"\n"); 61 EQ(""" 62 ""\" 63 """, "\"\"\"\n"); 64 EQ(""" 65 \r 66 """, "\r\n"); 67 EQ(""" 68 \u2022 69 """, "\u2022\n"); 70 EQ(""" 71 • 72 """, "\u2022\n"); 73 LENGTH(""" 74 abc 75 """, 4); 76 } 77 78 79 /* 80 * Raise an exception if the string is not the expected length. 81 */ LENGTH(String string, int length)82 static void LENGTH(String string, int length) { 83 if (string == null || string.length() != length) { 84 System.err.println("Failed LENGTH"); 85 System.err.println(string + " " + length); 86 throw new RuntimeException("Failed LENGTH"); 87 } 88 } 89 90 /* 91 * Raise an exception if the two input strings are not equal. 92 */ EQ(String input, String expected)93 static void EQ(String input, String expected) { 94 if (input == null || expected == null || !expected.equals(input)) { 95 System.err.println("Failed EQ"); 96 System.err.println(); 97 System.err.println("Input:"); 98 System.err.println(input.replaceAll(" ", ".")); 99 System.err.println(); 100 System.err.println("Expected:"); 101 System.err.println(expected.replaceAll(" ", ".")); 102 throw new RuntimeException(); 103 } 104 } 105 } 106