Skip to content

Commit 5346a9b

Browse files
entlicherchrisseaton
authored andcommitted
[GR-13087] Test for "no properties"
1 parent 618ce28 commit 5346a9b

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/test/java/org/truffleruby/RubyDebugTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.InputStream;
3636
import java.io.InputStreamReader;
3737
import java.io.Reader;
38+
import java.util.Collection;
3839
import java.util.LinkedList;
3940
import java.util.concurrent.atomic.AtomicInteger;
4041

@@ -216,6 +217,55 @@ public void testEvalThrow() throws Throwable {
216217
assertExecutedOK("OK");
217218
}
218219

220+
@Test
221+
public void testProperties() throws Throwable {
222+
Source source = getSource("src/test/ruby/types.rb");
223+
run.addLast(() -> {
224+
assertNull(suspendedEvent);
225+
assertNotNull(debuggerSession);
226+
breakpoint = Breakpoint.newBuilder(DebuggerTester.getSourceImpl(source)).lineIs(27).build();
227+
debuggerSession.install(breakpoint);
228+
});
229+
assertLocation(27, "nme + nm1",
230+
"name", "\"Panama\"", // Possible bug: should really the quotes be included?
231+
"cityArray", "[80, 97, 110, 97, 109, 97]",
232+
"citySum", "590",
233+
"weatherTemperature", "14",
234+
"blt", "true",
235+
"blf", "false",
236+
"null", "nil",
237+
"nm1", "1",
238+
"nm11", "1.111",
239+
"nme", "3.5e+46",
240+
"nc", "(2+3i)",
241+
"nr", "(5404319552844595/18014398509481984)",
242+
"str", "\"A String\"",
243+
"symbol", ":symbolic",
244+
"arr", "[1, \"2\", 3.56, true, nil, \"A String\"]",
245+
"hash", "{:a=>1, \"b\"=>2}");
246+
run.addLast(() -> {
247+
final DebugStackFrame frame = suspendedEvent.getTopStackFrame();
248+
DebugValue value = frame.getScope().getDeclaredValue("name");
249+
Collection<DebugValue> properties = value.getProperties();
250+
assertTrue("String has " + properties.size() + " properties.", properties.size() > 0); // BUG: String have no properties
251+
value = frame.getScope().getDeclaredValue("hash");
252+
properties = value.getProperties();
253+
assertEquals(2, properties.size()); // 'hash' has two properties
254+
try {
255+
properties.iterator().next().as(String.class);
256+
} catch (IllegalStateException ex) {
257+
"Value is not readable".equals(ex.getMessage()); // BUG
258+
Assert.fail(ex.getMessage());
259+
}
260+
assertNotNull(value.getProperty("a")); // == null, BUG
261+
assertEquals(0, frame.getScope().getDeclaredValue("symbol").getProperties().size());
262+
assertEquals(6, frame.getScope().getDeclaredValue("arr").getArray().size());
263+
});
264+
performWork();
265+
context.eval(source);
266+
assertExecutedOK("OK");
267+
}
268+
219269
private void performWork() {
220270
try {
221271
if (ex == null && !run.isEmpty()) {

src/test/ruby/types.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 1.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
# Beware, RubyDebugTest use hard-coded line numbers from this file!
10+
11+
def temperature_in_city(name)
12+
cityArray = name.bytes
13+
citySum = cityArray.reduce(0, :+)
14+
weatherTemperature = citySum.modulo(36)
15+
blt = true
16+
blf = false
17+
null = nil
18+
nm1 = 1
19+
nm11 = 1.111
20+
nme = 35e45
21+
nc = 2 + 3i
22+
nr = Rational(0.3)
23+
str = "A String"
24+
symbol = :symbolic
25+
arr = [1, '2', 3.56, blt, nil, str]
26+
hash = {:a => 1, "b" => 2}
27+
nme + nm1
28+
end
29+
30+
temperature_in_city("Panama")

0 commit comments

Comments
 (0)