langtools/test/jdk/jshell/HistoryTest.java
author tschatzl
Fri, 04 Aug 2017 14:15:42 +0200
changeset 46750 bcab0128a16f
parent 44683 610dc2b48954
permissions -rw-r--r--
8184346: Clean up G1CMBitmap Summary: Trim down and improve the G1CMBitMap class structure. Reviewed-by: mgerdin, shade, rkennke
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
/*
38521
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
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
/*
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    25
 * @test
41249
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
    26
 * @bug 8166744
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
 * @summary Test Completion
38521
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    28
 * @modules jdk.internal.le/jdk.internal.jline.extra
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41249
diff changeset
    29
 *          jdk.jshell/jdk.internal.jshell.tool:+open
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    30
 * @build HistoryTest
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
 * @run testng HistoryTest
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
38521
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    34
import java.lang.reflect.Field;
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    35
import java.util.Locale;
44683
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 42843
diff changeset
    36
import java.util.logging.Level;
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 42843
diff changeset
    37
import java.util.logging.Logger;
38521
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    38
import jdk.internal.jline.extra.EditingHistory;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    39
import org.testng.annotations.Test;
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    40
import jdk.internal.jshell.tool.JShellTool;
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    41
import jdk.internal.jshell.tool.JShellToolBuilder;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
import static org.testng.Assert.*;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
38521
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    44
public class HistoryTest extends ReplToolTesting {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    46
    private JShellTool repl;
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    47
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    48
    @Override
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    49
    protected void testRawRun(Locale locale, String[] args) {
44683
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 42843
diff changeset
    50
        // turn on logging of launch failures
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 42843
diff changeset
    51
        Logger.getLogger("jdk.jshell.execution").setLevel(Level.ALL);
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    52
        repl = ((JShellToolBuilder) builder(locale))
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    53
                .rawTool();
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    54
        try {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    55
            repl.start(args);
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    56
        } catch (Exception ex) {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    57
            fail("Repl tool died with exception", ex);
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    58
        }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    59
    }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    60
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    61
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
    public void testHistory() {
38521
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    63
        test(
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    64
             a -> {if (!a) setCommandInput("void test() {\n");},
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    65
             a -> {if (!a) setCommandInput("    System.err.println(1);\n");},
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    66
             a -> {if (!a) setCommandInput("    System.err.println(1);\n");},
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    67
             a -> {assertCommand(a, "} //test", "|  created method test()");},
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    68
             a -> {
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    69
                 if (!a) {
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    70
                     try {
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    71
                         previousAndAssert(getHistory(), "} //test");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    72
                         previousSnippetAndAssert(getHistory(), "void test() {");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    73
                     } catch (Exception ex) {
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    74
                         throw new IllegalStateException(ex);
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    75
                     }
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    76
                 }
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    77
                 assertCommand(a, "int dummy;", "dummy ==> 0");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    78
             });
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    79
        test(
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    80
             a -> {if (!a) setCommandInput("void test2() {\n");},
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    81
             a -> {assertCommand(a, "} //test2", "|  created method test2()");},
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    82
             a -> {
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    83
                 if (!a) {
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    84
                     try {
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    85
                         previousAndAssert(getHistory(), "} //test2");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    86
                         previousSnippetAndAssert(getHistory(), "void test2() {");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    87
                         previousSnippetAndAssert(getHistory(), "/debug 0"); //added by test framework
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    88
                         previousSnippetAndAssert(getHistory(), "/exit");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    89
                         previousSnippetAndAssert(getHistory(), "int dummy;");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    90
                         previousSnippetAndAssert(getHistory(), "void test() {");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    91
                     } catch (Exception ex) {
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    92
                         throw new IllegalStateException(ex);
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    93
                     }
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    94
                 }
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    95
                 assertCommand(a, "int dummy;", "dummy ==> 0");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
    96
             });
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42407
diff changeset
    99
    @Test
41249
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   100
    public void test8166744() {
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   101
        test(
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   102
             a -> {if (!a) setCommandInput("class C {\n");},
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   103
             a -> {if (!a) setCommandInput("void f() {\n");},
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   104
             a -> {if (!a) setCommandInput("}\n");},
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   105
             a -> {assertCommand(a, "}", "|  created class C");},
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   106
             a -> {
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   107
                 if (!a) {
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   108
                     try {
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   109
                         previousAndAssert(getHistory(), "}");
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   110
                         previousAndAssert(getHistory(), "}");
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   111
                         previousAndAssert(getHistory(), "void f() {");
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   112
                         previousAndAssert(getHistory(), "class C {");
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   113
                         getHistory().add("class C{");
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   114
                     } catch (Exception ex) {
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   115
                         throw new IllegalStateException(ex);
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   116
                     }
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   117
                 }
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   118
                 assertCommand(a, "int dummy;", "dummy ==> 0");
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   119
             });
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   120
        test(
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   121
             a -> {if (!a) setCommandInput("class C {\n");},
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   122
             a -> {if (!a) setCommandInput("void f() {\n");},
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   123
             a -> {if (!a) setCommandInput("}\n");},
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   124
             a -> {assertCommand(a, "}", "|  created class C");},
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   125
             a -> {
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   126
                 if (!a) {
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   127
                     try {
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   128
                         previousSnippetAndAssert(getHistory(), "class C {");
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   129
                         getHistory().add("class C{");
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   130
                     } catch (Exception ex) {
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   131
                         throw new IllegalStateException(ex);
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   132
                     }
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   133
                 }
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   134
                 assertCommand(a, "int dummy;", "dummy ==> 0");
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   135
             });
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   136
    }
8c2aab77c2d2 8166744: JShell: java.lang.IndexOutOfBoundsException for legal history access
shinyafox
parents: 38521
diff changeset
   137
38521
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
   138
    private EditingHistory getHistory() throws Exception {
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
   139
        Field input = repl.getClass().getDeclaredField("input");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
   140
        input.setAccessible(true);
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
   141
        Object console = input.get(repl);
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
   142
        Field history = console.getClass().getDeclaredField("history");
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
   143
        history.setAccessible(true);
f2fe39ab9256 8133549: Generalize jshell's EditingHistory
jlahoda
parents: 35359
diff changeset
   144
        return (EditingHistory) history.get(console);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   145
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   146
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
    private void previousAndAssert(EditingHistory history, String expected) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   148
        assertTrue(history.previous());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   149
        assertEquals(history.current().toString(), expected);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   150
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   151
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   152
    private void previousSnippetAndAssert(EditingHistory history, String expected) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   153
        assertTrue(history.previousSnippet());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   154
        assertEquals(history.current().toString(), expected);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   155
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   156
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   157
}