File tree Expand file tree Collapse file tree 3 files changed +52
-13
lines changed
Expand file tree Collapse file tree 3 files changed +52
-13
lines changed Original file line number Diff line number Diff line change @@ -29,19 +29,24 @@ def line_count
2929
3030 def ranges
3131 @ranges ||= begin
32- lines = content . lines
33- lines << "" if content . end_with? ( "\n " )
34-
35- ranges = [ ] #: Array[Range[Integer]]
36- offset = 0
37-
38- lines . each do |line |
39- size0 = line . size
40- line = line . chomp
41- range = offset ...( offset +line . size )
42- ranges << range
43-
44- offset += size0
32+ if content . empty?
33+ ranges = [ 0 ...0 ] #: Array[Range[Integer]]
34+ lines = [ "" ]
35+ else
36+ lines = content . lines
37+ lines << "" if content . end_with? ( "\n " )
38+
39+ ranges = [ ] #: Array[Range[Integer]]
40+ offset = 0
41+
42+ lines . each do |line |
43+ size0 = line . size
44+ line = line . chomp
45+ range = offset ...( offset +line . size )
46+ ranges << range
47+
48+ offset += size0
49+ end
4550 end
4651
4752 ranges
Original file line number Diff line number Diff line change @@ -144,6 +144,21 @@ def test_each_paragraph
144144 end
145145 end
146146
147+ def test_each_paragraph__empty
148+ buffer , comments = parse_comments ( <<~RUBY )
149+ #
150+ RUBY
151+
152+ block = CommentBlock . new ( buffer , comments )
153+
154+ paragraphs = block . each_paragraph ( [ ] ) . to_a
155+
156+ paragraphs [ 0 ] . tap do |paragraph |
157+ assert_instance_of RBS ::Location , paragraph
158+ assert_equal "" , paragraph . local_source
159+ end
160+ end
161+
147162 def test_each_paragraph_colon
148163 buffer , comments = parse_comments ( <<~RUBY )
149164 # : Foo
Original file line number Diff line number Diff line change @@ -96,4 +96,23 @@ def test_sub_buffer
9696 assert_equal [ 3 , 0 ] , sub_buffer . pos_to_loc ( 6 )
9797 end
9898 end
99+
100+ def test_empty_buffer
101+ buffer = Buffer . new ( name : Pathname ( "foo.rbs" ) , content : "" )
102+
103+ assert_equal "" , buffer . content
104+ assert_equal [ "" ] , buffer . lines
105+ assert_equal [ 0 ...0 ] , buffer . ranges
106+ assert_equal "" , buffer . content
107+ end
108+
109+ def test_empty_sub_buffer
110+ buffer = Buffer . new ( name : Pathname ( "foo.rbs" ) , content : "" )
111+
112+ sub_buffer = buffer . sub_buffer ( lines : [ 0 ...0 ] )
113+ assert_equal "" , sub_buffer . content
114+ assert_equal [ "" ] , sub_buffer . lines
115+ assert_equal [ 0 ...0 ] , sub_buffer . ranges
116+ assert_equal "" , sub_buffer . content
117+ end
99118end
You can’t perform that action at this time.
0 commit comments