Skip to content

Commit 7bb5b72

Browse files
aardvark179eregon
authored andcommitted
Add a spec for reading caller variables and bindings.
1 parent af0379a commit 7bb5b72

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

spec/truffle/caller_data_spec.rb

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# truffleruby_primitives: true
2+
3+
# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. This
4+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
5+
# redistribute it and/or modify it under the terms of the:
6+
#
7+
# Eclipse Public License version 2.0, or
8+
# GNU General Public License version 2, or
9+
# GNU Lesser General Public License version 2.1.
10+
11+
require_relative '../ruby/spec_helper'
12+
13+
module TruffleCallerSpecFixtures
14+
15+
def self.last_line_set(last_line)
16+
Primitive.io_last_line_set(Primitive.caller_special_variables, last_line)
17+
last_line
18+
end
19+
20+
def self.last_match_set(match)
21+
Primitive.regexp_last_match_set(Primitive.caller_special_variables, match)
22+
match
23+
end
24+
25+
def self.caller_binding
26+
Primitive.caller_binding
27+
end
28+
29+
def self.caller_binding_and_variables(last_line, last_match)
30+
b = Primitive.caller_binding
31+
Primitive.io_last_line_set(Primitive.caller_special_variables, last_line)
32+
Primitive.regexp_last_match_set(Primitive.caller_special_variables, last_match)
33+
b
34+
end
35+
36+
end
37+
38+
describe "A caller" do
39+
40+
it "can have its special variables read and modified" do
41+
last_line = "Hello!"
42+
md = Primitive.matchdata_create(/o/, "Hello", [4], [5])
43+
TruffleCallerSpecFixtures.last_line_set(last_line)
44+
TruffleCallerSpecFixtures.last_match_set(md)
45+
$_.should == last_line
46+
$~.should == md
47+
end
48+
49+
it "can have its special variables read and modified through an intermediate #send" do
50+
last_line = "Hello!"
51+
md = Primitive.matchdata_create(/o/, "Hello", [4], [5])
52+
TruffleCallerSpecFixtures.send(:last_line_set, last_line)
53+
TruffleCallerSpecFixtures.send(:last_match_set, md)
54+
$_.should == last_line
55+
$~.should == md
56+
end
57+
58+
it "can have its special variables and frame read by the same method" do
59+
last_line = "Hello!"
60+
md = Primitive.matchdata_create(/o/, "Hello", [4], [5])
61+
b = TruffleCallerSpecFixtures.caller_binding_and_variables(last_line, md)
62+
$_.should == last_line
63+
$~.should == md
64+
b.local_variable_get(:md).should == md
65+
end
66+
67+
it "can have its special variables and frame read by the same method through an intermediate #send" do
68+
last_line = "Hello!"
69+
md = Primitive.matchdata_create(/o/, "Hello", [4], [5])
70+
b = TruffleCallerSpecFixtures.send(:caller_binding_and_variables, last_line, md)
71+
$_.should == last_line
72+
$~.should == md
73+
b.local_variable_get(:md).should == md
74+
end
75+
76+
end

0 commit comments

Comments
 (0)