27 import java.util.ArrayList; |
27 import java.util.ArrayList; |
28 import java.util.Arrays; |
28 import java.util.Arrays; |
29 import java.util.Collections; |
29 import java.util.Collections; |
30 import java.util.HashMap; |
30 import java.util.HashMap; |
31 import java.util.List; |
31 import java.util.List; |
|
32 import java.util.Locale; |
32 import java.util.Map; |
33 import java.util.Map; |
33 import java.util.function.Consumer; |
34 import java.util.function.Consumer; |
34 import java.util.function.Function; |
35 import java.util.function.Function; |
35 import java.util.function.Predicate; |
36 import java.util.function.Predicate; |
36 import java.util.prefs.AbstractPreferences; |
37 import java.util.prefs.AbstractPreferences; |
192 public void test(String[] args, ReplTest... tests) { |
193 public void test(String[] args, ReplTest... tests) { |
193 test(true, args, tests); |
194 test(true, args, tests); |
194 } |
195 } |
195 |
196 |
196 public void test(boolean isDefaultStartUp, String[] args, ReplTest... tests) { |
197 public void test(boolean isDefaultStartUp, String[] args, ReplTest... tests) { |
197 test(isDefaultStartUp, args, DEFAULT_STARTUP_MESSAGE, tests); |
198 test(Locale.ROOT, isDefaultStartUp, args, DEFAULT_STARTUP_MESSAGE, tests); |
198 } |
199 } |
199 |
200 |
200 public void test(boolean isDefaultStartUp, String[] args, String startUpMessage, ReplTest... tests) { |
201 public void test(Locale locale, boolean isDefaultStartUp, String[] args, String startUpMessage, ReplTest... tests) { |
201 this.isDefaultStartUp = isDefaultStartUp; |
202 this.isDefaultStartUp = isDefaultStartUp; |
202 initSnippets(); |
203 initSnippets(); |
203 ReplTest[] wtests = new ReplTest[tests.length + 3]; |
204 ReplTest[] wtests = new ReplTest[tests.length + 3]; |
204 wtests[0] = a -> assertCommandCheckOutput(a, "<start>", |
205 wtests[0] = a -> assertCommandCheckOutput(a, "<start>", |
205 s -> assertTrue(s.startsWith(startUpMessage), "Expected start-up message '" + startUpMessage + "' Got: " + s)); |
206 s -> assertTrue(s.startsWith(startUpMessage), "Expected start-up message '" + startUpMessage + "' Got: " + s)); |
206 wtests[1] = a -> assertCommand(a, "/debug 0", null); |
207 wtests[1] = a -> assertCommand(a, "/debug 0", null); |
207 System.arraycopy(tests, 0, wtests, 2, tests.length); |
208 System.arraycopy(tests, 0, wtests, 2, tests.length); |
208 wtests[tests.length + 2] = a -> assertCommand(a, "/exit", null); |
209 wtests[tests.length + 2] = a -> assertCommand(a, "/exit", null); |
209 testRaw(args, wtests); |
210 testRaw(locale, args, wtests); |
210 } |
211 } |
211 |
212 |
212 private void initSnippets() { |
213 private void initSnippets() { |
213 keys = new ArrayList<>(); |
214 keys = new ArrayList<>(); |
214 variables = new HashMap<>(); |
215 variables = new HashMap<>(); |
228 @BeforeMethod |
229 @BeforeMethod |
229 public void setUp() { |
230 public void setUp() { |
230 prefs = new MemoryPreferences(); |
231 prefs = new MemoryPreferences(); |
231 } |
232 } |
232 |
233 |
233 public void testRaw(String[] args, ReplTest... tests) { |
234 public void testRaw(Locale locale, String[] args, ReplTest... tests) { |
234 cmdin = new WaitingTestingInputStream(); |
235 cmdin = new WaitingTestingInputStream(); |
235 cmdout = new ByteArrayOutputStream(); |
236 cmdout = new ByteArrayOutputStream(); |
236 cmderr = new ByteArrayOutputStream(); |
237 cmderr = new ByteArrayOutputStream(); |
237 console = new PromptedCommandOutputStream(tests); |
238 console = new PromptedCommandOutputStream(tests); |
238 userin = new TestingInputStream(); |
239 userin = new TestingInputStream(); |
244 new PrintStream(cmderr), |
245 new PrintStream(cmderr), |
245 new PrintStream(console), |
246 new PrintStream(console), |
246 userin, |
247 userin, |
247 new PrintStream(userout), |
248 new PrintStream(userout), |
248 new PrintStream(usererr), |
249 new PrintStream(usererr), |
249 prefs); |
250 prefs, |
|
251 locale); |
250 repl.testPrompt = true; |
252 repl.testPrompt = true; |
251 try { |
253 try { |
252 repl.start(args); |
254 repl.start(args); |
253 } catch (Exception ex) { |
255 } catch (Exception ex) { |
254 fail("Repl tool died with exception", ex); |
256 fail("Repl tool died with exception", ex); |
256 // perform internal consistency checks on state, if desired |
258 // perform internal consistency checks on state, if desired |
257 String cos = getCommandOutput(); |
259 String cos = getCommandOutput(); |
258 String ceos = getCommandErrorOutput(); |
260 String ceos = getCommandErrorOutput(); |
259 String uos = getUserOutput(); |
261 String uos = getUserOutput(); |
260 String ueos = getUserErrorOutput(); |
262 String ueos = getUserErrorOutput(); |
261 assertTrue((cos.isEmpty() || cos.startsWith("| Goodbye")), |
263 assertTrue((cos.isEmpty() || cos.startsWith("| Goodbye") || !locale.equals(Locale.ROOT)), |
262 "Expected a goodbye, but got: " + cos); |
264 "Expected a goodbye, but got: " + cos); |
263 assertTrue(ceos.isEmpty(), "Expected empty error output, got: " + ceos); |
265 assertTrue(ceos.isEmpty(), "Expected empty error output, got: " + ceos); |
264 assertTrue(uos.isEmpty(), "Expected empty output, got: " + uos); |
266 assertTrue(uos.isEmpty(), "Expected empty output, got: " + uos); |
265 assertTrue(ueos.isEmpty(), "Expected empty error output, got: " + ueos); |
267 assertTrue(ueos.isEmpty(), "Expected empty error output, got: " + ueos); |
266 } |
268 } |
457 completions.toString()); |
459 completions.toString()); |
458 } |
460 } |
459 |
461 |
460 private List<String> computeCompletions(String code, boolean isSmart) { |
462 private List<String> computeCompletions(String code, boolean isSmart) { |
461 JShellTool js = this.repl != null ? this.repl |
463 JShellTool js = this.repl != null ? this.repl |
462 : new JShellTool(null, null, null, null, null, null, null, prefs); |
464 : new JShellTool(null, null, null, null, null, null, null, prefs, Locale.ROOT); |
463 int cursor = code.indexOf('|'); |
465 int cursor = code.indexOf('|'); |
464 code = code.replace("|", ""); |
466 code = code.replace("|", ""); |
465 assertTrue(cursor > -1, "'|' not found: " + code); |
467 assertTrue(cursor > -1, "'|' not found: " + code); |
466 List<Suggestion> completions = |
468 List<Suggestion> completions = |
467 js.commandCompletionSuggestions(code, cursor, new int[1]); //XXX: ignoring anchor for now |
469 js.commandCompletionSuggestions(code, cursor, new int[1]); //XXX: ignoring anchor for now |