summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2025-12-16 09:48:41 +0100
committerBenoit Daloze <eregontp@gmail.com>2025-12-30 16:02:39 +0100
commitd82fc3360d7cfa7e1e1a4dddb668b4c38808538a (patch)
treedc7ade1ad746167100b3c6f59e48cd4b451c6af9 /test
parent19e539c9ee1701b34189fa0c1feb942adeb0e326 (diff)
Reapply "[Feature #6012] Extend `source_location` for end position
* This reverts commit 065c48cdf11a1c4cece84db44ed8624d294f8fd5. * This functionality is very valuable and has already taken 14 years to agree on the API. * Let's just document it's byte columns (in the next commit). * See https://bugs.ruby-lang.org/issues/21783#note-9
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_lambda.rb12
-rw-r--r--test/ruby/test_proc.rb18
2 files changed, 17 insertions, 13 deletions
diff --git a/test/ruby/test_lambda.rb b/test/ruby/test_lambda.rb
index 7738034240..3cbb54306c 100644
--- a/test/ruby/test_lambda.rb
+++ b/test/ruby/test_lambda.rb
@@ -276,27 +276,27 @@ class TestLambdaParameters < Test::Unit::TestCase
end
def test_do_lambda_source_location
- exp_lineno = __LINE__ + 3
+ exp = [__LINE__ + 1, 12, __LINE__ + 5, 7]
lmd = ->(x,
y,
z) do
#
end
- file, lineno = lmd.source_location
+ file, *loc = lmd.source_location
assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
- assert_equal(exp_lineno, lineno, "must be at the beginning of the block")
+ assert_equal(exp, loc)
end
def test_brace_lambda_source_location
- exp_lineno = __LINE__ + 3
+ exp = [__LINE__ + 1, 12, __LINE__ + 5, 5]
lmd = ->(x,
y,
z) {
#
}
- file, lineno = lmd.source_location
+ file, *loc = lmd.source_location
assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
- assert_equal(exp_lineno, lineno, "must be at the beginning of the block")
+ assert_equal(exp, loc)
end
def test_not_orphan_return
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index f74342322f..959ea87f25 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -513,7 +513,7 @@ class TestProc < Test::Unit::TestCase
file, lineno = method(:source_location_test).to_proc.binding.source_location
assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
- assert_equal(@@line_of_source_location_test, lineno, 'Bug #2427')
+ assert_equal(@@line_of_source_location_test[0], lineno, 'Bug #2427')
end
def test_binding_error_unless_ruby_frame
@@ -1499,15 +1499,19 @@ class TestProc < Test::Unit::TestCase
assert_include(EnvUtil.labeled_class(name, Proc).new {}.to_s, name)
end
- @@line_of_source_location_test = __LINE__ + 1
+ @@line_of_source_location_test = [__LINE__ + 1, 2, __LINE__ + 3, 5]
def source_location_test a=1,
b=2
end
def test_source_location
- file, lineno = method(:source_location_test).source_location
+ file, *loc = method(:source_location_test).source_location
assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
- assert_equal(@@line_of_source_location_test, lineno, 'Bug #2427')
+ assert_equal(@@line_of_source_location_test, loc, 'Bug #2427')
+
+ file, *loc = self.class.instance_method(:source_location_test).source_location
+ assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
+ assert_equal(@@line_of_source_location_test, loc, 'Bug #2427')
end
@@line_of_attr_reader_source_location_test = __LINE__ + 3
@@ -1540,13 +1544,13 @@ class TestProc < Test::Unit::TestCase
end
def test_block_source_location
- exp_lineno = __LINE__ + 3
- file, lineno = block_source_location_test(1,
+ exp_loc = [__LINE__ + 3, 49, __LINE__ + 4, 49]
+ file, *loc = block_source_location_test(1,
2,
3) do
end
assert_match(/^#{ Regexp.quote(__FILE__) }$/, file)
- assert_equal(exp_lineno, lineno)
+ assert_equal(exp_loc, loc)
end
def test_splat_without_respond_to