2016-04-09 18:03:48 +00:00
|
|
|
/*
|
2018-01-19 16:11:52 +00:00
|
|
|
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
2016-04-09 18:03:48 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
2018-10-22 16:26:50 +00:00
|
|
|
* @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103 8165405 8173073 8173848 8174041 8173916 8174028 8174262 8174797 8177079 8180508 8177466 8172154 8192979 8191842 8198573 8198801 8210596 8210959
|
2016-04-09 18:03:48 +00:00
|
|
|
* @summary Simple jshell tool tests
|
|
|
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
|
|
|
* jdk.compiler/com.sun.tools.javac.main
|
|
|
|
* jdk.jdeps/com.sun.tools.javap
|
|
|
|
* jdk.jshell/jdk.internal.jshell.tool
|
|
|
|
* @build KullaTesting TestingInputStream
|
2018-12-11 10:29:28 +00:00
|
|
|
* @run testng/othervm ToolSimpleTest
|
2016-04-09 18:03:48 +00:00
|
|
|
*/
|
2018-10-22 16:26:50 +00:00
|
|
|
|
2016-04-09 18:03:48 +00:00
|
|
|
import java.util.ArrayList;
|
2018-10-22 16:26:50 +00:00
|
|
|
import java.util.Arrays;
|
2016-04-09 18:03:48 +00:00
|
|
|
import java.util.List;
|
2016-11-03 16:12:02 +00:00
|
|
|
import java.util.Locale;
|
2016-04-09 18:03:48 +00:00
|
|
|
import java.util.function.Consumer;
|
2017-05-18 21:16:25 +00:00
|
|
|
import java.util.regex.Pattern;
|
2016-04-09 18:03:48 +00:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
|
|
|
|
import static org.testng.Assert.assertEquals;
|
|
|
|
import static org.testng.Assert.assertTrue;
|
|
|
|
|
|
|
|
public class ToolSimpleTest extends ReplToolTesting {
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void testRemaining() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "int z; z =", "z ==> 0"),
|
|
|
|
(a) -> assertCommand(a, "5", "z ==> 5"),
|
|
|
|
(a) -> assertCommand(a, "/*nada*/; int q =", ""),
|
|
|
|
(a) -> assertCommand(a, "77", "q ==> 77"),
|
|
|
|
(a) -> assertCommand(a, "//comment;", ""),
|
|
|
|
(a) -> assertCommand(a, "int v;", "v ==> 0"),
|
|
|
|
(a) -> assertCommand(a, "int v; int c",
|
|
|
|
"v ==> 0\n" +
|
|
|
|
"c ==> 0")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-06-02 19:52:00 +00:00
|
|
|
public void testOpenComment() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "int z = /* blah", ""),
|
|
|
|
(a) -> assertCommand(a, "baz */ 5", "z ==> 5"),
|
|
|
|
(a) -> assertCommand(a, "/** hoge ", ""),
|
|
|
|
(a) -> assertCommand(a, "baz **/", ""),
|
|
|
|
(a) -> assertCommand(a, "int v", "v ==> 0")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-17 15:37:47 +00:00
|
|
|
@Test
|
|
|
|
public void testRawString() {
|
2018-10-22 15:30:39 +00:00
|
|
|
test(false, new String[]{"--enable-preview", "--no-startup"},
|
|
|
|
(a) -> assertCommand(a, "String s = `abc`", "s ==> \"abc\""),
|
|
|
|
(a) -> assertCommand(a, "String a = `abc", ""),
|
|
|
|
(a) -> assertCommand(a, "def`", "a ==> \"abc\\ndef\""),
|
|
|
|
(a) -> assertCommand(a, "String bj = ``Hi, `Bob` and ```Jim```.``", "bj ==> \"Hi, `Bob` and ```Jim```.\""),
|
|
|
|
(a) -> assertCommand(a, "String hw = ````````````", ""),
|
|
|
|
(a) -> assertCommand(a, "Hello, world", ""),
|
|
|
|
(a) -> assertCommand(a, "````````````;", "hw ==> \"\\nHello, world\\n\""),
|
|
|
|
(a) -> assertCommand(a, "String uc = `\\u000d\\u000a`", "uc ==> \"\\\\u000d\\\\u000a\""),
|
|
|
|
(a) -> assertCommand(a, "String es = `\\(.\\)\\1`", "es ==> \"\\\\(.\\\\)\\\\1\""),
|
|
|
|
(a) -> assertCommand(a, "String end = `abc`+`def`+`ghi`", "end ==> \"abcdefghi\"")
|
2018-09-17 15:37:47 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-22 15:30:39 +00:00
|
|
|
@Test
|
|
|
|
public void testSwitchExpression() {
|
|
|
|
test(false, new String[]{"--enable-preview", "--no-startup"},
|
|
|
|
(a) -> assertCommand(a, "enum Day {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }", "| created enum Day"),
|
|
|
|
(a) -> assertCommand(a, "Day day = Day.FRIDAY;", "day ==> FRIDAY"),
|
|
|
|
(a) -> assertCommand(a, "switch (day) {", ""),
|
|
|
|
(a) -> assertCommand(a, "case MONDAY, FRIDAY, SUNDAY -> 6;", ""),
|
|
|
|
(a) -> assertCommand(a, "case TUESDAY -> 7;", ""),
|
|
|
|
(a) -> assertCommand(a, "case THURSDAY, SATURDAY -> 8;", ""),
|
|
|
|
(a) -> assertCommand(a, "case WEDNESDAY -> 9;", ""),
|
|
|
|
(a) -> assertCommandOutputContains(a, "}", " ==> 6")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSwitchExpressionCompletion() {
|
|
|
|
test(false, new String[]{"--enable-preview", "--no-startup"},
|
|
|
|
(a) -> assertCommand(a, "enum Day {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }", "| created enum Day"),
|
|
|
|
(a) -> assertCommand(a, "Day day = Day.FRIDAY;", "day ==> FRIDAY"),
|
|
|
|
(a) -> assertCommand(a, "switch (day) {", ""),
|
|
|
|
(a) -> assertCommand(a, "case MONDAY, FRIDAY, SUNDAY -> 6;", ""),
|
|
|
|
(a) -> assertCommand(a, "case TUESDAY -> 7;", ""),
|
|
|
|
(a) -> assertCommand(a, "case THURSDAY, SATURDAY -> 8;", ""),
|
|
|
|
(a) -> assertCommand(a, "case WEDNESDAY -> 9;", ""),
|
|
|
|
(a) -> assertCommand(a, "} +", ""),
|
|
|
|
(a) -> assertCommandOutputContains(a, "1000", " ==> 1006")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-06 17:00:02 +00:00
|
|
|
@Test
|
|
|
|
public void testLessThan() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "45", "$1 ==> 45"),
|
|
|
|
(a) -> assertCommand(a, "72", "$2 ==> 72"),
|
|
|
|
(a) -> assertCommand(a, "$1 < $2", "$3 ==> true"),
|
|
|
|
(a) -> assertCommand(a, "int a, b", "a ==> 0\n" +
|
|
|
|
"b ==> 0"),
|
|
|
|
(a) -> assertCommand(a, "a < b", "$6 ==> false")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-03 20:27:58 +00:00
|
|
|
@Test
|
|
|
|
public void testChainedThrow() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "void p() throws Exception { ((String) null).toString(); }",
|
|
|
|
"| created method p()"),
|
|
|
|
(a) -> assertCommand(a, "void n() throws Exception { try { p(); } catch (Exception ex) { throw new IOException(\"bar\", ex); }}",
|
|
|
|
"| created method n()"),
|
|
|
|
(a) -> assertCommand(a, "void m() { try { n(); } catch (Exception ex) { throw new RuntimeException(\"foo\", ex); }}",
|
|
|
|
"| created method m()"),
|
|
|
|
(a) -> assertCommand(a, "m()",
|
|
|
|
"| Exception java.lang.RuntimeException: foo\n"
|
|
|
|
+ "| at m (#3:1)\n"
|
|
|
|
+ "| at (#4:1)\n"
|
|
|
|
+ "| Caused by: java.io.IOException: bar\n"
|
|
|
|
+ "| at n (#2:1)\n"
|
|
|
|
+ "| ...\n"
|
|
|
|
+ "| Caused by: java.lang.NullPointerException\n"
|
|
|
|
+ "| at p (#1:1)\n"
|
|
|
|
+ "| ..."),
|
|
|
|
(a) -> assertCommand(a, "/drop p",
|
|
|
|
"| dropped method p()"),
|
|
|
|
(a) -> assertCommand(a, "m()",
|
|
|
|
"| attempted to call method n() which cannot be invoked until method p() is declared")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-22 16:26:50 +00:00
|
|
|
@Test
|
|
|
|
public void testThrowWithPercent() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandCheckOutput(a,
|
|
|
|
"URI u = new URI(\"http\", null, \"h\", -1, \"a\" + (char)0x04, null, null);", (s) ->
|
|
|
|
assertTrue(s.contains("URISyntaxException") && !s.contains("JShellTool"),
|
|
|
|
"Output: '" + s + "'")),
|
|
|
|
(a) -> assertCommandCheckOutput(a,
|
|
|
|
"throw new Exception(\"%z\")", (s) ->
|
|
|
|
assertTrue(s.contains("java.lang.Exception") && !s.contains("UnknownFormatConversionException"),
|
|
|
|
"Output: '" + s + "'"))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void oneLineOfError() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "12+", null),
|
|
|
|
(a) -> assertCommandCheckOutput(a, " true", (s) ->
|
|
|
|
assertTrue(s.contains("12+") && !s.contains("true"), "Output: '" + s + "'"))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void defineVariables() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
|
|
|
|
(a) -> assertVariable(a, "int", "a"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
|
|
|
|
(a) -> assertVariable(a, "double", "a", "1", "1.0"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
|
|
|
|
(a) -> evaluateExpression(a, "double", "2 * a", "2.0"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void defineMethods() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
|
|
|
|
(a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
|
|
|
|
(a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
|
|
|
|
(a) -> assertMethod(a, "void g() {}", "()void", "g"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-05-17 04:46:32 +00:00
|
|
|
public void defineTypes() {
|
2016-04-13 05:23:11 +00:00
|
|
|
test(
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
2016-05-17 04:46:32 +00:00
|
|
|
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
|
2016-04-13 05:23:11 +00:00
|
|
|
(a) -> assertClass(a, "class A { }", "class", "A"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
2016-05-17 04:46:32 +00:00
|
|
|
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
|
2016-04-13 05:23:11 +00:00
|
|
|
(a) -> assertClass(a, "interface A { }", "interface", "A"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
2016-05-17 04:46:32 +00:00
|
|
|
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
|
2016-04-13 05:23:11 +00:00
|
|
|
(a) -> assertClass(a, "enum A { }", "enum", "A"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
2016-05-17 04:46:32 +00:00
|
|
|
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
|
2016-04-13 05:23:11 +00:00
|
|
|
(a) -> assertClass(a, "@interface A { }", "@interface", "A"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
2016-05-17 04:46:32 +00:00
|
|
|
(a) -> assertCommandCheckOutput(a, "/types", assertClasses())
|
2016-04-13 05:23:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void defineImports() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
|
|
|
|
(a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
|
|
|
|
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
|
|
|
|
(a) -> assertImport(a, "import static java.lang.Math.PI;", "static", "java.lang.Math.PI"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
|
|
|
|
(a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/imports", assertImports())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-09 18:03:48 +00:00
|
|
|
public void defineVar() {
|
|
|
|
test(
|
2016-04-13 05:23:11 +00:00
|
|
|
(a) -> assertCommand(a, "int x = 72", "x ==> 72"),
|
|
|
|
(a) -> assertCommand(a, "x", "x ==> 72"),
|
2016-04-09 18:03:48 +00:00
|
|
|
(a) -> assertCommand(a, "/vars", "| int x = 72")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-09 18:03:48 +00:00
|
|
|
public void defineUnresolvedVar() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "undefined x",
|
2016-04-13 05:23:11 +00:00
|
|
|
"| created variable x, however, it cannot be referenced until class undefined is declared"),
|
2016-04-09 18:03:48 +00:00
|
|
|
(a) -> assertCommand(a, "/vars", "| undefined x = (not-active)")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-09 18:03:48 +00:00
|
|
|
public void testUnresolved() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "int f() { return g() + x + new A().a; }",
|
2016-04-13 05:23:11 +00:00
|
|
|
"| created method f(), however, it cannot be invoked until method g(), variable x, and class A are declared"),
|
2016-04-09 18:03:48 +00:00
|
|
|
(a) -> assertCommand(a, "f()",
|
2016-04-13 05:23:11 +00:00
|
|
|
"| attempted to call method f() which cannot be invoked until method g(), variable x, and class A are declared"),
|
2016-04-09 18:03:48 +00:00
|
|
|
(a) -> assertCommandOutputStartsWith(a, "int g() { return x; }",
|
2016-04-13 05:23:11 +00:00
|
|
|
"| created method g(), however, it cannot be invoked until variable x is declared"),
|
|
|
|
(a) -> assertCommand(a, "g()", "| attempted to call method g() which cannot be invoked until variable x is declared")
|
2016-04-09 18:03:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void testUnknownCommand() {
|
|
|
|
test((a) -> assertCommand(a, "/unknown",
|
2017-05-18 21:16:25 +00:00
|
|
|
"| Invalid command: /unknown\n" +
|
2016-04-13 05:23:11 +00:00
|
|
|
"| Type /help for help."));
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void testEmptyClassPath() {
|
2017-01-06 18:31:25 +00:00
|
|
|
test(after -> assertCommand(after, "/env --class-path", "| Argument to class-path missing."));
|
2016-04-13 05:23:11 +00:00
|
|
|
}
|
|
|
|
|
2017-02-13 16:50:26 +00:00
|
|
|
@Test
|
|
|
|
public void testInvalidClassPath() {
|
|
|
|
test(
|
2017-02-14 01:04:26 +00:00
|
|
|
a -> assertCommand(a, "/env --class-path snurgefusal",
|
2017-12-13 10:27:28 +00:00
|
|
|
"| File 'snurgefusal' for '--class-path' is not found."),
|
|
|
|
a -> assertCommand(a, "/env --class-path ?",
|
|
|
|
"| File '?' for '--class-path' is not found.")
|
2017-02-13 16:50:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void testNoArgument() {
|
2016-05-23 17:12:05 +00:00
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "/save",
|
|
|
|
"| '/save' requires a filename argument."),
|
|
|
|
(a) -> assertCommand(a, "/open",
|
|
|
|
"| '/open' requires a filename argument."),
|
2016-10-20 19:53:11 +00:00
|
|
|
(a) -> assertCommandOutputStartsWith(a, "/drop",
|
|
|
|
"| In the /drop argument, please specify an import, variable, method, or class to drop.")
|
2016-05-23 17:12:05 +00:00
|
|
|
);
|
2016-04-13 05:23:11 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-09 18:03:48 +00:00
|
|
|
public void testDebug() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "/deb", "| Debugging on"),
|
|
|
|
(a) -> assertCommand(a, "/debug", "| Debugging off"),
|
|
|
|
(a) -> assertCommand(a, "/debug", "| Debugging on"),
|
|
|
|
(a) -> assertCommand(a, "/deb", "| Debugging off")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void testDrop() {
|
2016-08-23 02:31:37 +00:00
|
|
|
test(false, new String[]{"--no-startup"},
|
2016-04-13 05:23:11 +00:00
|
|
|
a -> assertVariable(a, "int", "a"),
|
|
|
|
a -> dropVariable(a, "/drop 1", "int a = 0", "| dropped variable a"),
|
2017-02-08 21:35:42 +00:00
|
|
|
a -> assertMethod(a, "int b() { return 0; }", "()int", "b"),
|
|
|
|
a -> dropMethod(a, "/drop 2", "int b()", "| dropped method b()"),
|
2016-04-13 05:23:11 +00:00
|
|
|
a -> assertClass(a, "class A {}", "class", "A"),
|
|
|
|
a -> dropClass(a, "/drop 3", "class A", "| dropped class A"),
|
|
|
|
a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
|
|
|
|
a -> dropImport(a, "/drop 4", "import java.util.stream.*", ""),
|
2016-10-11 01:41:12 +00:00
|
|
|
a -> assertCommand(a, "for (int i = 0; i < 10; ++i) {}", ""),
|
|
|
|
a -> assertCommand(a, "/drop 5", ""),
|
|
|
|
a -> assertCommand(a, "/list", ""),
|
2016-04-13 05:23:11 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
|
|
|
|
a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/types", assertClasses()),
|
2016-04-13 05:23:11 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/imports", assertImports())
|
|
|
|
);
|
2016-08-23 02:31:37 +00:00
|
|
|
test(false, new String[]{"--no-startup"},
|
2016-04-13 05:23:11 +00:00
|
|
|
a -> assertVariable(a, "int", "a"),
|
|
|
|
a -> dropVariable(a, "/drop a", "int a = 0", "| dropped variable a"),
|
2017-02-08 21:35:42 +00:00
|
|
|
a -> assertMethod(a, "int b() { return 0; }", "()int", "b"),
|
|
|
|
a -> dropMethod(a, "/drop b", "int b()", "| dropped method b()"),
|
2016-04-13 05:23:11 +00:00
|
|
|
a -> assertClass(a, "class A {}", "class", "A"),
|
|
|
|
a -> dropClass(a, "/drop A", "class A", "| dropped class A"),
|
|
|
|
a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
|
|
|
|
a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/types", assertClasses()),
|
2016-04-13 05:23:11 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/imports", assertImports())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-05-18 21:16:25 +00:00
|
|
|
@Test
|
|
|
|
public void testDropRange() {
|
|
|
|
test(false, new String[]{"--no-startup"},
|
|
|
|
a -> assertVariable(a, "int", "a"),
|
|
|
|
a -> assertMethod(a, "int b() { return 0; }", "()int", "b"),
|
|
|
|
a -> assertClass(a, "class A {}", "class", "A"),
|
|
|
|
a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
|
|
|
|
a -> assertCommand(a, "for (int i = 0; i < 10; ++i) {}", ""),
|
|
|
|
a -> assertCommand(a, "/drop 3-5 b 1",
|
|
|
|
"| dropped class A\n" +
|
|
|
|
"| dropped method b()\n" +
|
|
|
|
"| dropped variable a\n"),
|
|
|
|
a -> assertCommand(a, "/list", "")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void testDropNegative() {
|
2016-08-23 02:31:37 +00:00
|
|
|
test(false, new String[]{"--no-startup"},
|
2018-01-04 20:24:56 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/drop 0", "| No snippet with ID: 0"),
|
2016-05-23 17:12:05 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/drop a", "| No such snippet: a"),
|
2016-04-13 05:23:11 +00:00
|
|
|
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", "a ==> 0"),
|
2016-10-11 01:41:12 +00:00
|
|
|
a -> assertCommand(a, "/drop 2", ""),
|
2016-05-23 17:12:05 +00:00
|
|
|
a -> assertCommand(a, "/drop 2",
|
|
|
|
"| This command does not accept the snippet '2' : a\n" +
|
|
|
|
"| See /types, /methods, /vars, or /list")
|
2016-04-13 05:23:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void testAmbiguousDrop() {
|
|
|
|
test(
|
|
|
|
a -> assertVariable(a, "int", "a"),
|
|
|
|
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
|
|
|
|
a -> assertClass(a, "class a {}", "class", "a"),
|
2017-05-18 21:16:25 +00:00
|
|
|
a -> assertCommand(a, "/drop a",
|
|
|
|
"| dropped variable a\n" +
|
|
|
|
"| dropped method a()\n" +
|
|
|
|
"| dropped class a")
|
2016-04-13 05:23:11 +00:00
|
|
|
);
|
|
|
|
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"),
|
2017-05-18 21:16:25 +00:00
|
|
|
a -> assertCommand(a, "/drop a",
|
|
|
|
"| dropped method a()\n" +
|
|
|
|
"| dropped method a(int)\n" +
|
|
|
|
"| dropped method a(double)\n")
|
2016-04-13 05:23:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-12-02 18:17:03 +00:00
|
|
|
public void testApplicationOfPost() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "/set mode t normal -command", "| Created new feedback mode: t"),
|
|
|
|
(a) -> assertCommand(a, "/set feedback t", "| Feedback mode: t"),
|
|
|
|
(a) -> assertCommand(a, "/set format t post \"$%n\"", ""),
|
|
|
|
(a) -> assertCommand(a, "/set prompt t \"+\" \"-\"", ""),
|
|
|
|
(a) -> assertCommand(a, "/set prompt t", "| /set prompt t \"+\" \"-\"$")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-09 18:03:48 +00:00
|
|
|
public void testHelpLength() {
|
|
|
|
Consumer<String> testOutput = (s) -> {
|
|
|
|
List<String> ss = Stream.of(s.split("\n"))
|
|
|
|
.filter(l -> !l.isEmpty())
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
assertTrue(ss.size() >= 10, "Help does not print enough lines:" + s);
|
|
|
|
};
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/?", testOutput),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/help", testOutput),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/help /list", testOutput)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-09 18:03:48 +00:00
|
|
|
public void testHelp() {
|
|
|
|
test(
|
|
|
|
(a) -> assertHelp(a, "/?", "/list", "/help", "/exit", "intro"),
|
|
|
|
(a) -> assertHelp(a, "/help", "/list", "/help", "/exit", "intro"),
|
|
|
|
(a) -> assertHelp(a, "/help short", "shortcuts", "<tab>"),
|
2016-05-18 18:35:10 +00:00
|
|
|
(a) -> assertHelp(a, "/? /li", "/list -all", "snippets"),
|
2016-12-02 18:17:03 +00:00
|
|
|
(a) -> assertHelp(a, "/help /set prompt", "optionally contain '%s'", "quoted"),
|
2017-03-29 23:07:30 +00:00
|
|
|
(a) -> assertHelp(a, "/help /help", "/help <command>"),
|
|
|
|
(a) -> assertHelp(a, "/help li", "/list -start"),
|
|
|
|
(a) -> assertHelp(a, "/help fe", "/set feedback -retain")
|
2016-04-09 18:03:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-12-05 19:04:42 +00:00
|
|
|
@Test
|
|
|
|
public void testHelpStart() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/help /exit",
|
|
|
|
s -> assertTrue(s.replaceAll("\\r\\n?", "\n").startsWith(
|
|
|
|
"| \n" +
|
|
|
|
"| /exit\n" +
|
|
|
|
"| =====\n" +
|
|
|
|
"| "
|
|
|
|
))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-12-02 18:17:03 +00:00
|
|
|
public void testHelpFormat() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/help", s -> {
|
|
|
|
String[] lines = s.split("\\R");
|
|
|
|
assertTrue(lines.length > 20,
|
|
|
|
"Too few lines of /help output: " + lines.length
|
|
|
|
+ "\n" + s);
|
|
|
|
for (int i = 0; i < lines.length; ++i) {
|
|
|
|
String l = lines[i];
|
|
|
|
assertTrue(l.startsWith("| "),
|
|
|
|
"Expected /help line to start with | :\n" + l);
|
|
|
|
assertTrue(l.length() <= 80,
|
|
|
|
"/help line too long: " + l.length() + "\n" + l);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-06-16 17:32:46 +00:00
|
|
|
@Test
|
|
|
|
public void testConfusedUserPseudoCommands() {
|
|
|
|
test(
|
|
|
|
(a) -> assertHelp(a, "/-<n>", "last snippet", "digits"),
|
|
|
|
(a) -> assertHelp(a, "/<id>", "last snippet", "digits")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-09 18:03:48 +00:00
|
|
|
private void assertHelp(boolean a, String command, String... find) {
|
|
|
|
assertCommandCheckOutput(a, command, s -> {
|
|
|
|
for (String f : find) {
|
2016-12-02 18:17:03 +00:00
|
|
|
assertTrue(s.contains(f),
|
|
|
|
"Expected output of " + command + " to contain: " + f
|
|
|
|
+ "\n" + s);
|
2016-04-09 18:03:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that each line of output contains the corresponding string from the list
|
|
|
|
private void checkLineToList(String in, List<String> match) {
|
2016-05-17 04:46:32 +00:00
|
|
|
String trimmed = in.trim();
|
|
|
|
String[] res = trimmed.isEmpty()
|
|
|
|
? new String[0]
|
|
|
|
: trimmed.split("\n");
|
2016-04-09 18:03:48 +00:00
|
|
|
assertEquals(res.length, match.size(), "Got: " + Arrays.asList(res));
|
|
|
|
for (int i = 0; i < match.size(); ++i) {
|
|
|
|
assertTrue(res[i].contains(match.get(i)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-09 18:03:48 +00:00
|
|
|
public void testListArgs() {
|
|
|
|
String arg = "qqqq";
|
|
|
|
List<String> startVarList = new ArrayList<>(START_UP);
|
|
|
|
startVarList.add("int aardvark");
|
2017-05-18 21:16:25 +00:00
|
|
|
startVarList.add("int weevil");
|
2016-04-09 18:03:48 +00:00
|
|
|
test(
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/list -all",
|
2016-04-09 18:03:48 +00:00
|
|
|
s -> checkLineToList(s, START_UP)),
|
|
|
|
a -> assertCommandOutputStartsWith(a, "/list " + arg,
|
2016-05-23 17:12:05 +00:00
|
|
|
"| No such snippet: " + arg),
|
2016-04-09 18:03:48 +00:00
|
|
|
a -> assertVariable(a, "int", "aardvark"),
|
2017-05-18 21:16:25 +00:00
|
|
|
a -> assertVariable(a, "int", "weevil"),
|
2016-04-09 18:03:48 +00:00
|
|
|
a -> assertCommandOutputContains(a, "/list aardvark", "aardvark"),
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/list -start",
|
2016-04-09 18:03:48 +00:00
|
|
|
s -> checkLineToList(s, START_UP)),
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/list -all",
|
2016-04-09 18:03:48 +00:00
|
|
|
s -> checkLineToList(s, startVarList)),
|
2017-01-03 02:31:30 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/list s3",
|
|
|
|
"s3 : import"),
|
2017-05-18 21:16:25 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/list 1-2 s3",
|
|
|
|
s -> {
|
|
|
|
assertTrue(Pattern.matches(".*aardvark.*\\R.*weevil.*\\R.*s3.*import.*", s.trim()),
|
|
|
|
"No match: " + s);
|
|
|
|
}),
|
2016-04-09 18:03:48 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/list " + arg,
|
2016-05-23 17:12:05 +00:00
|
|
|
"| No such snippet: " + arg)
|
2016-05-17 04:46:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-05-17 04:46:32 +00:00
|
|
|
public void testVarsArgs() {
|
|
|
|
String arg = "qqqq";
|
|
|
|
List<String> startVarList = new ArrayList<>();
|
|
|
|
test(
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/vars -all",
|
2016-05-17 04:46:32 +00:00
|
|
|
s -> checkLineToList(s, startVarList)),
|
2016-05-23 17:12:05 +00:00
|
|
|
a -> assertCommand(a, "/vars " + arg,
|
|
|
|
"| No such snippet: " + arg),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertVariable(a, "int", "aardvark"),
|
|
|
|
a -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
|
|
|
|
a -> assertVariable(a, "int", "a"),
|
|
|
|
a -> assertVariable(a, "double", "a", "1", "1.0"),
|
2016-05-23 17:12:05 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/vars aardvark",
|
|
|
|
"| int aardvark = 0"),
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/vars -start",
|
2016-05-17 04:46:32 +00:00
|
|
|
s -> checkLineToList(s, startVarList)),
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/vars -all",
|
2016-05-17 04:46:32 +00:00
|
|
|
"| int aardvark = 0\n| int a = "),
|
2017-05-18 21:16:25 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/vars 1-4",
|
|
|
|
"| int aardvark = 0\n| int a = "),
|
2017-01-03 02:31:30 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/vars f",
|
|
|
|
"| This command does not accept the snippet 'f'"),
|
2016-05-23 17:12:05 +00:00
|
|
|
a -> assertCommand(a, "/var " + arg,
|
|
|
|
"| No such snippet: " + arg)
|
2016-04-09 18:03:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-05-17 04:46:32 +00:00
|
|
|
public void testMethodsArgs() {
|
|
|
|
String arg = "qqqq";
|
2017-01-03 02:31:30 +00:00
|
|
|
List<String> printingMethodList = new ArrayList<>(PRINTING_CMD_METHOD);
|
|
|
|
test(new String[]{"--startup", "PRINTING"},
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/methods -all",
|
2017-01-03 02:31:30 +00:00
|
|
|
s -> checkLineToList(s, printingMethodList)),
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/methods -start",
|
2017-01-03 02:31:30 +00:00
|
|
|
s -> checkLineToList(s, printingMethodList)),
|
|
|
|
a -> assertCommandCheckOutput(a, "/methods print println printf",
|
|
|
|
s -> checkLineToList(s, printingMethodList)),
|
|
|
|
a -> assertCommandCheckOutput(a, "/methods println",
|
|
|
|
s -> assertEquals(s.trim().split("\n").length, 10)),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/methods",
|
2017-01-03 02:31:30 +00:00
|
|
|
s -> checkLineToList(s, printingMethodList)),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/methods " + arg,
|
2016-05-23 17:12:05 +00:00
|
|
|
"| No such snippet: " + arg),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
|
|
|
|
a -> assertVariable(a, "int", "aardvark"),
|
|
|
|
a -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"),
|
|
|
|
a -> assertMethod(a, "void g() {}", "()void", "g"),
|
|
|
|
a -> assertCommandOutputStartsWith(a, "/methods " + arg,
|
2016-05-23 17:12:05 +00:00
|
|
|
"| No such snippet: " + arg),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/methods aardvark",
|
2016-05-23 17:12:05 +00:00
|
|
|
"| This command does not accept the snippet 'aardvark' : int aardvark"),
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/methods -start",
|
2017-01-03 02:31:30 +00:00
|
|
|
s -> checkLineToList(s, printingMethodList)),
|
|
|
|
a -> assertCommandCheckOutput(a, "/methods print println printf",
|
|
|
|
s -> checkLineToList(s, printingMethodList)),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/methods g",
|
2017-02-08 21:35:42 +00:00
|
|
|
"| void g()"),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/methods f",
|
2017-02-08 21:35:42 +00:00
|
|
|
"| int f()\n" +
|
|
|
|
"| void f(int)")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testMethodsWithErrors() {
|
|
|
|
test(new String[]{"--no-startup"},
|
|
|
|
a -> assertCommand(a, "double m(int x) { return x; }",
|
|
|
|
"| created method m(int)"),
|
|
|
|
a -> assertCommand(a, "GARBAGE junk() { return TRASH; }",
|
|
|
|
"| created method junk(), however, it cannot be referenced until class GARBAGE, and variable TRASH are declared"),
|
|
|
|
a -> assertCommand(a, "int w = 5;",
|
|
|
|
"w ==> 5"),
|
|
|
|
a -> assertCommand(a, "int tyer() { return w; }",
|
|
|
|
"| created method tyer()"),
|
|
|
|
a -> assertCommand(a, "String w = \"hi\";",
|
|
|
|
"w ==> \"hi\""),
|
|
|
|
a -> assertCommand(a, "/methods",
|
|
|
|
"| double m(int)\n" +
|
|
|
|
"| GARBAGE junk()\n" +
|
|
|
|
"| which cannot be referenced until class GARBAGE, and variable TRASH are declared\n" +
|
|
|
|
"| int tyer()\n" +
|
|
|
|
"| which cannot be invoked until this error is corrected: \n" +
|
|
|
|
"| incompatible types: java.lang.String cannot be converted to int\n" +
|
|
|
|
"| int tyer() { return w; }\n" +
|
|
|
|
"| ^\n")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testTypesWithErrors() {
|
|
|
|
test(new String[]{"--no-startup"},
|
|
|
|
a -> assertCommand(a, "class C extends NONE { int x; }",
|
|
|
|
"| created class C, however, it cannot be referenced until class NONE is declared"),
|
|
|
|
a -> assertCommand(a, "class D { void m() { System.out.println(nada); } }",
|
2017-02-10 02:58:36 +00:00
|
|
|
"| created class D, however, it cannot be instantiated or its methods invoked until variable nada is declared"),
|
2017-02-08 21:35:42 +00:00
|
|
|
a -> assertCommand(a, "/types",
|
|
|
|
"| class C\n" +
|
|
|
|
"| which cannot be referenced until class NONE is declared\n" +
|
|
|
|
"| class D\n" +
|
2017-02-10 02:58:36 +00:00
|
|
|
"| which cannot be instantiated or its methods invoked until variable nada is declared\n")
|
2016-05-17 04:46:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-05-17 04:46:32 +00:00
|
|
|
public void testTypesArgs() {
|
|
|
|
String arg = "qqqq";
|
|
|
|
List<String> startTypeList = new ArrayList<>();
|
|
|
|
test(
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/types -all",
|
2016-05-17 04:46:32 +00:00
|
|
|
s -> checkLineToList(s, startTypeList)),
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/types -start",
|
2016-05-17 04:46:32 +00:00
|
|
|
s -> checkLineToList(s, startTypeList)),
|
|
|
|
a -> assertCommandOutputStartsWith(a, "/types " + arg,
|
2016-05-23 17:12:05 +00:00
|
|
|
"| No such snippet: " + arg),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertVariable(a, "int", "aardvark"),
|
|
|
|
(a) -> assertClass(a, "class A { }", "class", "A"),
|
|
|
|
(a) -> assertClass(a, "interface A { }", "interface", "A"),
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/types -all",
|
2016-05-17 04:46:32 +00:00
|
|
|
"| class A\n" +
|
|
|
|
"| interface A"),
|
|
|
|
(a) -> assertClass(a, "enum E { }", "enum", "E"),
|
|
|
|
(a) -> assertClass(a, "@interface B { }", "@interface", "B"),
|
2016-05-23 17:12:05 +00:00
|
|
|
a -> assertCommand(a, "/types aardvark",
|
|
|
|
"| This command does not accept the snippet 'aardvark' : int aardvark;"),
|
2016-05-17 04:46:32 +00:00
|
|
|
a -> assertCommandOutputStartsWith(a, "/types A",
|
|
|
|
"| interface A"),
|
|
|
|
a -> assertCommandOutputStartsWith(a, "/types E",
|
|
|
|
"| enum E"),
|
|
|
|
a -> assertCommandOutputStartsWith(a, "/types B",
|
|
|
|
"| @interface B"),
|
|
|
|
a -> assertCommandOutputStartsWith(a, "/types " + arg,
|
2016-05-23 17:12:05 +00:00
|
|
|
"| No such snippet: " + arg),
|
2016-05-18 18:35:10 +00:00
|
|
|
a -> assertCommandCheckOutput(a, "/types -start",
|
2016-05-17 04:46:32 +00:00
|
|
|
s -> checkLineToList(s, startTypeList))
|
|
|
|
);
|
|
|
|
}
|
2016-12-22 04:14:39 +00:00
|
|
|
|
2017-01-20 19:05:48 +00:00
|
|
|
@Test
|
|
|
|
public void testBlankLinesInSnippetContinuation() {
|
|
|
|
test(Locale.ROOT, false, new String[]{"--no-startup"}, "",
|
|
|
|
a -> assertCommand(a, "class C {",
|
|
|
|
""),
|
|
|
|
a -> assertCommand(a, "",
|
|
|
|
""),
|
|
|
|
a -> assertCommand(a, "",
|
|
|
|
""),
|
|
|
|
a -> assertCommand(a, " int x;",
|
|
|
|
""),
|
|
|
|
a -> assertCommand(a, "",
|
|
|
|
""),
|
|
|
|
a -> assertCommand(a, "",
|
|
|
|
""),
|
|
|
|
a -> assertCommand(a, "}",
|
|
|
|
"| created class C"),
|
|
|
|
a -> assertCommand(a, "/list",
|
|
|
|
"\n" +
|
|
|
|
" 1 : class C {\n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" int x;\n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" }")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-03 02:31:30 +00:00
|
|
|
@Test
|
|
|
|
public void testCompoundStart() {
|
|
|
|
test(new String[]{"--startup", "DEFAULT", "--startup", "PRINTING"},
|
|
|
|
(a) -> assertCommand(a, "printf(\"%4.2f\", Math.PI)",
|
|
|
|
"", "", null, "3.14", "")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testJavaSeStart() {
|
|
|
|
test(new String[]{"--startup", "JAVASE"},
|
|
|
|
(a) -> assertCommand(a, "ZoneOffsetTransitionRule.TimeDefinition.WALL",
|
|
|
|
"$1 ==> WALL")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-14 18:45:22 +00:00
|
|
|
@Test
|
|
|
|
public void testJavaSeSetStart() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommand(a, "/set sta JAVASE", ""),
|
|
|
|
(a) -> assertCommand(a, "/reset", "| Resetting state."),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/li -a",
|
|
|
|
s -> assertTrue(s.split("import ").length > 160,
|
|
|
|
"not enough imports for JAVASE:\n" + s))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-05-17 04:46:32 +00:00
|
|
|
public void defineClasses() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
|
|
|
|
(a) -> assertClass(a, "class A { }", "class", "A"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
|
|
|
|
(a) -> assertClass(a, "interface A { }", "interface", "A"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
|
|
|
|
(a) -> assertClass(a, "enum A { }", "enum", "A"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
|
|
|
|
(a) -> assertClass(a, "@interface A { }", "@interface", "A"),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
|
|
|
|
(a) -> assertCommandCheckOutput(a, "/types", assertClasses())
|
|
|
|
);
|
|
|
|
}
|
2016-12-22 04:14:39 +00:00
|
|
|
|
|
|
|
@Test
|
2016-04-13 05:23:11 +00:00
|
|
|
public void testCommandPrefix() {
|
|
|
|
test(a -> assertCommandCheckOutput(a, "/s",
|
|
|
|
assertStartsWith("| Command: '/s' is ambiguous: /save, /set")),
|
|
|
|
a -> assertCommand(a, "int var", "var ==> 0"),
|
|
|
|
a -> assertCommandCheckOutput(a, "/va",
|
|
|
|
assertStartsWith("| int var = 0")),
|
|
|
|
a -> assertCommandCheckOutput(a, "/save",
|
|
|
|
assertStartsWith("| '/save' requires a filename argument.")));
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-28 01:13:19 +00:00
|
|
|
public void testOptionQ() {
|
2016-11-03 16:12:02 +00:00
|
|
|
test(Locale.ROOT, false, new String[]{"-q", "--no-startup"}, "",
|
2016-04-28 01:13:19 +00:00
|
|
|
(a) -> assertCommand(a, "1+1", "$1 ==> 2"),
|
|
|
|
(a) -> assertCommand(a, "int x = 5", "")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-08-23 02:31:37 +00:00
|
|
|
public void testOptionS() {
|
2016-11-03 16:12:02 +00:00
|
|
|
test(Locale.ROOT, false, new String[]{"-s", "--no-startup"}, "",
|
2016-04-28 01:13:19 +00:00
|
|
|
(a) -> assertCommand(a, "1+1", "")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-28 01:13:19 +00:00
|
|
|
public void testOptionV() {
|
2016-08-23 02:31:37 +00:00
|
|
|
test(new String[]{"-v", "--no-startup"},
|
2016-04-28 01:13:19 +00:00
|
|
|
(a) -> assertCommand(a, "1+1",
|
|
|
|
"$1 ==> 2\n" +
|
|
|
|
"| created scratch variable $1 : int")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-28 01:13:19 +00:00
|
|
|
public void testOptionFeedback() {
|
2016-11-03 16:12:02 +00:00
|
|
|
test(Locale.ROOT, false, new String[]{"--feedback", "concise", "--no-startup"}, "",
|
2016-04-28 01:13:19 +00:00
|
|
|
(a) -> assertCommand(a, "1+1", "$1 ==> 2"),
|
|
|
|
(a) -> assertCommand(a, "int x = 5", "")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-08-23 02:31:37 +00:00
|
|
|
public void testCompoundOptions() {
|
|
|
|
Consumer<String> confirmNoStartup = s -> {
|
|
|
|
assertEquals(0, Stream.of(s.split("\n"))
|
|
|
|
.filter(l -> !l.isEmpty())
|
|
|
|
.count(), "Expected no lines: " + s);
|
|
|
|
};
|
2016-11-03 16:12:02 +00:00
|
|
|
test(Locale.ROOT, false, new String[]{"-nq"}, "",
|
2016-08-23 02:31:37 +00:00
|
|
|
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
|
|
|
|
(a) -> assertCommand(a, "1+1", "$1 ==> 2"),
|
|
|
|
(a) -> assertCommand(a, "int x = 5", "")
|
|
|
|
);
|
2016-11-03 16:12:02 +00:00
|
|
|
test(Locale.ROOT, false, new String[]{"-qn"}, "",
|
2016-08-23 02:31:37 +00:00
|
|
|
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
|
|
|
|
(a) -> assertCommand(a, "1+1", "$1 ==> 2"),
|
|
|
|
(a) -> assertCommand(a, "int x = 5", "")
|
|
|
|
);
|
2016-11-03 16:12:02 +00:00
|
|
|
test(Locale.ROOT, false, new String[]{"-ns"}, "",
|
2016-08-23 02:31:37 +00:00
|
|
|
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
|
|
|
|
(a) -> assertCommand(a, "1+1", "")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-04-28 01:13:19 +00:00
|
|
|
public void testOptionR() {
|
2016-08-23 02:31:37 +00:00
|
|
|
test(new String[]{"-R-Dthe.sound=blorp", "--no-startup"},
|
2016-04-28 01:13:19 +00:00
|
|
|
(a) -> assertCommand(a, "System.getProperty(\"the.sound\")",
|
|
|
|
"$1 ==> \"blorp\"")
|
|
|
|
);
|
|
|
|
}
|
2016-05-20 18:55:46 +00:00
|
|
|
|
2017-01-06 18:31:25 +00:00
|
|
|
@Test
|
|
|
|
public void testWrapSourceHandlerDiagCrash() {
|
|
|
|
test(new String[]{"--add-exports", "jdk.javadoc/ALL-UNNAMED"},
|
|
|
|
(a) -> assertCommand(a, "1+1", "$1 ==> 2")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:14:39 +00:00
|
|
|
@Test
|
2016-05-20 18:55:46 +00:00
|
|
|
public void test8156910() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandOutputContains(a, "System.out.println(\"%5d\", 10);", "%5d"),
|
|
|
|
(a) -> assertCommandOutputContains(a, "1234", "==> 1234")
|
|
|
|
);
|
|
|
|
}
|
2017-09-26 11:52:53 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testIntersection() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandOutputContains(a, "<Z extends Runnable&CharSequence> Z get1() { return null; }", "get1()"),
|
|
|
|
(a) -> assertCommandOutputContains(a, "var g1 = get1()", "g1"),
|
|
|
|
(a) -> assertCommand(a, "/vars g1", "| CharSequence&Runnable g1 = null"),
|
|
|
|
(a) -> assertCommandOutputContains(a, "<Z extends Number&CharSequence> Z get2() { return null; }", "get2()"),
|
|
|
|
(a) -> assertCommandOutputContains(a, "var g2 = get2()", "g2"),
|
|
|
|
(a) -> assertCommand(a, "/vars g2", "| Number&CharSequence g2 = null")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAnonymous() {
|
|
|
|
test(
|
|
|
|
(a) -> assertCommandOutputContains(a, "var r1 = new Object() {}", "r1"),
|
|
|
|
(a) -> assertCommandOutputContains(a, "/vars r1", "| <anonymous class extending Object> r1 = "),
|
|
|
|
(a) -> assertCommandOutputContains(a, "var r2 = new Runnable() { public void run() { } }", "r2"),
|
2018-01-19 16:11:52 +00:00
|
|
|
(a) -> assertCommandOutputContains(a, "/vars r2", "| <anonymous class implementing Runnable> r2 = "),
|
|
|
|
(a) -> assertCommandOutputContains(a, "import java.util.stream.*;", ""),
|
|
|
|
(a) -> assertCommandOutputContains(a, "var list = Stream.of(1, 2, 3).map(j -> new Object() { int i = j; }).collect(Collectors.toList());",
|
|
|
|
"list"),
|
|
|
|
(a) -> assertCommandOutputContains(a, "/vars list", "| List<<anonymous class extending Object>> list = ")
|
2017-09-26 11:52:53 +00:00
|
|
|
);
|
|
|
|
}
|
2018-02-23 18:49:56 +00:00
|
|
|
|
|
|
|
// This is mainly interesting in the TestLocalSimpleTest case (8198573)
|
|
|
|
@Test
|
|
|
|
public void testUpdateFalsePositive() {
|
|
|
|
test(
|
|
|
|
a -> assertClass(a, "class A { int a() { int error = 0; return error; } }", "class", "A"),
|
|
|
|
a -> assertVariable(a, "A", "a", "new A()", "A@.+"),
|
|
|
|
a -> assertVariable(a, "int", "error", "4711", "4711"),
|
|
|
|
a -> assertCommandOutputContains(a, "a", "A@")
|
|
|
|
);
|
|
|
|
}
|
2016-04-09 18:03:48 +00:00
|
|
|
}
|