summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2023-11-29 11:46:33 +0100
committergit <svn-admin@ruby-lang.org>2023-11-29 13:56:19 +0000
commit2af82e23165180f20ca2af374aedb7a45dedcc20 (patch)
tree1bd829f6f15140c645496167a208d38736ac8d81 /test
parent2653404840952d25bbdd7deaf599fbfb1f5287f0 (diff)
[ruby/prism] Convert start line to signed integers
Ruby allows for 0 or negative line start, this is often used with `eval` calls to get a correct offset when prefixing a snippet. e.g. ```ruby caller = caller_locations(1, 1).first class_eval <<~RUBY, caller.path, caller.line - 2 # frozen_string_literal: true def some_method #{caller_provided_code_snippet} end RUBY ``` https://github.com/ruby/prism/commit/0d14ed1452
Diffstat (limited to 'test')
-rw-r--r--test/prism/parse_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/prism/parse_test.rb b/test/prism/parse_test.rb
index 6bd7a5d2a1..2feb15b48b 100644
--- a/test/prism/parse_test.rb
+++ b/test/prism/parse_test.rb
@@ -46,6 +46,22 @@ module Prism
assert_equal filepath, find_source_file_node(result.value).filepath
end
+ def test_parse_takes_line
+ line = 4
+ result = Prism.parse("def foo\n __FILE__\nend", line: line)
+
+ assert_equal line, result.value.location.start_line
+ assert_equal line + 1, find_source_file_node(result.value).location.start_line
+ end
+
+ def test_parse_takes_negative_lines
+ line = -2
+ result = Prism.parse("def foo\n __FILE__\nend", line: line)
+
+ assert_equal line, result.value.location.start_line
+ assert_equal line + 1, find_source_file_node(result.value).location.start_line
+ end
+
def test_parse_lex
node, tokens = Prism.parse_lex("def foo; end").value