aboutsummaryrefslogtreecommitdiffstats
path: root/test/yarp
diff options
context:
space:
mode:
authorNathan Froyd <froydnj@gmail.com>2023-08-30 10:47:59 -0400
committergit <svn-admin@ruby-lang.org>2023-08-30 15:10:24 +0000
commitc521b6f823154eeb6135881cec510fbff088b7ac (patch)
treed33b5e05dbeb6a382336d644f584c14fbd6067f7 /test/yarp
parent74f4d2683e22fe1507ff4a95648f53be86d90d41 (diff)
downloadruby-c521b6f823154eeb6135881cec510fbff088b7ac.tar.gz
[ruby/yarp] add tests for `Location#join`
https://github.com/ruby/yarp/commit/b01711396f
Diffstat (limited to 'test/yarp')
-rw-r--r--test/yarp/ruby_api_test.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/yarp/ruby_api_test.rb b/test/yarp/ruby_api_test.rb
index f02026541d..73b8825df0 100644
--- a/test/yarp/ruby_api_test.rb
+++ b/test/yarp/ruby_api_test.rb
@@ -31,6 +31,33 @@ class YARPRubyAPITest < Test::Unit::TestCase
assert_equal 0.5ri, parse_expression("0.5ri").value
end
+ def test_location_join
+ recv, args_node, _ = parse_expression("1234 + 567").child_nodes
+ arg = args_node.arguments[0]
+
+ joined = recv.location.join(arg.location)
+ assert_equal 0, joined.start_offset
+ assert_equal 10, joined.length
+
+ e = assert_raises RuntimeError do
+ arg.location.join(recv.location)
+ end
+ assert_equal "Incompatible locations", e.message
+
+ other_recv, other_args_node, _ = parse_expression("1234 + 567").child_nodes
+ other_arg = other_args_node.arguments[0]
+
+ e = assert_raises RuntimeError do
+ other_arg.location.join(recv.location)
+ end
+ assert_equal "Incompatible sources", e.message
+
+ e = assert_raises RuntimeError do
+ recv.location.join(other_arg.location)
+ end
+ assert_equal "Incompatible sources", e.message
+ end
+
private
def parse_expression(source)