1 /* |
1 /* |
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
|
26 * @bug 8139829 |
26 * @summary test accessors of Snippet |
27 * @summary test accessors of Snippet |
27 * @build KullaTesting TestingInputStream |
28 * @build KullaTesting TestingInputStream |
28 * @run testng SnippetTest |
29 * @run testng SnippetTest |
29 */ |
30 */ |
30 |
31 |
31 import jdk.jshell.Snippet; |
32 import jdk.jshell.Snippet; |
32 import jdk.jshell.DeclarationSnippet; |
33 import jdk.jshell.DeclarationSnippet; |
33 import org.testng.annotations.Test; |
34 import org.testng.annotations.Test; |
34 |
35 |
|
36 import jdk.jshell.MethodSnippet; |
|
37 import jdk.jshell.Snippet.Status; |
|
38 import static org.testng.Assert.assertFalse; |
|
39 import static org.testng.Assert.assertTrue; |
35 import static jdk.jshell.Snippet.Status.VALID; |
40 import static jdk.jshell.Snippet.Status.VALID; |
36 import static jdk.jshell.Snippet.Status.RECOVERABLE_DEFINED; |
41 import static jdk.jshell.Snippet.Status.RECOVERABLE_DEFINED; |
37 import static jdk.jshell.Snippet.Status.OVERWRITTEN; |
42 import static jdk.jshell.Snippet.Status.OVERWRITTEN; |
|
43 import static jdk.jshell.Snippet.Status.RECOVERABLE_NOT_DEFINED; |
38 import static jdk.jshell.Snippet.SubKind.*; |
44 import static jdk.jshell.Snippet.SubKind.*; |
39 |
45 |
40 @Test |
46 @Test |
41 public class SnippetTest extends KullaTesting { |
47 public class SnippetTest extends KullaTesting { |
42 |
48 |
145 ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
151 ste(f, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
146 assertKeys(method("()void", "g"), clazz(KullaTesting.ClassType.INTERFACE, "A"), |
152 assertKeys(method("()void", "g"), clazz(KullaTesting.ClassType.INTERFACE, "A"), |
147 method("()double", "f")); |
153 method("()double", "f")); |
148 assertActiveKeys(); |
154 assertActiveKeys(); |
149 } |
155 } |
|
156 |
|
157 public void testBooleanSnippetQueries() { |
|
158 Snippet nd = varKey(assertEval("blort x;", added(RECOVERABLE_NOT_DEFINED))); |
|
159 assertTrue(nd.kind().isPersistent(), "nd.isPersistent"); |
|
160 Status ndstat = getState().status(nd); |
|
161 assertTrue(ndstat.isActive(), "nd.isActive"); |
|
162 assertFalse(ndstat.isDefined(), "nd.isDefined"); |
|
163 MethodSnippet g = methodKey(assertEval("void g() { f(); }", added(RECOVERABLE_DEFINED))); |
|
164 assertTrue(g.kind().isPersistent(), "g.isPersistent"); |
|
165 Status gstat = getState().status(g); |
|
166 assertTrue(gstat.isActive(), "g.isActive"); |
|
167 assertTrue(gstat.isDefined(), "g.isDefined"); |
|
168 getState().drop(g); |
|
169 assertTrue(g.kind().isPersistent(), "drop isPersistent"); |
|
170 gstat = getState().status(g); |
|
171 assertFalse(gstat.isActive(), "drop isActive"); |
|
172 assertFalse(gstat.isDefined(), "drop isDefined"); |
|
173 Snippet stmt = key(assertEval("if (true) {}", added(VALID))); |
|
174 assertFalse(stmt.kind().isPersistent(), "stmt isPersistent"); |
|
175 Status stmtstat = getState().status(stmt); |
|
176 assertTrue(stmtstat.isActive(), "stmt isActive"); |
|
177 assertTrue(stmtstat.isDefined(), "stmt isDefined"); |
|
178 } |
150 } |
179 } |