|
1 /* |
|
2 * Copyright (c) 2017, 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 8166334 |
|
27 * @summary test shift-tab shortcuts "fixes" |
|
28 * @modules |
|
29 * jdk.jshell/jdk.internal.jshell.tool.resources:open |
|
30 * jdk.jshell/jdk.jshell:open |
|
31 * @build UITesting |
|
32 * @build ToolShiftTabTest |
|
33 * @run testng/timeout=300 ToolShiftTabTest |
|
34 */ |
|
35 |
|
36 import java.util.regex.Pattern; |
|
37 import org.testng.annotations.Test; |
|
38 |
|
39 @Test |
|
40 public class ToolShiftTabTest extends UITesting { |
|
41 |
|
42 // Shift-tab as escape sequence |
|
43 private String FIX = "\033\133\132"; |
|
44 |
|
45 public void testFixVariable() throws Exception { |
|
46 doRunTest((inputSink, out) -> { |
|
47 inputSink.write("3+4"); |
|
48 inputSink.write(FIX + "v"); |
|
49 inputSink.write("jj\n"); |
|
50 waitOutput(out, "jj ==> 7"); |
|
51 inputSink.write("jj\n"); |
|
52 waitOutput(out, "jj ==> 7"); |
|
53 }); |
|
54 } |
|
55 |
|
56 public void testFixMethod() throws Exception { |
|
57 doRunTest((inputSink, out) -> { |
|
58 inputSink.write("5.5 >= 3.1415926535"); |
|
59 inputSink.write(FIX + "m"); |
|
60 waitOutput(out, "boolean "); |
|
61 inputSink.write("mm\n"); |
|
62 waitOutput(out, "| created method mm()"); |
|
63 inputSink.write("mm()\n"); |
|
64 waitOutput(out, "==> true"); |
|
65 inputSink.write("/method\n"); |
|
66 waitOutput(out, "boolean mm()"); |
|
67 }); |
|
68 } |
|
69 |
|
70 public void testFixMethodVoid() throws Exception { |
|
71 doRunTest((inputSink, out) -> { |
|
72 inputSink.write("System.out.println(\"Testing\")"); |
|
73 inputSink.write(FIX + "m"); |
|
74 inputSink.write("p\n"); |
|
75 waitOutput(out, "| created method p()"); |
|
76 inputSink.write("p()\n"); |
|
77 waitOutput(out, "Testing"); |
|
78 inputSink.write("/method\n"); |
|
79 waitOutput(out, "void p()"); |
|
80 }); |
|
81 } |
|
82 |
|
83 public void testFixMethodNoLeaks() throws Exception { |
|
84 doRunTest((inputSink, out) -> { |
|
85 inputSink.write("4"); |
|
86 inputSink.write(FIX + "m"); |
|
87 inputSink.write("\u0003 55"); |
|
88 inputSink.write(FIX + "m"); |
|
89 inputSink.write("\u0003 55"); |
|
90 inputSink.write(FIX + "m"); |
|
91 inputSink.write("\u0003 55"); |
|
92 inputSink.write(FIX + "m"); |
|
93 inputSink.write("\u0003 55"); |
|
94 inputSink.write(FIX + "m"); |
|
95 inputSink.write("\u0003'X'"); |
|
96 inputSink.write(FIX + "m"); |
|
97 inputSink.write("nl\n"); |
|
98 waitOutput(out, "| created method nl()"); |
|
99 inputSink.write("/list\n"); |
|
100 waitOutput(out, Pattern.quote("1 : char nl() { return 'X'; }")); |
|
101 inputSink.write("true\n"); |
|
102 waitOutput(out, Pattern.quote("$2 ==> true")); |
|
103 inputSink.write("/list\n"); |
|
104 waitOutput(out, "2 : true"); |
|
105 }); |
|
106 } |
|
107 |
|
108 public void testFixImport() throws Exception { |
|
109 doRunTest((inputSink, out) -> { |
|
110 inputSink.write("Frame"); |
|
111 inputSink.write(FIX + "i"); |
|
112 inputSink.write("1"); |
|
113 inputSink.write(".WIDTH\n"); |
|
114 waitOutput(out, "==> 1"); |
|
115 inputSink.write("/import\n"); |
|
116 waitOutput(out, "| import java.awt.Frame"); |
|
117 |
|
118 inputSink.write("Object"); |
|
119 inputSink.write(FIX + "i"); |
|
120 waitOutput(out, "The identifier is resolvable in this context"); |
|
121 }); |
|
122 } |
|
123 |
|
124 public void testFixBad() throws Exception { |
|
125 doRunTest((inputSink, out) -> { |
|
126 inputSink.write("123"); |
|
127 inputSink.write(FIX + "z"); |
|
128 waitOutput(out, "Unexpected character after Shift-Tab"); |
|
129 }); |
|
130 } |
|
131 } |