Skip to content

Commit

Permalink
+ Added Parser::Source::Range#to_range. (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliabylich committed May 22, 2020
1 parent ea787b5 commit 54da73c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit 54da73c

Please sign in to comment.