Skip to content

Commit 61f0d9d

Browse files
committed
TCK test for parse(InlineParsingRequest)
1 parent a60a893 commit 61f0d9d

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ AllCops:
99
- 'lib/truffle/socket/mri.rb' # taken from MRI
1010
- 'lib/truffle/ffi/library.rb' # taken from FFI gem
1111
- 'src/test/ruby/types.rb' # deliberately strange code for debugging purposes
12+
- 'src/test/ruby/lexical-context.rb' # deliberately strange code for debugging purposes
1213

1314
# Type 'Layout' (166):
1415
# Supports --auto-correct

src/test/java/org/truffleruby/RubyTCKLanguageProvider.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
package org.truffleruby;
1111

1212
import org.graalvm.polyglot.Context;
13+
import org.graalvm.polyglot.PolyglotException;
1314
import org.graalvm.polyglot.Source;
1415
import org.graalvm.polyglot.Value;
16+
import org.graalvm.polyglot.tck.InlineSnippet;
1517
import org.graalvm.polyglot.tck.LanguageProvider;
1618
import org.graalvm.polyglot.tck.ResultVerifier;
1719
import org.graalvm.polyglot.tck.Snippet;
1820
import org.graalvm.polyglot.tck.TypeDescriptor;
1921
import org.junit.Assert;
22+
import org.truffleruby.language.control.RaiseException;
2023
import org.truffleruby.shared.TruffleRuby;
2124

2225
import java.io.File;
@@ -142,6 +145,39 @@ public Collection<? extends Snippet> createScripts(Context context) {
142145
return Collections.unmodifiableList(res);
143146
}
144147

148+
@Override
149+
public Collection<? extends InlineSnippet> createInlineScripts(Context context) {
150+
List<InlineSnippet> res = new ArrayList<>();
151+
res.add(createInlineSnippet(
152+
context,
153+
getSource("src/test/ruby/lexical-context.rb"),
154+
16,
155+
"a + b + c",
156+
14 + 2 + 6));
157+
res.add(createInlineSnippet(
158+
context,
159+
getSource("src/test/ruby/lexical-context.rb"),
160+
16,
161+
"binding.local_variable_get(:a) + binding.local_variable_get(:b) + binding.local_variable_get(:c)",
162+
14 + 2 + 6));
163+
return Collections.unmodifiableList(res);
164+
}
165+
166+
private InlineSnippet createInlineSnippet(Context context, Source mainSource, int line, String inlineSource, int expected) {
167+
final Snippet mainSnippet = Snippet.newBuilder(mainSource.getName(), context.eval(mainSource), TypeDescriptor.ANY).build();
168+
169+
return InlineSnippet.newBuilder(mainSnippet, inlineSource)
170+
.locationPredicate(sourceSection ->
171+
sourceSection.getSource().getName().endsWith(mainSource.getName()) && sourceSection.getStartLine() == line)
172+
.resultVerifier(snippetRun -> {
173+
final PolyglotException exception = snippetRun.getException();
174+
if (exception != null) {
175+
throw exception;
176+
}
177+
Assert.assertEquals(expected, snippetRun.getResult().asInt());
178+
}).build();
179+
}
180+
145181
private Snippet createValueConstructor(Context context, String value, TypeDescriptor type) {
146182
return Snippet.newBuilder(value, context.eval(getId(), String.format("-> { %s }", value)), type).build();
147183
}

src/test/ruby/lexical-context.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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, RubyTCKLanguageProvider use hard-coded line numbers from this file!
10+
11+
-> {
12+
a = 14
13+
3.times do
14+
b = 2
15+
[6].each do |c|
16+
x = c
17+
end
18+
end
19+
}

0 commit comments

Comments
 (0)