@@ -15,16 +15,15 @@ def eat
1515 end
1616 EOM
1717
18- code_lines = CodeLine . from_source ( source )
19-
18+ code_lines = CleanDocument . new ( source : source ) . call . lines
2019 block = CodeBlock . new ( lines : code_lines [ 0 ] )
2120
2221 display = CaptureCodeContext . new (
2322 blocks : [ block ] ,
2423 code_lines : code_lines
2524 )
2625 lines = display . call
27- expect ( lines . join ) . to eq ( <<~EOM )
26+ expect ( lines . join ) . to eq ( <<~' EOM' )
2827 def sit
2928 end
3029 def bark
@@ -35,73 +34,28 @@ def eat
3534
3635 it "handles ambiguous end" do
3736 source = <<~'EOM'
38- def call # 1
39- puts "lol" # 2
40- end # one # 3
41- end # two # 4
42- EOM
43-
44- search = CodeSearch . new ( source )
45- search . call
46-
47- display = CaptureCodeContext . new (
48- blocks : search . invalid_blocks ,
49- code_lines : search . code_lines
50- )
51- lines = display . call
52-
53- lines = lines . sort . map ( &:original )
54-
55- expect ( lines . join ) . to eq ( <<~EOM )
56- def call # 1
57- end # one # 3
58- end # two # 4
59- EOM
60- end
61-
62- it "finds internal end associated with missing do" do
63- source = <<~'EOM'
64- def call
65- trydo
66-
67- @options = CommandLineParser.new.parse
68-
69- options.requires.each { |r| require!(r) }
70- load_global_config_if_exists
71- options.loads.each { |file| load(file) }
72-
73- @user_source_code = ARGV.join(' ')
74- @user_source_code = 'self' if @user_source_code == ''
75-
76- @callable = create_callable
77-
78- init_rexe_context
79- init_parser_and_formatters
80-
81- # This is where the user's source code will be executed; the action will in turn call `execute`.
82- lookup_action(options.input_mode).call unless options.noop
83-
84- output_log_entry
85- end # one
86- end # two
37+ def call # 0
38+ print "lol" # 1
39+ end # one # 2
40+ end # two # 3
8741 EOM
8842
89- search = CodeSearch . new ( source )
90- search . call
43+ code_lines = CleanDocument . new ( source : source ) . call . lines
44+ code_lines [ 0 ..2 ] . each ( &:mark_invisible )
45+ block = CodeBlock . new ( lines : code_lines )
9146
9247 display = CaptureCodeContext . new (
93- blocks : search . invalid_blocks ,
94- code_lines : search . code_lines
48+ blocks : [ block ] ,
49+ code_lines : code_lines
9550 )
9651 lines = display . call
9752
9853 lines = lines . sort . map ( &:original )
9954
100- expect ( lines . join ) . to eq ( <<~EOM )
101- def call
102- trydo
103- end # one
104- end # two
55+ expect ( lines . join ) . to eq ( <<~'EOM' )
56+ def call # 0
57+ end # one # 2
58+ end # two # 3
10559 EOM
10660 end
10761
@@ -110,22 +64,24 @@ def call
11064 lines . delete_at ( 148 - 1 )
11165 source = lines . join
11266
113- search = CodeSearch . new ( source )
114- search . call
67+ code_lines = CleanDocument . new ( source : source ) . call . lines
68+
69+ code_lines [ 0 ..75 ] . each ( &:mark_invisible )
70+ code_lines [ 77 ..-1 ] . each ( &:mark_invisible )
71+ expect ( code_lines . join . strip ) . to eq ( "class Lookups" )
72+
73+ block = CodeBlock . new ( lines : code_lines [ 76 ..149 ] )
11574
11675 display = CaptureCodeContext . new (
117- blocks : search . invalid_blocks ,
118- code_lines : search . code_lines
76+ blocks : [ block ] ,
77+ code_lines : code_lines
11978 )
12079 lines = display . call
12180
12281 lines = lines . sort . map ( &:original )
123- expect ( lines . join ) . to eq ( <<~EOM )
124- class Rexe
125- VERSION = '1.5.1'
126- class Lookups
127- def format_requires
128- end
82+ expect ( lines . join ) . to include ( <<~'EOM' . indent ( 2 ) )
83+ class Lookups
84+ def format_requires
12985 end
13086 EOM
13187 end
@@ -137,24 +93,27 @@ def bark
13793 puts "woof"
13894 end
13995 EOM
140- search = CodeSearch . new ( source )
141- search . call
14296
143- expect ( search . invalid_blocks . join . strip ) . to eq ( "class Dog" )
97+ code_lines = CleanDocument . new ( source : source ) . call . lines
98+ block = CodeBlock . new ( lines : code_lines )
99+ code_lines [ 1 ..-1 ] . each ( &:mark_invisible )
100+
101+ expect ( block . to_s . strip ) . to eq ( "class Dog" )
102+
144103 display = CaptureCodeContext . new (
145- blocks : search . invalid_blocks ,
146- code_lines : search . code_lines
104+ blocks : [ block ] ,
105+ code_lines : code_lines
147106 )
148107 lines = display . call . sort . map ( &:original )
149- expect ( lines . join ) . to eq ( <<~EOM )
108+ expect ( lines . join ) . to eq ( <<~' EOM' )
150109 class Dog
151110 def bark
152111 end
153112 EOM
154113 end
155114
156115 it "captures surrounding context on falling indent" do
157- syntax_string = <<~EOM
116+ source = <<~' EOM'
158117 class Blerg
159118 end
160119
@@ -168,18 +127,17 @@ def hello
168127 class Zerg
169128 end
170129 EOM
130+ code_lines = CleanDocument . new ( source : source ) . call . lines
131+ block = CodeBlock . new ( lines : code_lines [ 6 ] )
171132
172- search = CodeSearch . new ( syntax_string )
173- search . call
174-
175- expect ( search . invalid_blocks . join . strip ) . to eq ( 'it "foo" do' )
133+ expect ( block . to_s . strip ) . to eq ( 'it "foo" do' )
176134
177135 display = CaptureCodeContext . new (
178- blocks : search . invalid_blocks ,
179- code_lines : search . code_lines
136+ blocks : [ block ] ,
137+ code_lines : code_lines
180138 )
181139 lines = display . call . sort . map ( &:original )
182- expect ( lines . join ) . to eq ( <<~EOM )
140+ expect ( lines . join ) . to eq ( <<~' EOM' )
183141 class OH
184142 def hello
185143 it "foo" do
@@ -189,7 +147,7 @@ def hello
189147 end
190148
191149 it "captures surrounding context on same indent" do
192- syntax_string = <<~EOM
150+ source = <<~' EOM'
193151 class Blerg
194152 end
195153 class OH
@@ -200,7 +158,6 @@ def nope
200158 def lol
201159 end
202160
203- puts "here"
204161 end # here
205162
206163 def haha
@@ -214,26 +171,31 @@ class Zerg
214171 end
215172 EOM
216173
217- search = CodeSearch . new ( syntax_string )
218- search . call
174+ code_lines = CleanDocument . new ( source : source ) . call . lines
175+ block = CodeBlock . new ( lines : code_lines [ 7 ..10 ] )
176+ expect ( block . to_s ) . to eq ( <<~'EOM' . indent ( 2 ) )
177+ def lol
178+ end
179+
180+ end # here
181+ EOM
219182
220183 code_context = CaptureCodeContext . new (
221- blocks : search . invalid_blocks ,
222- code_lines : search . code_lines
184+ blocks : [ block ] ,
185+ code_lines : code_lines
223186 )
224187
225188 lines = code_context . call
226-
227189 out = DisplayCodeWithLineNumbers . new (
228190 lines : lines
229191 ) . call
230192
231- expect ( out ) . to eq ( <<~EOM . indent ( 2 ) )
193+ expect ( out ) . to eq ( <<~' EOM' . indent ( 2 ) )
232194 3 class OH
233195 8 def lol
234196 9 end
235- 12 end # here
236- 19 end
197+ 11 end # here
198+ 18 end
237199 EOM
238200 end
239201 end
0 commit comments