Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ GEM
erb (5.0.1)
extconf_compile_commands_json (0.0.7)
ffi (1.17.2)
ffi (1.17.2-arm64-darwin)
fileutils (1.7.3)
goodcheck (3.1.0)
marcel (>= 1.0, < 2.0)
Expand All @@ -63,16 +64,14 @@ GEM
logger (1.7.0)
marcel (1.0.4)
memory_profiler (1.1.0)
mini_portile2 (2.8.9)
minitest (5.25.5)
mutex_m (0.3.0)
net-protocol (0.2.2)
timeout
net-smtp (0.5.1)
net-protocol
nkf (0.2.0)
nokogiri (1.18.8)
mini_portile2 (~> 2.8.2)
nokogiri (1.18.8-arm64-darwin)
racc (~> 1.4)
ostruct (0.6.1)
parallel (1.27.0)
Expand All @@ -86,8 +85,8 @@ GEM
psych (4.0.6)
stringio
public_suffix (6.0.2)
raap (1.2.0)
rbs (~> 3.0)
raap (1.3.0)
rbs (~> 3.9.0)
timeout (~> 0.4)
racc (1.8.1)
rainbow (3.1.1)
Expand Down Expand Up @@ -176,6 +175,7 @@ GEM
zlib (3.2.1)

PLATFORMS
arm64-darwin-24

DEPENDENCIES
abbrev
Expand Down
31 changes: 18 additions & 13 deletions lib/rbs/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,24 @@ def line_count

def ranges
@ranges ||= begin
lines = content.lines
lines << "" if content.end_with?("\n")

ranges = [] #: Array[Range[Integer]]
offset = 0

lines.each do |line|
size0 = line.size
line = line.chomp
range = offset...(offset+line.size)
ranges << range

offset += size0
if content.empty?
ranges = [0...0] #: Array[Range[Integer]]
lines = [""]
else
lines = content.lines
lines << "" if content.end_with?("\n")

ranges = [] #: Array[Range[Integer]]
offset = 0

lines.each do |line|
size0 = line.size
line = line.chomp
range = offset...(offset+line.size)
ranges << range

offset += size0
end
end

ranges
Expand Down
15 changes: 15 additions & 0 deletions test/rbs/ast/ruby/comment_block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ def test_each_paragraph
end
end

def test_each_paragraph__empty
buffer, comments = parse_comments(<<~RUBY)
#
RUBY

block = CommentBlock.new(buffer, comments)

paragraphs = block.each_paragraph([]).to_a

paragraphs[0].tap do |paragraph|
assert_instance_of RBS::Location, paragraph
assert_equal "", paragraph.local_source
end
end

def test_each_paragraph_colon
buffer, comments = parse_comments(<<~RUBY)
# : Foo
Expand Down
19 changes: 19 additions & 0 deletions test/rbs/buffer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,23 @@ def test_sub_buffer
assert_equal [3, 0], sub_buffer.pos_to_loc(6)
end
end

def test_empty_buffer
buffer = Buffer.new(name: Pathname("foo.rbs"), content: "")

assert_equal "", buffer.content
assert_equal [""], buffer.lines
assert_equal [0...0], buffer.ranges
assert_equal "", buffer.content
end

def test_empty_sub_buffer
buffer = Buffer.new(name: Pathname("foo.rbs"), content: "")

sub_buffer = buffer.sub_buffer(lines: [0...0])
assert_equal "", sub_buffer.content
assert_equal [""], sub_buffer.lines
assert_equal [0...0], sub_buffer.ranges
assert_equal "", sub_buffer.content
end
end
Loading