1 /*
2  * Copyright (c) 2017, 2018, 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 8182297
27  * @summary Verify that pasting multi-line snippets works properly.
28  * @library /tools/lib
29  * @modules
30  *     java.base/java.lang:open
31  *     java.base/java.io:open
32  *     jdk.compiler/com.sun.tools.javac.api
33  *     jdk.compiler/com.sun.tools.javac.main
34  *     jdk.jshell/jdk.internal.jshell.tool.resources:open
35  *     jdk.jshell/jdk.jshell:open
36  * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
37  * @build Compiler UITesting
38  * @build PasteAndMeasurementsUITest
39  * @run testng/othervm PasteAndMeasurementsUITest
40  */
41 
42 import java.io.Console;
43 import java.lang.reflect.Constructor;
44 import java.lang.reflect.Field;
45 
46 import org.testng.annotations.Test;
47 
48 @Test
49 public class PasteAndMeasurementsUITest extends UITesting {
50 
PasteAndMeasurementsUITest()51     public PasteAndMeasurementsUITest() {
52         super(true);
53     }
54 
testPrevNextSnippet()55     public void testPrevNextSnippet() throws Exception {
56         Field cons = System.class.getDeclaredField("cons");
57         cons.setAccessible(true);
58         Constructor console = Console.class.getDeclaredConstructor();
59         console.setAccessible(true);
60         cons.set(null, console.newInstance());
61         doRunTest((inputSink, out) -> {
62             inputSink.write("void test1() {\nSystem.err.println(1);\n}\n" + //LOC +
63                             "void test2() {\nSystem.err.println(1);\n}\n"/* + LOC + LOC + LOC + LOC + LOC*/);
64             waitOutput(out,       "void test1\\(\\)\u001B\\[2D\u001B\\[2C \\{\n" +
65                             CONTINUATION_PROMPT + "System.err.println\\(1\\)\u001B\\[3D\u001B\\[3C;\n" +
66                             CONTINUATION_PROMPT + "\\}\u001B\\[2A\u001B\\[12C\n\n\u001B\\[C\n" +
67                             "\u001B\\[\\?2004l\\|  created method test1\\(\\)\n" +
68                             "\u001B\\[\\?2004h" + PROMPT + "void test2\\(\\)\u001B\\[2D\u001B\\[2C \\{\n" +
69                             CONTINUATION_PROMPT + "System.err.println\\(1\\)\u001B\\[3D\u001B\\[3C;\n" +
70                             CONTINUATION_PROMPT + "\\}\u001B\\[2A\u001B\\[12C\n\n\u001B\\[C\n" +
71                             "\u001B\\[\\?2004l\\|  created method test2\\(\\)\n" +
72                             "\u001B\\[\\?2004h" + PROMPT);
73         });
74     }
75         private static final String LOC = "\033[12;1R";
76 }
77