author | rfield |
Sun, 25 Feb 2018 23:02:45 -0800 | |
changeset 48987 | 513e98643998 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
38418 | 1 |
/* |
48987
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
38418 | 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 |
|
48987
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
26 |
* @bug 8178821 8198670 |
38418 | 27 |
* @summary Test Completion |
28 |
* @modules jdk.internal.le/jdk.internal.jline |
|
29 |
* jdk.internal.le/jdk.internal.jline.console |
|
30 |
* jdk.internal.le/jdk.internal.jline.console.history |
|
31 |
* jdk.internal.le/jdk.internal.jline.extra |
|
32 |
* @build HistoryTest |
|
33 |
* @run testng HistoryTest |
|
34 |
*/ |
|
35 |
||
36 |
import java.io.ByteArrayInputStream; |
|
37 |
import java.io.ByteArrayOutputStream; |
|
38 |
import java.io.IOException; |
|
39 |
import java.util.Arrays; |
|
40 |
import java.util.Collection; |
|
41 |
import java.util.Collections; |
|
42 |
import java.util.concurrent.atomic.AtomicBoolean; |
|
43 |
||
44 |
import jdk.internal.jline.UnsupportedTerminal; |
|
45 |
import jdk.internal.jline.console.ConsoleReader; |
|
46 |
import jdk.internal.jline.console.history.MemoryHistory; |
|
47 |
import jdk.internal.jline.extra.EditingHistory; |
|
48 |
||
49 |
import org.testng.annotations.Test; |
|
50 |
||
51 |
import static org.testng.Assert.*; |
|
52 |
||
53 |
@Test |
|
54 |
public class HistoryTest { |
|
55 |
||
56 |
public void testHistory() throws IOException { |
|
57 |
ConsoleReader in = new ConsoleReader(new ByteArrayInputStream(new byte[0]), new ByteArrayOutputStream(), new UnsupportedTerminal()); |
|
58 |
AtomicBoolean complete = new AtomicBoolean(); |
|
59 |
EditingHistory history = new EditingHistory(in, Collections.emptyList()) { |
|
60 |
@Override |
|
61 |
protected boolean isComplete(CharSequence input) { |
|
62 |
return complete.get(); |
|
63 |
} |
|
64 |
}; |
|
65 |
complete.set(false); history.add("void test() {"); |
|
66 |
complete.set(false); history.add(" System.err.println(1);"); |
|
67 |
complete.set(true); history.add("}"); |
|
68 |
complete.set(true); history.add("/exit"); |
|
69 |
||
70 |
previousAndAssert(history, "/exit"); |
|
71 |
||
72 |
history.previous(); history.previous(); history.previous(); |
|
73 |
||
74 |
complete.set(false); history.add("void test() { /*changed*/"); |
|
75 |
||
76 |
complete.set(true); |
|
77 |
previousAndAssert(history, "}"); |
|
78 |
previousAndAssert(history, " System.err.println(1);"); |
|
79 |
previousAndAssert(history, "void test() {"); |
|
80 |
||
81 |
assertFalse(history.previous()); |
|
82 |
||
83 |
nextAndAssert(history, " System.err.println(1);"); |
|
84 |
nextAndAssert(history, "}"); |
|
85 |
nextAndAssert(history, ""); |
|
86 |
||
87 |
complete.set(false); history.add(" System.err.println(2);"); |
|
88 |
complete.set(true); history.add("} /*changed*/"); |
|
89 |
||
90 |
assertEquals(history.size(), 7); |
|
91 |
||
92 |
Collection<? extends String> persistentHistory = history.save(); |
|
93 |
||
94 |
history = new EditingHistory(in, persistentHistory) { |
|
95 |
@Override |
|
96 |
protected boolean isComplete(CharSequence input) { |
|
97 |
return complete.get(); |
|
98 |
} |
|
99 |
}; |
|
100 |
||
101 |
previousSnippetAndAssert(history, "void test() { /*changed*/"); |
|
102 |
previousSnippetAndAssert(history, "/exit"); |
|
103 |
previousSnippetAndAssert(history, "void test() {"); |
|
104 |
||
105 |
assertFalse(history.previousSnippet()); |
|
106 |
||
107 |
nextSnippetAndAssert(history, "/exit"); |
|
108 |
nextSnippetAndAssert(history, "void test() { /*changed*/"); |
|
109 |
nextSnippetAndAssert(history, ""); |
|
110 |
||
111 |
assertFalse(history.nextSnippet()); |
|
112 |
||
113 |
complete.set(false); history.add("{"); |
|
114 |
complete.set(true); history.add("}"); |
|
115 |
||
116 |
persistentHistory = history.save(); |
|
117 |
||
118 |
history = new EditingHistory(in, persistentHistory) { |
|
119 |
@Override |
|
120 |
protected boolean isComplete(CharSequence input) { |
|
121 |
return complete.get(); |
|
122 |
} |
|
123 |
}; |
|
124 |
||
125 |
previousSnippetAndAssert(history, "{"); |
|
126 |
previousSnippetAndAssert(history, "void test() { /*changed*/"); |
|
127 |
previousSnippetAndAssert(history, "/exit"); |
|
128 |
previousSnippetAndAssert(history, "void test() {"); |
|
129 |
||
130 |
while (history.next()); |
|
131 |
||
132 |
complete.set(true); history.add("/*current1*/"); |
|
133 |
complete.set(true); history.add("/*current2*/"); |
|
134 |
complete.set(true); history.add("/*current3*/"); |
|
135 |
||
48987
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
136 |
assertEquals(history.entries(true), Arrays.asList("/*current1*/", "/*current2*/", "/*current3*/")); |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
137 |
assertEquals(history.entries(false), Arrays.asList( |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
138 |
"void test() {", |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
139 |
" System.err.println(1);", |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
140 |
"}", |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
141 |
"/exit", |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
142 |
"void test() { /*changed*/", |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
143 |
" System.err.println(2);", |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
144 |
"} /*changed*/", |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
145 |
"{", |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
146 |
"}", |
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
147 |
"/*current1*/", "/*current2*/", "/*current3*/"), history.entries(false).toString()); |
38418 | 148 |
|
149 |
history.remove(0); |
|
150 |
||
48987
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
151 |
assertEquals(history.entries(true), Arrays.asList("/*current1*/", "/*current2*/", "/*current3*/")); |
38418 | 152 |
|
153 |
while (history.size() > 2) |
|
154 |
history.remove(0); |
|
155 |
||
48987
513e98643998
8198670: [testbug] Test jdk/internal/jline/extra/HistoryTest.java is broken after 8166232
rfield
parents:
47216
diff
changeset
|
156 |
assertEquals(history.entries(true), Arrays.asList("/*current2*/", "/*current3*/")); |
38418 | 157 |
|
158 |
for (int i = 0; i < MemoryHistory.DEFAULT_MAX_SIZE * 2; i++) { |
|
159 |
complete.set(true); history.add("/exit"); |
|
160 |
} |
|
161 |
||
162 |
complete.set(false); history.add("void test() { /*after full*/"); |
|
163 |
complete.set(false); history.add(" System.err.println(1);"); |
|
164 |
complete.set(true); history.add("}"); |
|
165 |
||
166 |
previousSnippetAndAssert(history, "void test() { /*after full*/"); |
|
44701
73cb7afafdff
8178821: jshell tool: ctrl-down does nothing in current context
jlahoda
parents:
38418
diff
changeset
|
167 |
nextSnippetAndAssert(history, ""); |
73cb7afafdff
8178821: jshell tool: ctrl-down does nothing in current context
jlahoda
parents:
38418
diff
changeset
|
168 |
|
73cb7afafdff
8178821: jshell tool: ctrl-down does nothing in current context
jlahoda
parents:
38418
diff
changeset
|
169 |
assertFalse(history.nextSnippet()); |
73cb7afafdff
8178821: jshell tool: ctrl-down does nothing in current context
jlahoda
parents:
38418
diff
changeset
|
170 |
|
73cb7afafdff
8178821: jshell tool: ctrl-down does nothing in current context
jlahoda
parents:
38418
diff
changeset
|
171 |
while (history.previousSnippet()) |
73cb7afafdff
8178821: jshell tool: ctrl-down does nothing in current context
jlahoda
parents:
38418
diff
changeset
|
172 |
; |
73cb7afafdff
8178821: jshell tool: ctrl-down does nothing in current context
jlahoda
parents:
38418
diff
changeset
|
173 |
|
73cb7afafdff
8178821: jshell tool: ctrl-down does nothing in current context
jlahoda
parents:
38418
diff
changeset
|
174 |
while (history.nextSnippet()) |
73cb7afafdff
8178821: jshell tool: ctrl-down does nothing in current context
jlahoda
parents:
38418
diff
changeset
|
175 |
; |
38418 | 176 |
} |
177 |
||
178 |
private void previousAndAssert(EditingHistory history, String expected) { |
|
179 |
assertTrue(history.previous()); |
|
180 |
assertEquals(history.current().toString(), expected); |
|
181 |
} |
|
182 |
||
183 |
private void nextAndAssert(EditingHistory history, String expected) { |
|
184 |
assertTrue(history.next()); |
|
185 |
assertEquals(history.current().toString(), expected); |
|
186 |
} |
|
187 |
||
188 |
private void previousSnippetAndAssert(EditingHistory history, String expected) { |
|
189 |
assertTrue(history.previousSnippet()); |
|
190 |
assertEquals(history.current().toString(), expected); |
|
191 |
} |
|
192 |
||
193 |
private void nextSnippetAndAssert(EditingHistory history, String expected) { |
|
194 |
assertTrue(history.nextSnippet()); |
|
195 |
assertEquals(history.current().toString(), expected); |
|
196 |
} |
|
197 |
||
198 |
} |