seeing_is_believing 2.2.0 → 3.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Changelog.md +33 -0
- data/bin/seeing_is_believing +1 -1
- data/features/errors.feature +3 -3
- data/features/examples.feature +6 -6
- data/features/flags.feature +51 -196
- data/features/regression.feature +12 -3
- data/features/safe.feature +33 -0
- data/features/support/env.rb +20 -0
- data/features/xmpfilter-style.feature +156 -0
- data/lib/seeing_is_believing.rb +17 -35
- data/lib/seeing_is_believing/binary.rb +81 -176
- data/lib/seeing_is_believing/binary/align_chunk.rb +5 -7
- data/lib/seeing_is_believing/binary/align_file.rb +4 -5
- data/lib/seeing_is_believing/binary/align_line.rb +4 -4
- data/lib/seeing_is_believing/binary/annotate_end_of_file.rb +60 -0
- data/lib/seeing_is_believing/binary/annotate_every_line.rb +64 -0
- data/lib/seeing_is_believing/binary/annotate_xmpfilter_style.rb +133 -0
- data/lib/seeing_is_believing/binary/comment_formatter.rb +19 -5
- data/lib/seeing_is_believing/binary/comment_lines.rb +1 -1
- data/lib/seeing_is_believing/binary/commentable_lines.rb +1 -1
- data/lib/seeing_is_believing/binary/interpret_flags.rb +149 -0
- data/lib/seeing_is_believing/binary/parse_args.rb +96 -104
- data/lib/seeing_is_believing/binary/remove_annotations.rb +95 -0
- data/lib/seeing_is_believing/binary/rewrite_comments.rb +8 -30
- data/lib/seeing_is_believing/code.rb +99 -0
- data/lib/seeing_is_believing/evaluate_by_moving_files.rb +27 -19
- data/lib/seeing_is_believing/evaluate_with_eval_in.rb +27 -0
- data/lib/seeing_is_believing/event_stream/consumer.rb +111 -0
- data/lib/seeing_is_believing/event_stream/events.rb +16 -0
- data/lib/seeing_is_believing/event_stream/producer.rb +106 -0
- data/lib/seeing_is_believing/event_stream/update_result.rb +21 -0
- data/lib/seeing_is_believing/inspect_expressions.rb +24 -0
- data/lib/seeing_is_believing/parser_helpers.rb +1 -11
- data/lib/seeing_is_believing/result.rb +14 -56
- data/lib/seeing_is_believing/the_matrix.rb +14 -14
- data/lib/seeing_is_believing/version.rb +1 -1
- data/lib/seeing_is_believing/wrap_expressions.rb +32 -9
- data/seeing_is_believing.gemspec +7 -7
- data/spec/binary/comment_formatter_spec.rb +169 -18
- data/spec/binary/comment_lines_spec.rb +1 -1
- data/spec/binary/interpret_flags_spec.rb +307 -0
- data/spec/binary/parse_args_spec.rb +93 -91
- data/spec/binary/{clean_body_spec.rb → remove_annotations_spec.rb} +29 -22
- data/spec/binary/rewrite_comments_spec.rb +13 -13
- data/spec/code_spec.rb +49 -0
- data/spec/debugger_spec.rb +1 -1
- data/spec/evaluate_by_moving_files_spec.rb +7 -3
- data/spec/event_stream_spec.rb +390 -0
- data/spec/hard_core_ensure_spec.rb +1 -1
- data/spec/seeing_is_believing_spec.rb +137 -40
- data/spec/spec_helper.rb +3 -3
- data/spec/wrap_expressions_spec.rb +48 -35
- metadata +58 -35
- data/lib/seeing_is_believing/binary/add_annotations.rb +0 -144
- data/lib/seeing_is_believing/binary/clean_body.rb +0 -95
- data/lib/seeing_is_believing/has_exception.rb +0 -27
- data/lib/seeing_is_believing/line.rb +0 -90
- data/spec/line_spec.rb +0 -86
@@ -1,10 +1,26 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'spec_helper'
|
3
|
-
require 'seeing_is_believing'
|
4
3
|
require 'stringio'
|
4
|
+
require 'seeing_is_believing'
|
5
|
+
require 'seeing_is_believing/evaluate_with_eval_in'
|
6
|
+
|
7
|
+
RSpec.describe SeeingIsBelieving do
|
8
|
+
def method_result(name)
|
9
|
+
@result = def __some_method__; end
|
10
|
+
if :__some_method__ == @result
|
11
|
+
name.inspect
|
12
|
+
elsif nil == @result
|
13
|
+
nil.inspect
|
14
|
+
else
|
15
|
+
raise "huh? #{@result.inspect}"
|
16
|
+
end
|
17
|
+
end
|
5
18
|
|
6
|
-
describe SeeingIsBelieving do
|
7
19
|
def invoke(input, options={})
|
20
|
+
if options[:debug]
|
21
|
+
options.delete :debug
|
22
|
+
options[:debugger] = SeeingIsBelieving::Debugger.new(stream: $stderr, colour: true)
|
23
|
+
end
|
8
24
|
described_class.new(input, options).call
|
9
25
|
end
|
10
26
|
|
@@ -14,6 +30,10 @@ describe SeeingIsBelieving do
|
|
14
30
|
|
15
31
|
let(:proving_grounds_dir) { File.expand_path '../../proving_grounds', __FILE__ }
|
16
32
|
|
33
|
+
it 'evaluates with EvaluateByMovingFiles by default' do
|
34
|
+
expect(values_for "`echo 1`").to eq [['"1\n"']] # shows we're not using the only other option (EvaluateWithEvalIn)
|
35
|
+
end
|
36
|
+
|
17
37
|
it 'takes a string and returns a result of the line numbers (counting from 1) and each inspected result from that line' do
|
18
38
|
input = "10+10\n'2'+'2'"
|
19
39
|
expect(invoke(input)[1]).to eq ["20"]
|
@@ -25,6 +45,16 @@ describe SeeingIsBelieving do
|
|
25
45
|
expect(invoke(input)[1]).to eq ['"NUM"']
|
26
46
|
end
|
27
47
|
|
48
|
+
it 'allows uers to pass in their own inspection recorder' do
|
49
|
+
wrapper = lambda { |program, num_captures|
|
50
|
+
SeeingIsBelieving::InspectExpressions.call \
|
51
|
+
program,
|
52
|
+
num_captures,
|
53
|
+
after_each: -> line_number { ").tap { $SiB.record_result(:inspect, #{line_number}, 'zomg') }" }
|
54
|
+
}
|
55
|
+
expect(invoke(':body', record_expressions: wrapper)[1]).to eq ['"zomg"']
|
56
|
+
end
|
57
|
+
|
28
58
|
it 'remembers context of previous lines' do
|
29
59
|
expect(values_for("a=12\na*2")).to eq [['12'], ['24']]
|
30
60
|
end
|
@@ -51,8 +81,8 @@ describe SeeingIsBelieving do
|
|
51
81
|
it 'evalutes to an empty array for lines that it cannot understand' do
|
52
82
|
expect(values_for("[3].map \\\ndo |n|\n n*2\n end")).to eq [['[3]'], [], ['6'], ['[6]']]
|
53
83
|
expect(values_for("'\n1\n'")).to eq [[], [], ['"\n1\n"']]
|
54
|
-
expect(values_for("<<HEREDOC\n\n1\nHEREDOC")).to eq [[%Q'"\\n1\\n"']] # newlines escaped b/c lib inspects them
|
55
|
-
expect(values_for("<<-HEREDOC\n\n1\nHEREDOC")).to eq [[%Q'"\\n1\\n"']]
|
84
|
+
expect(values_for("<<HEREDOC\n\n1\nHEREDOC")).to eq [[%Q'"\\n1\\n"'], [], [], []] # newlines escaped b/c lib inspects them
|
85
|
+
expect(values_for("<<-HEREDOC\n\n1\nHEREDOC")).to eq [[%Q'"\\n1\\n"'], [], [], []]
|
56
86
|
end
|
57
87
|
|
58
88
|
it 'records the targets of chained methods' do
|
@@ -65,8 +95,8 @@ describe SeeingIsBelieving do
|
|
65
95
|
end
|
66
96
|
|
67
97
|
it "records heredocs" do
|
68
|
-
expect(values_for("<<A\n1\nA")).to
|
69
|
-
expect(values_for("<<-A\n1\nA")).to eq [[%'"1\\n"']]
|
98
|
+
expect(values_for("<<A\n1\nA")).to eq [[%'"1\\n"'], [], []]
|
99
|
+
expect(values_for("<<-A\n1\nA")).to eq [[%'"1\\n"'], [], []]
|
70
100
|
end
|
71
101
|
|
72
102
|
it 'does not insert code into the middle of heredocs' do
|
@@ -105,10 +135,7 @@ describe SeeingIsBelieving do
|
|
105
135
|
expect(result.exception.message).to eq 'omg!'
|
106
136
|
|
107
137
|
expect(result[1]).to eq ['12']
|
108
|
-
|
109
138
|
expect(result[2]).to eq []
|
110
|
-
expect(result[2].exception).to eq result.exception
|
111
|
-
|
112
139
|
expect(result[3]).to eq []
|
113
140
|
end
|
114
141
|
|
@@ -128,11 +155,11 @@ describe SeeingIsBelieving do
|
|
128
155
|
|
129
156
|
# comment
|
130
157
|
__LINE__')
|
131
|
-
).to eq [['1'], ['2'], [], [], ['5'], [], ['5'], [], [], ['10']]
|
158
|
+
).to eq [['1'], ['2'], [], [], ['5'], [method_result(:meth)], ['5'], [], [], ['10']]
|
132
159
|
end
|
133
160
|
|
134
161
|
it 'records return statements' do
|
135
|
-
expect(values_for("def meth \n return 1 \n end \n meth")).to eq [[], ['1'], [], ['1']]
|
162
|
+
expect(values_for("def meth \n return 1 \n end \n meth")).to eq [[], ['1'], [method_result(:meth)], ['1']]
|
136
163
|
expect(values_for("-> { \n return 1 \n }.call" )).to eq [[], ['1'], ['1']]
|
137
164
|
expect(values_for("-> { return 1 }.call" )).to eq [['1']]
|
138
165
|
|
@@ -149,7 +176,7 @@ describe SeeingIsBelieving do
|
|
149
176
|
end
|
150
177
|
|
151
178
|
it 'does not try to record the keyword redo' do
|
152
|
-
expect(values_for(<<-DOC)).to eq [[], ['0'], ['0...3'], ['1', '2', '3', '4'], ['false', 'true', 'false', 'false'], ['0...3'], [], ['0...3']]
|
179
|
+
expect(values_for(<<-DOC)).to eq [[], ['0'], ['0...3'], ['1', '2', '3', '4'], ['false', 'true', 'false', 'false'], ['0...3'], [method_result(:meth)], ['0...3']]
|
153
180
|
def meth
|
154
181
|
n = 0
|
155
182
|
for i in 0...3
|
@@ -162,7 +189,7 @@ describe SeeingIsBelieving do
|
|
162
189
|
end
|
163
190
|
|
164
191
|
it 'does not try to record the keyword retry' do
|
165
|
-
expect(values_for(<<-DOC)).to eq [[], [], [], [], ['nil']]
|
192
|
+
expect(values_for(<<-DOC)).to eq [[], [], [], [method_result(:meth)], ['nil']]
|
166
193
|
def meth
|
167
194
|
rescue
|
168
195
|
retry
|
@@ -228,7 +255,7 @@ describe SeeingIsBelieving do
|
|
228
255
|
end
|
229
256
|
|
230
257
|
it 'does not capture output from __END__ onward' do
|
231
|
-
expect(values_for("1+1\nDATA.read\n__END__\n....")).to eq [['2'], ['"....\n"']] # <-- should this actually write a newline on the end?
|
258
|
+
expect(values_for("1+1\nDATA.read\n__END__\n....")).to eq [['2'], ['"....\n"'], [], []] # <-- should this actually write a newline on the end?
|
232
259
|
end
|
233
260
|
|
234
261
|
it 'raises a SyntaxError when the whole program is invalid' do
|
@@ -250,7 +277,7 @@ describe SeeingIsBelieving do
|
|
250
277
|
it 'can deal with methods that are invoked entirely on the next line' do
|
251
278
|
expect(values_for("a = 1\n.even?\na")).to eq [['1'], ['false'], ['false']]
|
252
279
|
expect(values_for("a = 1.\neven?\na")).to eq [['1'], ['false'], ['false']]
|
253
|
-
expect(values_for("1\n.even?\n__END__")).to eq [['1'], ['false']]
|
280
|
+
expect(values_for("1\n.even?\n__END__")).to eq [['1'], ['false'], []] # TODO: would be nice if we could consolidate this shit so we could find out things like __END__ without repeatedly parsing, I'd prefer if this did not imply there were results on this line -.-
|
254
281
|
end
|
255
282
|
|
256
283
|
it 'does not record leading comments' do
|
@@ -278,7 +305,7 @@ describe SeeingIsBelieving do
|
|
278
305
|
|
279
306
|
it "doesn't fuck up when there are lines with magic comments in the middle of the app" do
|
280
307
|
expect(values_for '1+1
|
281
|
-
# encoding: wtf').to eq [['2']]
|
308
|
+
# encoding: wtf').to eq [['2'], []]
|
282
309
|
end
|
283
310
|
|
284
311
|
it "doesn't remove multiple leading comments" do
|
@@ -321,12 +348,10 @@ describe SeeingIsBelieving do
|
|
321
348
|
File.write 'omg-ruby', "#!/usr/bin/env ruby
|
322
349
|
$LOAD_PATH.unshift '#{File.expand_path '../../lib', __FILE__}'
|
323
350
|
|
324
|
-
require 'seeing_is_believing'
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
require 'json'
|
329
|
-
puts JSON.dump result.to_primitive
|
351
|
+
require 'seeing_is_believing/event_stream/producer'
|
352
|
+
sib = SeeingIsBelieving::EventStream::Producer.new($stdout)
|
353
|
+
sib.record_result(:inspect, 1, /omg/)
|
354
|
+
sib.finish!
|
330
355
|
"
|
331
356
|
File.chmod 0755, 'omg-ruby'
|
332
357
|
old_path = ENV['PATH']
|
@@ -339,21 +364,47 @@ describe SeeingIsBelieving do
|
|
339
364
|
end
|
340
365
|
end
|
341
366
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
367
|
+
describe 'BEGIN and END' do
|
368
|
+
it 'Executes in the appropriate order' do
|
369
|
+
pending 'not implemented'
|
370
|
+
expect(invoke <<-CODE).stdout.to eq "1\n2\n3\n4\n5\n6\n7\n8\n9\n"
|
371
|
+
p 3
|
372
|
+
END { p 8 }
|
373
|
+
p 4
|
374
|
+
BEGIN { p 1 }
|
375
|
+
p 5
|
376
|
+
END { p 9 }
|
377
|
+
p 6
|
378
|
+
BEGIN { p 2 }
|
379
|
+
p 7
|
380
|
+
CODE
|
381
|
+
end
|
382
|
+
|
383
|
+
it 'Maintains correct line numbers' do
|
384
|
+
pending 'not implemented'
|
385
|
+
expected_values = [
|
386
|
+
['1'],
|
387
|
+
[],
|
388
|
+
['3'],
|
389
|
+
[],
|
390
|
+
['5'],
|
391
|
+
[],
|
392
|
+
['7'],
|
393
|
+
[],
|
394
|
+
['9'],
|
395
|
+
]
|
396
|
+
expect(values_for <<-CODE).to eq expected_values
|
397
|
+
__LINE__
|
398
|
+
BEGIN {
|
399
|
+
__LINE__
|
400
|
+
}
|
401
|
+
__LINE__
|
402
|
+
END {
|
403
|
+
__LINE__
|
404
|
+
}
|
405
|
+
__LINE__
|
406
|
+
CODE
|
407
|
+
end
|
357
408
|
end
|
358
409
|
|
359
410
|
# For more info about this one
|
@@ -367,12 +418,19 @@ describe SeeingIsBelieving do
|
|
367
418
|
result = invoke(%[def self.inspect
|
368
419
|
self
|
369
420
|
end
|
370
|
-
self], filename: 'blowsup.rb')
|
421
|
+
self], filename: 'blowsup.rb') # TODO This actually writes the file into the root of SiB
|
371
422
|
expect(result).to have_exception
|
372
423
|
expect(result.exception.class_name).to eq 'SystemStackError'
|
373
424
|
expect(result.exception.backtrace.grep(/blowsup.rb/)).to_not be_empty # backtrace includes a line that we can show
|
374
425
|
expect(result.exception.message).to match /recursive/i
|
375
|
-
|
426
|
+
end
|
427
|
+
|
428
|
+
it 'makes the SeeingIsBelieving::VERSION available to the program' do
|
429
|
+
expect(values_for "SeeingIsBelieving::VERSION").to eq [[SeeingIsBelieving::VERSION.inspect]]
|
430
|
+
end
|
431
|
+
|
432
|
+
it 'does not change the number of lines in the file' do
|
433
|
+
expect(values_for "File.read(__FILE__).lines.count").to eq [['1']]
|
376
434
|
end
|
377
435
|
|
378
436
|
context 'when given a debugger' do
|
@@ -392,8 +450,47 @@ describe SeeingIsBelieving do
|
|
392
450
|
it 'prints the result' do
|
393
451
|
call
|
394
452
|
expect(stream.string).to include "RESULT:"
|
395
|
-
expect(stream.string).to include '
|
453
|
+
expect(stream.string).to include 'SIB::Result'
|
454
|
+
expect(stream.string).to include '@results={'
|
396
455
|
end
|
397
456
|
# should ProgramRewriter have some debug options?
|
398
457
|
end
|
458
|
+
|
459
|
+
context 'when :evaluator option is set' do
|
460
|
+
require 'webmock'
|
461
|
+
WebMock.disable_net_connect!
|
462
|
+
|
463
|
+
include WebMock::API
|
464
|
+
before { WebMock.reset! }
|
465
|
+
|
466
|
+
it 'can use EvaluateByMovingFiles' do
|
467
|
+
# shows we're not using the only other option (EvaluateWithEvalIn)
|
468
|
+
expect(values_for "`echo 1`", evaluator: SeeingIsBelieving::EvaluateByMovingFiles).to eq [['"1\n"']]
|
469
|
+
end
|
470
|
+
|
471
|
+
it 'can use EvaluateWithEvalIn' do
|
472
|
+
require 'seeing_is_believing/event_stream/producer'
|
473
|
+
redirect_url = 'https://example.com/whatever'
|
474
|
+
api_redirect_url = redirect_url + '.json'
|
475
|
+
|
476
|
+
stream = StringIO.new
|
477
|
+
producer = SeeingIsBelieving::EventStream::Producer.new(stream)
|
478
|
+
producer.record_result :inspect, 1, "a"
|
479
|
+
producer.record_result :inspect, 1, "b"
|
480
|
+
producer.record_result :inspect, 2, "c"
|
481
|
+
producer.finish!
|
482
|
+
|
483
|
+
response = { 'lang' => 'whatever',
|
484
|
+
'lang_friendly' => 'whatever',
|
485
|
+
'code' => 'whatever',
|
486
|
+
'output' => stream.string,
|
487
|
+
'status' => 'OK (0.012 sec real, 0.013 sec wall, 7 MB, 22 syscalls)'}
|
488
|
+
|
489
|
+
stub_request(:post, 'https://eval.in/').to_return(status: 302, headers: {'Location' => redirect_url})
|
490
|
+
stub_request(:get, api_redirect_url).to_return(status: 200, body: JSON.dump(response))
|
491
|
+
|
492
|
+
values = values_for "whatever", evaluator: SeeingIsBelieving::EvaluateWithEvalIn
|
493
|
+
expect(values).to eq [['"a"', '"b"'], ['"c"']]
|
494
|
+
end
|
495
|
+
end
|
399
496
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
RSpec.configure do |c|
|
2
|
+
c.disable_monkey_patching!
|
3
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'seeing_is_believing/wrap_expressions'
|
3
3
|
|
4
|
-
describe SeeingIsBelieving::WrapExpressions do
|
4
|
+
RSpec.describe SeeingIsBelieving::WrapExpressions do
|
5
5
|
def wrap(code)
|
6
6
|
described_class.call code,
|
7
7
|
before_each: -> * { '<' },
|
@@ -17,23 +17,36 @@ describe SeeingIsBelieving::WrapExpressions do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
describe 'wrapping the body' do
|
20
|
-
let(:options) { { before_all: "[",
|
21
|
-
after_all: "]",
|
22
|
-
before_each: -> * { '<' },
|
23
|
-
after_each: -> * { '>' } } }
|
20
|
+
let(:options) { { before_all: -> { "[".freeze },
|
21
|
+
after_all: -> { "]".freeze },
|
22
|
+
before_each: -> * { '<'.freeze },
|
23
|
+
after_each: -> * { '>'.freeze } } }
|
24
24
|
|
25
25
|
it 'wraps the entire body, ignoring leading comments and the data segment' do
|
26
26
|
expect(described_class.call("#comment\nA\n__END__\n1", options)).to eq "#comment\n[<A>]\n__END__\n1"
|
27
27
|
end
|
28
28
|
|
29
|
-
it '
|
30
|
-
expect(described_class.call(
|
29
|
+
it 'comes in on blank lines' do
|
30
|
+
expect(described_class.call('', options)).to eq '[]'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'comes in first when there are only comments' do
|
34
|
+
expect(described_class.call("# abc", options)).to eq "[]# abc"
|
31
35
|
end
|
32
36
|
|
33
37
|
it 'comes in before trailing comments' do
|
34
38
|
expect(described_class.call("1# abc", options)).to eq "[<1>]# abc"
|
35
39
|
end
|
36
40
|
|
41
|
+
# this changes the number of lines, annoyingly, though it shouldn't mess anything up,
|
42
|
+
# unless you were trying to reopen the file to read it, in which case, *surprise* the whole thing's been rewritten
|
43
|
+
it 'injects a newline if there is a data segment and the after block doesn\'t end in a newline' do
|
44
|
+
expect(described_class.call("__END__", options)).to eq "[]\n__END__"
|
45
|
+
expect(described_class.call("\n__END__", options)).to eq "[]\n__END__"
|
46
|
+
expect(described_class.call("\n\n__END__", options)).to eq "[]\n\n__END__"
|
47
|
+
expect(described_class.call("__END__!", options)).to eq "[<__END__!>]"
|
48
|
+
end
|
49
|
+
|
37
50
|
it 'wraps bodies that are wrapped in parentheses' do
|
38
51
|
expect(wrap('(1)')).to eq '<(1)>'
|
39
52
|
expect(wrap("(\n<<doc\ndoc\n)")).to eq "<(\n<<<doc>\ndoc\n)>"
|
@@ -71,9 +84,9 @@ describe SeeingIsBelieving::WrapExpressions do
|
|
71
84
|
"end",
|
72
85
|
options)
|
73
86
|
).to eq "[<a>\n"\
|
74
|
-
"def b\n"\
|
87
|
+
"<def b\n"\
|
75
88
|
" <c = 1>\n"\
|
76
|
-
"end]"
|
89
|
+
"end>]"
|
77
90
|
end
|
78
91
|
end
|
79
92
|
|
@@ -185,8 +198,8 @@ describe SeeingIsBelieving::WrapExpressions do
|
|
185
198
|
end
|
186
199
|
|
187
200
|
it 'does not wrap multiple expressions when they constitute a void value' do
|
188
|
-
expect(wrap("def a\n1\nreturn 2\nend")).to eq "def a\n<1>\nreturn <2>\nend"
|
189
|
-
expect(wrap("def a\nreturn 1\n2\nend")).to eq "def a\nreturn <1>\n<2>\nend"
|
201
|
+
expect(wrap("def a\n1\nreturn 2\nend")).to eq "<def a\n<1>\nreturn <2>\nend>"
|
202
|
+
expect(wrap("def a\nreturn 1\n2\nend")).to eq "<def a\nreturn <1>\n<2>\nend>"
|
190
203
|
end
|
191
204
|
|
192
205
|
it 'wraps nested expressions' do
|
@@ -519,19 +532,19 @@ describe SeeingIsBelieving::WrapExpressions do
|
|
519
532
|
end
|
520
533
|
|
521
534
|
it 'does not wrap if the last value in any portion is a void value expression' do
|
522
|
-
expect(wrap("def a\nif true\nreturn 1\nend\nend")).to eq "def a\nif <true>\nreturn <1>\nend\nend"
|
523
|
-
expect(wrap("def a\nif true\n1\nelse\nreturn 2\nend\nend")).to eq "def a\nif <true>\n<1>\nelse\nreturn <2>\nend\nend"
|
524
|
-
expect(wrap("def a\nif true\n1\nelsif true\n2\nelse\nreturn 3\nend\nend")).to eq "def a\nif <true>\n<1>\nelsif <true>\n<2>\nelse\nreturn <3>\nend\nend"
|
525
|
-
expect(wrap("def a\nif true\nif true\nreturn 1\nend\nend\nend")).to eq "def a\nif <true>\nif <true>\nreturn <1>\nend\nend\nend"
|
526
|
-
expect(wrap("def a\nunless true\nreturn 1\nend\nend")).to eq "def a\nunless <true>\nreturn <1>\nend\nend"
|
527
|
-
expect(wrap("def a\nunless true\n1\nelse\nreturn 2\nend\nend")).to eq "def a\nunless <true>\n<1>\nelse\nreturn <2>\nend\nend"
|
528
|
-
expect(wrap("def a\ntrue ?\n(return 1) :\n2\nend")).to eq "def a\n<true> ?\n(return <1>) :\n<2>\nend"
|
529
|
-
expect(wrap("def a\ntrue ?\n1 :\n(return 2)\nend")).to eq "def a\n<true> ?\n<1> :\n(return <2>)\nend"
|
535
|
+
expect(wrap("def a\nif true\nreturn 1\nend\nend")).to eq "<def a\nif <true>\nreturn <1>\nend\nend>"
|
536
|
+
expect(wrap("def a\nif true\n1\nelse\nreturn 2\nend\nend")).to eq "<def a\nif <true>\n<1>\nelse\nreturn <2>\nend\nend>"
|
537
|
+
expect(wrap("def a\nif true\n1\nelsif true\n2\nelse\nreturn 3\nend\nend")).to eq "<def a\nif <true>\n<1>\nelsif <true>\n<2>\nelse\nreturn <3>\nend\nend>"
|
538
|
+
expect(wrap("def a\nif true\nif true\nreturn 1\nend\nend\nend")).to eq "<def a\nif <true>\nif <true>\nreturn <1>\nend\nend\nend>"
|
539
|
+
expect(wrap("def a\nunless true\nreturn 1\nend\nend")).to eq "<def a\nunless <true>\nreturn <1>\nend\nend>"
|
540
|
+
expect(wrap("def a\nunless true\n1\nelse\nreturn 2\nend\nend")).to eq "<def a\nunless <true>\n<1>\nelse\nreturn <2>\nend\nend>"
|
541
|
+
expect(wrap("def a\ntrue ?\n(return 1) :\n2\nend")).to eq "<def a\n<true> ?\n(return <1>) :\n<2>\nend>"
|
542
|
+
expect(wrap("def a\ntrue ?\n1 :\n(return 2)\nend")).to eq "<def a\n<true> ?\n<1> :\n(return <2>)\nend>"
|
530
543
|
end
|
531
544
|
|
532
545
|
# not sure if I actually want this, or if it's just easier b/c it falls out of the current implementation
|
533
546
|
it 'wraps the conditional from an inline if, when it cannot wrap the entire if' do
|
534
|
-
expect(wrap("def a\nreturn if 1\nend")).to eq "def a\nreturn if <1>\nend"
|
547
|
+
expect(wrap("def a\nreturn if 1\nend")).to eq "<def a\nreturn if <1>\nend>"
|
535
548
|
end
|
536
549
|
|
537
550
|
it 'does not wrap &&, and, ||, or, not' do
|
@@ -781,37 +794,37 @@ describe SeeingIsBelieving::WrapExpressions do
|
|
781
794
|
end
|
782
795
|
|
783
796
|
describe 'method definitions' do
|
784
|
-
it 'does
|
785
|
-
expect(wrap("def a(b,c=1,*d,&e)\nend")).to eq "def a(b,c=1,*d,&e)\nend"
|
797
|
+
it 'does wraps the definition, but not the arguments' do
|
798
|
+
expect(wrap("def a(b,c=1,*d,&e)\nend")).to eq "<def a(b,c=1,*d,&e)\nend>"
|
786
799
|
end
|
787
800
|
|
788
801
|
it 'wraps the body' do
|
789
|
-
expect(wrap("def a\n1\nend")).to eq "def a\n<1>\nend"
|
790
|
-
expect(wrap("def a()\n1\nend")).to eq "def a()\n<1>\nend"
|
802
|
+
expect(wrap("def a\n1\nend")).to eq "<def a\n<1>\nend>"
|
803
|
+
expect(wrap("def a()\n1\nend")).to eq "<def a()\n<1>\nend>"
|
791
804
|
end
|
792
805
|
|
793
|
-
it '
|
794
|
-
expect(wrap("def a.b\n1\nend")).to eq "def a.b\n<1>\nend"
|
795
|
-
expect(wrap("def a.b()\n1\nend")).to eq "def a.b()\n<1>\nend"
|
806
|
+
it 'wrap singleton method definitions' do
|
807
|
+
expect(wrap("def a.b\n1\nend")).to eq "<def a.b\n<1>\nend>"
|
808
|
+
# expect(wrap("def a.b()\n1\nend")).to eq "<def a.b()\n<1>\nend>"
|
796
809
|
end
|
797
810
|
|
798
811
|
it 'wraps calls to yield' do
|
799
|
-
expect(wrap("def a\nyield\nend")).to eq "def a\n<yield>\nend"
|
812
|
+
expect(wrap("def a\nyield\nend")).to eq "<def a\n<yield>\nend>"
|
800
813
|
end
|
801
814
|
|
802
815
|
it 'wraps calls to super' do
|
803
|
-
expect(wrap("def a\nsuper\nend")).to eq "def a\n<super>\nend"
|
804
|
-
expect(wrap("def a\nsuper 1\nend")).to eq "def a\n<super 1>\nend"
|
816
|
+
expect(wrap("def a\nsuper\nend")).to eq "<def a\n<super>\nend>"
|
817
|
+
expect(wrap("def a\nsuper 1\nend")).to eq "<def a\n<super 1>\nend>"
|
805
818
|
end
|
806
819
|
|
807
820
|
it 'wraps the bodies of returns' do
|
808
|
-
expect(wrap("def a\nreturn 1\nend")).to eq "def a\nreturn <1>\nend"
|
821
|
+
expect(wrap("def a\nreturn 1\nend")).to eq "<def a\nreturn <1>\nend>"
|
809
822
|
end
|
810
823
|
|
811
824
|
it 'wraps the rescue and ensure portion' do
|
812
|
-
expect(wrap("def a\n1\nrescue\n2\nend")).to eq "def a\n<1>\nrescue\n<2>\nend"
|
813
|
-
expect(wrap("def a\n1\nrescue\n2\nensure\n3\nend")).to eq "def a\n<1>\nrescue\n<2>\nensure\n<3>\nend"
|
814
|
-
expect(wrap("def a\n1\nensure\n2\nend")).to eq "def a\n<1>\nensure\n<2>\nend"
|
825
|
+
expect(wrap("def a\n1\nrescue\n2\nend")).to eq "<def a\n<1>\nrescue\n<2>\nend>"
|
826
|
+
expect(wrap("def a\n1\nrescue\n2\nensure\n3\nend")).to eq "<def a\n<1>\nrescue\n<2>\nensure\n<3>\nend>"
|
827
|
+
expect(wrap("def a\n1\nensure\n2\nend")).to eq "<def a\n<1>\nensure\n<2>\nend>"
|
815
828
|
end
|
816
829
|
end
|
817
830
|
|
@@ -836,7 +849,7 @@ describe SeeingIsBelieving::WrapExpressions do
|
|
836
849
|
describe 'BEGIN/END' do
|
837
850
|
# not implemented b/c we cannot wrap around these either.
|
838
851
|
# So what does it mean to wrap around?
|
839
|
-
#
|
852
|
+
# maybe this?
|
840
853
|
# 1
|
841
854
|
# BEGIN {}
|
842
855
|
# 2
|