37 import jdk.jshell.VarSnippet; |
37 import jdk.jshell.VarSnippet; |
38 import jdk.jshell.SnippetEvent; |
38 import jdk.jshell.SnippetEvent; |
39 import org.testng.annotations.Test; |
39 import org.testng.annotations.Test; |
40 |
40 |
41 import static org.testng.Assert.assertEquals; |
41 import static org.testng.Assert.assertEquals; |
|
42 import static org.testng.Assert.assertFalse; |
|
43 import static org.testng.Assert.assertTrue; |
42 import static jdk.jshell.Snippet.Status.OVERWRITTEN; |
44 import static jdk.jshell.Snippet.Status.OVERWRITTEN; |
43 import static jdk.jshell.Snippet.SubKind.TEMP_VAR_EXPRESSION_SUBKIND; |
45 import static jdk.jshell.Snippet.SubKind.TEMP_VAR_EXPRESSION_SUBKIND; |
44 import static jdk.jshell.Snippet.Status.VALID; |
46 import static jdk.jshell.Snippet.Status.VALID; |
45 |
47 |
46 @Test |
48 @Test |
98 Snippet sn = methodKey(assertEval("<R> R n(R x) { return x; }", added(VALID))); |
100 Snippet sn = methodKey(assertEval("<R> R n(R x) { return x; }", added(VALID))); |
99 VarSnippet sne = varKey(assertEval("n(5)", added(VALID))); |
101 VarSnippet sne = varKey(assertEval("n(5)", added(VALID))); |
100 assertEquals(sne.typeName(), "Integer"); |
102 assertEquals(sne.typeName(), "Integer"); |
101 } |
103 } |
102 |
104 |
|
105 public void testLongRemoteStrings() { //8158906 |
|
106 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); }"); |
|
107 boolean[] shut = new boolean[1]; |
|
108 getState().onShutdown(j -> { |
|
109 shut[0] = true; |
|
110 }); |
|
111 for (String len : new String[]{"12345", "64000", "65535", "65536", "120000"}) { |
|
112 List<SnippetEvent> el = assertEval("m(" + len + ");"); |
|
113 assertFalse(shut[0], "JShell died with long string"); |
|
114 assertEquals(el.size(), 1, "Excepted one event"); |
|
115 assertTrue(el.get(0).value().length() > 10000, |
|
116 "Expected truncated but long String, got: " + el.get(0).value().length()); |
|
117 } |
|
118 } |
|
119 |
|
120 public void testLongRemoteJapaneseStrings() { //8158906 |
|
121 assertEval("import java.util.stream.*;"); |
|
122 assertEval("String m(int x) { return Stream.generate(() -> \"\u3042\").limit(x).collect(Collectors.joining()); }"); |
|
123 boolean[] shut = new boolean[1]; |
|
124 getState().onShutdown(j -> { |
|
125 shut[0] = true; |
|
126 }); |
|
127 for (String len : new String[]{"12345", "21843", "21844", "21845", "21846", "64000", "65535", "65536", "120000"}) { |
|
128 List<SnippetEvent> el = assertEval("m(" + len + ");"); |
|
129 assertFalse(shut[0], "JShell died with long string"); |
|
130 assertEquals(el.size(), 1, "Excepted one event"); |
|
131 assertTrue(el.get(0).value().length() > 10000, |
|
132 "Expected truncated but long String, got: " + el.get(0).value().length()); |
|
133 } |
|
134 } |
|
135 |
103 // 8130450 |
136 // 8130450 |
104 public void testDuplicate() { |
137 public void testDuplicate() { |
105 Snippet snm = methodKey(assertEval("void mm() {}", added(VALID))); |
138 Snippet snm = methodKey(assertEval("void mm() {}", added(VALID))); |
106 assertEval("void mm() {}", |
139 assertEval("void mm() {}", |
107 ste(MAIN_SNIPPET, VALID, VALID, false, null), |
140 ste(MAIN_SNIPPET, VALID, VALID, false, null), |