Skip to content

Commit

Permalink
Allow creating of Buffer with source
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed May 18, 2020
1 parent 21581a2 commit fdd09c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/parser/source/buffer.rb
Expand Up @@ -102,7 +102,7 @@ def self.reencode_string(input)
end
end

def initialize(name, first_line = 1)
def initialize(name, first_line = 1, source: nil)
@name = name.to_s
@source = nil
@first_line = first_line
Expand All @@ -116,6 +116,8 @@ def initialize(name, first_line = 1)
# Cache for fast lookup
@line_for_position = {}
@column_for_position = {}

self.source = source if source
end

##
Expand Down
3 changes: 3 additions & 0 deletions test/test_source_buffer.rb
Expand Up @@ -20,6 +20,9 @@ def test_initialize

buffer = Parser::Source::Buffer.new('(string)', 5)
assert_equal 5, buffer.first_line

buffer = Parser::Source::Buffer.new('(string)', source: '2+2')
assert_equal '2+2', buffer.source
end

def test_source_setter
Expand Down

0 comments on commit fdd09c5

Please sign in to comment.