langtools/test/jdk/jshell/SimpleRegressionTest.java
author rfield
Mon, 06 Feb 2017 09:00:02 -0800
changeset 43586 cc7a4eb79b29
parent 42971 22c8c025a651
child 43587 6103af590758
permissions -rw-r--r--
8173848: JShell: less-than causes: reached end of file while parsing Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     1
/*
41158
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     4
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     8
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    14
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    18
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    21
 * questions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    22
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    23
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    24
/*
43586
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 42971
diff changeset
    25
 * @test 8130450 8158906 8154374 8166400 8171892 8173848
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    26
 * @summary simple regression test
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
 * @build KullaTesting TestingInputStream
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    28
 * @run testng SimpleRegressionTest
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    29
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    30
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
import java.util.List;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    34
import javax.tools.Diagnostic;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
import jdk.jshell.Snippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
import jdk.jshell.VarSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
import jdk.jshell.SnippetEvent;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    39
import org.testng.annotations.Test;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
import static org.testng.Assert.assertEquals;
40512
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
    42
import static org.testng.Assert.assertFalse;
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
    43
import static org.testng.Assert.assertTrue;
37005
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
    44
import static jdk.jshell.Snippet.Status.OVERWRITTEN;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
import static jdk.jshell.Snippet.SubKind.TEMP_VAR_EXPRESSION_SUBKIND;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
import static jdk.jshell.Snippet.Status.VALID;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
@Test
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
public class SimpleRegressionTest extends KullaTesting {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    50
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
    public void testSnippetMemberAssignment() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
        assertEval("class C { int y; }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
        assertEval("C c = new C();");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    54
        assertVarKeyMatch("c.y = 4;", true, "$1", TEMP_VAR_EXPRESSION_SUBKIND, "int", added(VALID));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
    public void testUserTakesTempVarName() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
        assertEval("int $2 = 4;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
        assertEval("String $1;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
        assertVarKeyMatch("1234;", true, "$3", TEMP_VAR_EXPRESSION_SUBKIND, "int", added(VALID));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    63
    public void testCompileThrow() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
        assertEvalException("throw new Exception();");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
    public void testMultiSnippetDependencies() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
        List<SnippetEvent> events = assertEval("int a = 3, b = a+a, c = b *100;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
                DiagCheck.DIAG_OK, DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
                chain(added(VALID)),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
                chain(added(VALID)),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
                chain(added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
        assertEquals(events.get(0).value(), "3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
        assertEquals(events.get(1).value(), "6");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
        assertEquals(events.get(2).value(), "600");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
        assertEval("c;", "600");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
43586
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 42971
diff changeset
    79
    public void testLessThanParsing() {
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 42971
diff changeset
    80
        assertEval("int x = 3;", "3");
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 42971
diff changeset
    81
        assertEval("int y = 4;", "4");
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 42971
diff changeset
    82
        assertEval("int z = 5;", "5");
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 42971
diff changeset
    83
        assertEval("x < y", "true");
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 42971
diff changeset
    84
        assertEval("x < y;", "true");
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 42971
diff changeset
    85
        assertEval("x < y && y < z", "true");
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 42971
diff changeset
    86
    }
cc7a4eb79b29 8173848: JShell: less-than causes: reached end of file while parsing
rfield
parents: 42971
diff changeset
    87
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
    public void testNotStmtCannotResolve() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
        assertDeclareFail("dfasder;", new ExpectedDiagnostic("compiler.err.cant.resolve.location", 0, 7, 0, -1, -1, Diagnostic.Kind.ERROR));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    92
    public void testNotStmtIncomparable() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    93
        assertDeclareFail("true == 5.0;", new ExpectedDiagnostic("compiler.err.incomparable.types", 0, 11, 5, -1, -1, Diagnostic.Kind.ERROR));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    95
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    96
    public void testStringAdd() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
        assertEval("String s = \"a\" + \"b\";", "\"ab\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
    public void testExprSanity() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
        assertEval("int x = 3;", "3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
        assertEval("int y = 4;", "4");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
        assertEval("x + y;", "7");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   106
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   107
    public void testGenericMethodCrash() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   108
        assertDeclareWarn1("<T> void f(T...a) {}", (ExpectedDiagnostic) null);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
        Snippet sn = methodKey(assertEval("<R> R n(R x) { return x; }", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
        VarSnippet sne = varKey(assertEval("n(5)", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
        assertEquals(sne.typeName(), "Integer");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
    }
37005
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   113
40512
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   114
    public void testLongRemoteStrings() { //8158906
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   115
        assertEval("String m(int x) { byte[] b = new byte[x]; for (int i = 0; i < x; ++i) b[i] = (byte) 'a'; return new String(b); }");
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   116
        boolean[] shut = new boolean[1];
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   117
        getState().onShutdown(j -> {
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   118
            shut[0] = true;
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   119
        });
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   120
        for (String len : new String[]{"12345", "64000", "65535", "65536", "120000"}) {
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   121
            List<SnippetEvent> el = assertEval("m(" + len + ");");
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   122
            assertFalse(shut[0], "JShell died with long string");
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   123
            assertEquals(el.size(), 1, "Excepted one event");
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   124
            assertTrue(el.get(0).value().length() > 10000,
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   125
                    "Expected truncated but long String, got: " + el.get(0).value().length());
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   126
        }
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   127
    }
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   128
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   129
    public void testLongRemoteJapaneseStrings() { //8158906
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   130
        assertEval("import java.util.stream.*;");
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   131
        assertEval("String m(int x) { return Stream.generate(() -> \"\u3042\").limit(x).collect(Collectors.joining()); }");
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   132
        boolean[] shut = new boolean[1];
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   133
        getState().onShutdown(j -> {
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   134
            shut[0] = true;
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   135
        });
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   136
        for (String len : new String[]{"12345", "21843", "21844", "21845", "21846", "64000", "65535", "65536", "120000"}) {
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   137
            List<SnippetEvent> el = assertEval("m(" + len + ");");
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   138
            assertFalse(shut[0], "JShell died with long string");
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   139
            assertEquals(el.size(), 1, "Excepted one event");
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   140
            assertTrue(el.get(0).value().length() > 10000,
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   141
                    "Expected truncated but long String, got: " + el.get(0).value().length());
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   142
        }
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   143
    }
b9359154240c 8158906: JShell: crashes with extremely long result value
rfield
parents: 37005
diff changeset
   144
37005
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   145
    // 8130450
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   146
    public void testDuplicate() {
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   147
        Snippet snm = methodKey(assertEval("void mm() {}", added(VALID)));
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   148
        assertEval("void mm() {}",
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   149
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   150
                ste(snm, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   151
        Snippet snv = varKey(assertEval("boolean b;", added(VALID)));
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   152
        assertEval("boolean b;",
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   153
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   154
                ste(snv, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   155
    }
40516
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 40512
diff changeset
   156
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 40512
diff changeset
   157
    public void testContextClassLoader() {
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 40512
diff changeset
   158
        assertEval("class C {}");
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 40512
diff changeset
   159
        assertEval("C.class.getClassLoader() == Thread.currentThread().getContextClassLoader()", "true");
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 40512
diff changeset
   160
    }
41158
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   161
42971
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   162
    public void testArrayRepresentation() {
41158
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   163
        assertEval("new int[4]", "int[4] { 0, 0, 0, 0 }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   164
        assertEval("new int[0]", "int[0] {  }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   165
        assertEval("new byte[2]", "byte[2] { 0, 0 }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   166
        assertEval("new short[] { 1234, 4321 }", "short[2] { 1234, 4321 }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   167
        assertEval("new long[] { 123456789 }", "long[1] { 123456789 }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   168
        assertEval("new float[] { -23.5645f, 1.0101f }", "float[2] { -23.5645, 1.0101 }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   169
        assertEval("new double[] { 1/8, Math.PI }", "double[2] { 0.0, 3.141592653589793 }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   170
        assertEval("new String[] { \"hi\", \"low\", null }", "String[3] { \"hi\", \"low\", null }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   171
        assertEval("new char[] { 'a', 34, 77 }", "char[3] { 'a', '\"', 'M' }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   172
        assertEval("new boolean[] { false, true }", "boolean[2] { false, true }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   173
        assertEval("new int[][] { new int[] {44, 55}, new int[] {88,99}}",
42971
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   174
                "int[2][] { int[2] { 44, 55 }, int[2] { 88, 99 } }");
41158
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   175
        assertEval("new Object[] { \"howdy\", new int[] { 33, 44, 55 }, new String[] { \"up\", \"down\" }}",
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   176
                "Object[3] { \"howdy\", int[3] { 33, 44, 55 }, String[2] { \"up\", \"down\" } }");
957f4fa38bd6 8166400: JShell: friendlier representation of array values
rfield
parents: 40516
diff changeset
   177
    }
42971
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   178
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   179
    public void testMultiDimArrayRepresentation() {
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   180
        assertEval("new int[3][1]",
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   181
                "int[3][] { int[1] { 0 }, int[1] { 0 }, int[1] { 0 } }");
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   182
        assertEval("new int[3][]",
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   183
                "int[3][] { null, null, null }");
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   184
        assertEval("new int[][] { new int[] {44}, new int[] {77, 88,99}}",
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   185
                "int[2][] { int[1] { 44 }, int[3] { 77, 88, 99 } }");
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   186
        assertEval("new String[3][1]",
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   187
                "String[3][] { String[1] { null }, String[1] { null }, String[1] { null } }");
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   188
        assertEval("class C { }");
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   189
        assertEval("new C[3][2]",
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   190
                "C[3][] { C[2] { null, null }, C[2] { null, null }, C[2] { null, null } }");
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   191
        assertEval("new boolean[2][1][3]",
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   192
                "boolean[2][][] { boolean[1][] { boolean[3] { false, false, false } }, boolean[1][] { boolean[3] { false, false, false } } }");
22c8c025a651 8171892: JShell: incorrect printing of multidemensional arrays
rfield
parents: 41158
diff changeset
   193
    }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   194
}