Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ Added Parser::Source::Range#to_range. #697

Merged
merged 1 commit into from May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/parser/source/range.rb
Expand Up @@ -149,6 +149,13 @@ def to_a
(@begin_pos...@end_pos).to_a
end

##
# @return [Range] a Ruby range with the same `begin_pos` and `end_pos`
#
def to_range
self.begin_pos...self.end_pos
end

##
# Composes a GNU/Clang-style string representation of the beginning of this
# range.
Expand Down
5 changes: 5 additions & 0 deletions test/test_source_range.rb
Expand Up @@ -155,6 +155,11 @@ def test_is?
refute sr.is?('bar')
end

def test_to_range
sr = Parser::Source::Range.new(@buf, 10, 20)
assert_equal (10...20), sr.to_range
end

def test_to_s
sr = Parser::Source::Range.new(@buf, 8, 9)
assert_equal '(string):2:2', sr.to_s
Expand Down