diff -r 14deea5f86f1 -r 7af94fd75ede langtools/test/jdk/jshell/ToolBasicTest.java --- a/langtools/test/jdk/jshell/ToolBasicTest.java Thu Nov 26 17:38:15 2015 +0530 +++ b/langtools/test/jdk/jshell/ToolBasicTest.java Mon Nov 30 17:31:55 2015 +0100 @@ -23,6 +23,7 @@ /* * @test + * @bug 8143037 * @summary Tests for Basic tests for REPL tool * @ignore 8139873 * @library /tools/lib @@ -124,28 +125,28 @@ interrupt, (a) -> assertCommand(a, "int a\u0003", ""), (a) -> assertCommand(a, "int a = 2 + 2\u0003", ""), - (a) -> assertCommandCheckOutput(a, "/v", assertVariables()), + (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), (a) -> evaluateExpression(a, "int", "2", "2"), - (a) -> assertCommandCheckOutput(a, "/v", assertVariables()), + (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), (a) -> assertCommand(a, "void f() {", ""), (a) -> assertCommand(a, "int q = 10;" + s, ""), interrupt, (a) -> assertCommand(a, "void f() {}\u0003", ""), - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), + (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), (a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"), - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), + (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), (a) -> assertCommand(a, "class A {" + s, ""), interrupt, (a) -> assertCommand(a, "class A {}\u0003", ""), - (a) -> assertCommandCheckOutput(a, "/c", assertClasses()), + (a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), (a) -> assertClass(a, "interface A {}", "interface", "A"), - (a) -> assertCommandCheckOutput(a, "/c", assertClasses()), + (a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), (a) -> assertCommand(a, "import java.util.stream." + s, ""), interrupt, (a) -> assertCommand(a, "import java.util.stream.\u0003", ""), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()), + (a) -> assertCommandCheckOutput(a, "/imports", assertImports()), (a) -> assertImport(a, "import java.util.stream.Stream", "", "java.util.stream.Stream"), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()) + (a) -> assertCommandCheckOutput(a, "/imports", assertImports()) ); } } @@ -265,10 +266,10 @@ public void testDebug() { test( - (a) -> assertCommand(a, "/db", "| Debugging on\n"), + (a) -> assertCommand(a, "/deb", "| Debugging on\n"), (a) -> assertCommand(a, "/debug", "| Debugging off\n"), (a) -> assertCommand(a, "/debug", "| Debugging on\n"), - (a) -> assertCommand(a, "/db", "| Debugging off\n") + (a) -> assertCommand(a, "/deb", "| Debugging off\n") ); } @@ -295,106 +296,70 @@ public void defineVariables() { test( - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/v", assertVariables()), (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), (a) -> assertVariable(a, "int", "a"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/v", assertVariables()), (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), (a) -> assertVariable(a, "double", "a", "1", "1.0"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/v", assertVariables()), (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), (a) -> evaluateExpression(a, "double", "2 * a", "2.0"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/v", assertVariables()), (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()) ); } public void defineMethods() { test( - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), (a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), (a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), (a) -> assertMethod(a, "void g() {}", "()void", "g"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()) ); } public void defineClasses() { test( - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/c", assertClasses()), (a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), (a) -> assertClass(a, "class A { }", "class", "A"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/c", assertClasses()), (a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), (a) -> assertClass(a, "interface A { }", "interface", "A"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/c", assertClasses()), (a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), (a) -> assertClass(a, "enum A { }", "enum", "A"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/c", assertClasses()), (a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), (a) -> assertClass(a, "@interface A { }", "@interface", "A"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/c", assertClasses()), (a) -> assertCommandCheckOutput(a, "/classes", assertClasses()) ); } public void defineImports() { test( - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()), (a) -> assertCommandCheckOutput(a, "/imports", assertImports()), (a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()), (a) -> assertCommandCheckOutput(a, "/imports", assertImports()), (a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()), (a) -> assertCommandCheckOutput(a, "/imports", assertImports()), (a) -> assertImport(a, "import static java.lang.Math.PI;", "static", "java.lang.Math.PI"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()), (a) -> assertCommandCheckOutput(a, "/imports", assertImports()), (a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"), - (a) -> assertCommandCheckOutput(a, "/l", assertList()), (a) -> assertCommandCheckOutput(a, "/list", assertList()), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()), (a) -> assertCommandCheckOutput(a, "/imports", assertImports()) ); } @@ -405,7 +370,7 @@ compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }"); Path classpath = compiler.getPath(outDir); test( - (a) -> assertCommand(a, "/cp " + classpath, String.format("| Path %s added to classpath\n", classpath)), + (a) -> assertCommand(a, "/classpath " + classpath, String.format("| Path %s added to classpath\n", classpath)), (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "\"A\"") ); test(new String[] { "-cp", classpath.toString() }, @@ -471,20 +436,20 @@ public void testReset() { test( (a) -> assertReset(a, "/r"), - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), + (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), (a) -> assertVariable(a, "int", "x"), - (a) -> assertCommandCheckOutput(a, "/v", assertVariables()), + (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), (a) -> assertMethod(a, "void f() { }", "()void", "f"), - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), + (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), (a) -> assertClass(a, "class A { }", "class", "A"), - (a) -> assertCommandCheckOutput(a, "/c", assertClasses()), + (a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), (a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()), + (a) -> assertCommandCheckOutput(a, "/imports", assertImports()), (a) -> assertReset(a, "/reset"), - (a) -> assertCommandCheckOutput(a, "/v", assertVariables()), - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), - (a) -> assertCommandCheckOutput(a, "/c", assertClasses()), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()) + (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), + (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), + (a) -> assertCommandCheckOutput(a, "/classes", assertClasses()), + (a) -> assertCommandCheckOutput(a, "/imports", assertImports()) ); } @@ -508,11 +473,11 @@ loadClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"); loadImport(a, "import java.util.stream.*;", "", "java.util.stream.*"); - assertCommandCheckOutput(a, "/c", assertClasses()); + assertCommandCheckOutput(a, "/classes", assertClasses()); }, - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), - (a) -> assertCommandCheckOutput(a, "/v", assertVariables()), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()) + (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), + (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), + (a) -> assertCommandCheckOutput(a, "/imports", assertImports()) ); Path unknown = compiler.getPath("UNKNOWN.repl"); test( @@ -531,15 +496,13 @@ "int a;", "class A { public String toString() { return \"A\"; } }" ); - for (String s : new String[]{"/s", "/save"}) { - test( - (a) -> assertVariable(a, "int", "a"), - (a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), - (a) -> assertCommand(a, s + " " + path.toString(), "") - ); - assertEquals(Files.readAllLines(path), list); - } - for (String s : new String[]{"/s", "/save"}) { + test( + (a) -> assertVariable(a, "int", "a"), + (a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), + (a) -> assertCommand(a, "/save " + path.toString(), "") + ); + assertEquals(Files.readAllLines(path), list); + { List output = new ArrayList<>(); test( (a) -> assertCommand(a, "int a;", null), @@ -550,24 +513,22 @@ .map(str -> str.substring(str.indexOf(':') + 2)) .filter(str -> !str.startsWith("/")) .collect(Collectors.toList()))), - (a) -> assertCommand(a, s + " all " + path.toString(), "") + (a) -> assertCommand(a, "/save all " + path.toString(), "") ); assertEquals(Files.readAllLines(path), output); } - for (String s : new String[]{"/s", "/save"}) { - List output = new ArrayList<>(); - test( - (a) -> assertVariable(a, "int", "a"), - (a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), - (a) -> assertCommandCheckOutput(a, "/h", (out) -> - output.addAll(Stream.of(out.split("\n")) - .filter(str -> !str.isEmpty()) - .collect(Collectors.toList()))), - (a) -> assertCommand(a, s + " history " + path.toString(), "") - ); - output.add(s + " history " + path.toString()); - assertEquals(Files.readAllLines(path), output); - } + List output = new ArrayList<>(); + test( + (a) -> assertVariable(a, "int", "a"), + (a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"), + (a) -> assertCommandCheckOutput(a, "/history", (out) -> + output.addAll(Stream.of(out.split("\n")) + .filter(str -> !str.isEmpty()) + .collect(Collectors.toList()))), + (a) -> assertCommand(a, "/save history " + path.toString(), "") + ); + output.add("/save history " + path.toString()); + assertEquals(Files.readAllLines(path), output); } public void testStartSet() throws BackingStoreException { @@ -579,7 +540,7 @@ (a) -> assertVariable(a, "double", "b", "10", "10.0"), (a) -> assertMethod(a, "void f() {}", "()V", "f"), (a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), - (a) -> assertCommand(a, "/s " + startUpFile.toString(), null), + (a) -> assertCommand(a, "/save " + startUpFile.toString(), null), (a) -> assertCommand(a, "/setstart " + startUpFile.toString(), null) ); Path unknown = compiler.getPath("UNKNOWN"); @@ -593,11 +554,11 @@ loadVariable(a, "double", "b", "10.0", "10.0"); loadMethod(a, "void f() {}", "()void", "f"); loadImport(a, "import java.util.stream.*;", "", "java.util.stream.*"); - assertCommandCheckOutput(a, "/c", assertClasses()); + assertCommandCheckOutput(a, "/classes", assertClasses()); }, - (a) -> assertCommandCheckOutput(a, "/v", assertVariables()), - (a) -> assertCommandCheckOutput(a, "/m", assertMethods()), - (a) -> assertCommandCheckOutput(a, "/i", assertImports()) + (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()), + (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()), + (a) -> assertCommandCheckOutput(a, "/imports", assertImports()) ); } finally { removeStartup(); @@ -618,24 +579,14 @@ } public void testEmptyClassPath() { - String[] commands = {"/cp", "/classpath"}; - test(Stream.of(commands) - .map(cmd -> (ReplTest) after -> assertCommand(after, cmd, "| /classpath requires a path argument\n")) - .toArray(ReplTest[]::new)); - + test(after -> assertCommand(after, "/classpath", "| /classpath requires a path argument\n")); } public void testNoArgument() { - String[] commands = {"/s", "/save", "/o", "/open", "/setstart", "/savestart"}; + String[] commands = {"/save", "/open", "/setstart"}; test(Stream.of(commands) .map(cmd -> { String c = cmd; - if ("/s".equals(cmd)) { - c = "/save"; - } - if ("/o".equals(cmd)) { - c = "/open"; - } final String finalC = c; return (ReplTest) after -> assertCommand(after, cmd, "| The " + finalC + " command requires a filename argument.\n"); @@ -646,7 +597,7 @@ public void testStartSave() throws IOException { Compiler compiler = new Compiler(); Path startSave = compiler.getPath("startSave.txt"); - test(a -> assertCommand(a, "/savestart " + startSave.toString(), null)); + test(a -> assertCommand(a, "/save start " + startSave.toString(), null)); List lines = Files.lines(startSave) .filter(s -> !s.isEmpty()) .collect(Collectors.toList()); @@ -673,49 +624,42 @@ public void testRemoteExit() { test( a -> assertVariable(a, "int", "x"), - a -> assertCommandCheckOutput(a, "/v", assertVariables()), + a -> assertCommandCheckOutput(a, "/vars", assertVariables()), a -> assertCommandCheckOutput(a, "System.exit(5);", s -> assertTrue(s.contains("terminated"), s)), - a -> assertCommandCheckOutput(a, "/v", s -> + a -> assertCommandCheckOutput(a, "/vars", s -> assertTrue(s.trim().isEmpty(), s)), a -> assertMethod(a, "void f() { }", "()void", "f"), - a -> assertCommandCheckOutput(a, "/m", assertMethods()) + a -> assertCommandCheckOutput(a, "/methods", assertMethods()) ); } public void testListArgs() { - Consumer assertList = s -> assertTrue(s.split("\n").length >= 7, s); + Consumer assertList = s -> assertTrue(s.split("\n").length >= 4, s); String arg = "qqqq"; Consumer assertError = s -> assertEquals(s, "| Invalid /list argument: " + arg + "\n"); test( - a -> assertCommandCheckOutput(a, "/l all", assertList), a -> assertCommandCheckOutput(a, "/list all", assertList), - a -> assertCommandCheckOutput(a, "/l " + arg, assertError), a -> assertCommandCheckOutput(a, "/list " + arg, assertError), a -> assertVariable(a, "int", "a"), - a -> assertCommandCheckOutput(a, "/l history", assertList), a -> assertCommandCheckOutput(a, "/list history", assertList) ); } public void testFeedbackNegative() { - for (String feedback : new String[]{"/f", "/feedback"}) { - test(a -> assertCommandCheckOutput(a, feedback + " aaaa", - assertStartsWith("| Follow /feedback with of the following"))); - } + test(a -> assertCommandCheckOutput(a, "/feedback aaaa", + assertStartsWith("| Follow /feedback with of the following"))); } public void testFeedbackOff() { - for (String feedback : new String[]{"/f", "/feedback"}) { - for (String off : new String[]{"o", "off"}) { - test( - a -> assertCommand(a, feedback + " " + off, ""), - a -> assertCommand(a, "int a", ""), - a -> assertCommand(a, "void f() {}", ""), - a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("| Error:")), - a -> assertCommandCheckOutput(a, "public void f() {}", assertStartsWith("| Warning:")) - ); - } + for (String off : new String[]{"o", "off"}) { + test( + a -> assertCommand(a, "/feedback " + off, ""), + a -> assertCommand(a, "int a", ""), + a -> assertCommand(a, "void f() {}", ""), + a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("| Error:")), + a -> assertCommandCheckOutput(a, "public void f() {}", assertStartsWith("| Warning:")) + ); } } @@ -724,17 +668,15 @@ Path testConciseFile = compiler.getPath("testConciseFeedback"); String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"}; compiler.writeToFile(testConciseFile, sources); - for (String feedback : new String[]{"/f", "/feedback"}) { - for (String concise : new String[]{"c", "concise"}) { - test( - a -> assertCommand(a, feedback + " " + concise, ""), - a -> assertCommand(a, sources[0], ""), - a -> assertCommand(a, sources[1], ""), - a -> assertCommand(a, sources[2], ""), - a -> assertCommand(a, sources[3], "| a : 10\n"), - a -> assertCommand(a, "/o " + testConciseFile.toString(), "| a : 10\n") - ); - } + for (String concise : new String[]{"c", "concise"}) { + test( + a -> assertCommand(a, "/feedback " + concise, ""), + a -> assertCommand(a, sources[0], ""), + a -> assertCommand(a, sources[1], ""), + a -> assertCommand(a, sources[2], ""), + a -> assertCommand(a, sources[3], "| a : 10\n"), + a -> assertCommand(a, "/o " + testConciseFile.toString(), "| a : 10\n") + ); } } @@ -788,65 +730,59 @@ "| Variable a has been assigned the value 10\n" }; compiler.writeToFile(testDefaultFile, sources); - for (String feedback : new String[]{"/f", "/feedback"}) { - for (String defaultFeedback : new String[]{"", "d", "default"}) { - test( - a -> assertCommand(a, "/f o", ""), - a -> assertCommand(a, "int x", ""), - a -> assertCommand(a, feedback + " " + defaultFeedback, "| Feedback mode: default\n"), - a -> assertCommand(a, sources[0], output[0]), - a -> assertCommand(a, sources[1], output[1]), - a -> assertCommand(a, sources[2], output[2]), - a -> assertCommand(a, sources[3], output[3]), - a -> assertCommand(a, "/o " + testDefaultFile.toString(), "") - ); - } + for (String defaultFeedback : new String[]{"", "d", "default"}) { + test( + a -> assertCommand(a, "/feedback o", ""), + a -> assertCommand(a, "int x", ""), + a -> assertCommand(a, "/feedback " + defaultFeedback, "| Feedback mode: default\n"), + a -> assertCommand(a, sources[0], output[0]), + a -> assertCommand(a, sources[1], output[1]), + a -> assertCommand(a, sources[2], output[2]), + a -> assertCommand(a, sources[3], output[3]), + a -> assertCommand(a, "/o " + testDefaultFile.toString(), "") + ); } } public void testDrop() { - for (String drop : new String[]{"/d", "/drop"}) { - test(false, new String[]{"-nostartup"}, - a -> assertVariable(a, "int", "a"), - a -> dropVariable(a, drop + " 1", "int a = 0"), - a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), - a -> dropMethod(a, drop + " 2", "b ()I"), - a -> assertClass(a, "class A {}", "class", "A"), - a -> dropClass(a, drop + " 3", "class A"), - a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), - a -> dropImport(a, drop + " 4", "import java.util.stream.*"), - a -> assertCommandCheckOutput(a, "/v", assertVariables()), - a -> assertCommandCheckOutput(a, "/m", assertMethods()), - a -> assertCommandCheckOutput(a, "/c", assertClasses()), - a -> assertCommandCheckOutput(a, "/i", assertImports()) - ); - test(false, new String[]{"-nostartup"}, - a -> assertVariable(a, "int", "a"), - a -> dropVariable(a, drop + " a", "int a = 0"), - a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), - a -> dropMethod(a, drop + " b", "b ()I"), - a -> assertClass(a, "class A {}", "class", "A"), - a -> dropClass(a, drop + " A", "class A"), - a -> assertCommandCheckOutput(a, "/v", assertVariables()), - a -> assertCommandCheckOutput(a, "/m", assertMethods()), - a -> assertCommandCheckOutput(a, "/c", assertClasses()), - a -> assertCommandCheckOutput(a, "/i", assertImports()) - ); - } + test(false, new String[]{"-nostartup"}, + a -> assertVariable(a, "int", "a"), + a -> dropVariable(a, "/drop 1", "int a = 0"), + a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), + a -> dropMethod(a, "/drop 2", "b ()I"), + a -> assertClass(a, "class A {}", "class", "A"), + a -> dropClass(a, "/drop 3", "class A"), + a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), + a -> dropImport(a, "/drop 4", "import java.util.stream.*"), + a -> assertCommandCheckOutput(a, "/vars", assertVariables()), + a -> assertCommandCheckOutput(a, "/methods", assertMethods()), + a -> assertCommandCheckOutput(a, "/classes", assertClasses()), + a -> assertCommandCheckOutput(a, "/imports", assertImports()) + ); + test(false, new String[]{"-nostartup"}, + a -> assertVariable(a, "int", "a"), + a -> dropVariable(a, "/drop a", "int a = 0"), + a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), + a -> dropMethod(a, "/drop b", "b ()I"), + a -> assertClass(a, "class A {}", "class", "A"), + a -> dropClass(a, "/drop A", "class A"), + a -> assertCommandCheckOutput(a, "/vars", assertVariables()), + a -> assertCommandCheckOutput(a, "/methods", assertMethods()), + a -> assertCommandCheckOutput(a, "/classes", assertClasses()), + a -> assertCommandCheckOutput(a, "/imports", assertImports()) + ); } public void testDropNegative() { - for (String drop : new String[]{"/d", "/drop"}) { - test(false, new String[]{"-nostartup"}, - a -> assertCommand(a, drop + " 0", "| No definition or id named 0 found. See /classes /methods /vars or /list\n"), - a -> assertCommand(a, drop + " a", "| No definition or id named a found. See /classes /methods /vars or /list\n"), - a -> assertCommandCheckOutput(a, drop, - assertStartsWith("| In the /drop argument, please specify an import, variable, method, or class to drop.")), - a -> assertVariable(a, "int", "a"), - a -> assertCommand(a, "a", "| Variable a of type int has value 0\n"), - a -> assertCommand(a, drop + " 2", "| The argument did not specify an import, variable, method, or class to drop.\n") - ); - } + test(false, new String[]{"-nostartup"}, + a -> assertCommand(a, "/drop 0", "| No definition or id named 0 found. See /classes /methods /vars or /list\n"), + a -> assertCommand(a, "/drop a", "| No definition or id named a found. See /classes /methods /vars or /list\n"), + a -> assertCommandCheckOutput(a, "/drop", + assertStartsWith("| In the /drop argument, please specify an import, variable, method, or class to drop.")), + a -> assertVariable(a, "int", "a"), + a -> assertCommand(a, "a", "| Variable a of type int has value 0\n"), + a -> assertCommand(a, "/drop 2", "| The argument did not specify an import, variable, method, or class to drop.\n") + ); } public void testAmbiguousDrop() { @@ -855,25 +791,23 @@ int lines = s.split("\n").length; assertEquals(lines, 5, "Expected 3 ambiguous keys, but found: " + (lines - 2) + "\n" + s); }; - for (String drop : new String[]{"/d", "/drop"}) { - test( - a -> assertVariable(a, "int", "a"), - a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), - a -> assertClass(a, "class a {}", "class", "a"), - a -> assertCommandCheckOutput(a, drop + " a", check), - a -> assertCommandCheckOutput(a, "/v", assertVariables()), - a -> assertCommandCheckOutput(a, "/m", assertMethods()), - a -> assertCommandCheckOutput(a, "/c", assertClasses()), - a -> assertCommandCheckOutput(a, "/i", assertImports()) - ); - test( - a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), - a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"), - a -> assertMethod(a, "double a(double a) { return 0; }", "(double)double", "a"), - a -> assertCommandCheckOutput(a, drop + " a", check), - a -> assertCommandCheckOutput(a, "/m", assertMethods()) - ); - } + test( + a -> assertVariable(a, "int", "a"), + a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), + a -> assertClass(a, "class a {}", "class", "a"), + a -> assertCommandCheckOutput(a, "/drop a", check), + a -> assertCommandCheckOutput(a, "/vars", assertVariables()), + a -> assertCommandCheckOutput(a, "/methods", assertMethods()), + a -> assertCommandCheckOutput(a, "/classes", assertClasses()), + a -> assertCommandCheckOutput(a, "/imports", assertImports()) + ); + test( + a -> assertMethod(a, "int a() { return 0; }", "()int", "a"), + a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"), + a -> assertMethod(a, "double a(double a) { return 0; }", "(double)double", "a"), + a -> assertCommandCheckOutput(a, "/drop a", check), + a -> assertCommandCheckOutput(a, "/methods", assertMethods()) + ); } public void testHistoryReference() { @@ -893,4 +827,14 @@ a -> assertCommand(a, "/1", "System.err.println(1)\n", "", null, "", "1\n") ); } + + public void testCommandPrefix() { + test(a -> assertCommandCheckOutput(a, "/s", + assertStartsWith("| Command: /s is ambiguous: /seteditor, /save, /setstart")), + a -> assertCommand(a, "int var", "| Added variable var of type int\n"), + a -> assertCommandCheckOutput(a, "/va", + assertStartsWith("| int var = 0")), + a -> assertCommandCheckOutput(a, "/save", + assertStartsWith("| The /save command requires a filename argument."))); + } }