-
Notifications
You must be signed in to change notification settings - Fork 54
/
xmpfilter-style.feature
451 lines (400 loc) · 11 KB
/
xmpfilter-style.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
@xmpfilter
Feature: Xmpfilter style
Support the same (or highly similar) interface as xmpfilter,
so that people who use that lib can easily transition to SiB.
Scenario: --xmpfilter-style Generic updating of marked lines
Given the file "magic_comments.rb":
"""
1+1# =>
2+2 # => 10
"a
b" # =>
/a
b/ # =>
1
"omg"
# =>
"omg2"
# => "not omg2"
3+3#=>
"""
When I run "seeing_is_believing --xmpfilter-style magic_comments.rb"
Then stderr is empty
And the exit status is 0
And stdout is:
"""
1+1# => 2
2+2 # => 4
"a
b" # => "a\n b"
/a
b/ # => /a\n b/
1
"omg"
# => "omg"
"omg2"
# => "omg2"
3+3# => 6
"""
Scenario: --xmpfilter-style uses pp to inspect annotations whose value comes from the previous line (#44)
Given the file "xmpfilter-prev-line1.rb":
"""
{ foo: 42,
bar: {
baz: 1,
buz: 2,
fuz: 3,
},
wibble: {
magic_word: "xyzzy",
}
} # =>
# =>
"""
When I run "seeing_is_believing --xmpfilter-style xmpfilter-prev-line1.rb"
Then stdout is:
"""
{ foo: 42,
bar: {
baz: 1,
buz: 2,
fuz: 3,
},
wibble: {
magic_word: "xyzzy",
}
} # => {:foo=>42, :bar=>{:baz=>1, :buz=>2, :fuz=>3}, :wibble=>{:magic_word=>"xyzzy"}}
# => {:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}}
"""
Scenario: --xmpfilter-style overrides previous multiline results
Given the file "xmpfilter-prev-line2.rb":
"""
{foo: 42, bar: {baz: 1, buz: 2, fuz: 3}, wibble: {magic_word: "xyzzy"}}
# =>
"""
When I run "seeing_is_believing --xmpfilter-style xmpfilter-prev-line2.rb | seeing_is_believing --xmpfilter-style"
Then stdout is:
"""
{foo: 42, bar: {baz: 1, buz: 2, fuz: 3}, wibble: {magic_word: "xyzzy"}}
# => {:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}}
"""
Scenario: --xmpfilter-style respects the line formatting (but not currently alignment strategies, it just preserves submitted alignment)
Given the file "xmpfilter_line_lengths.rb":
"""
'1' * 30 # =>
# =>
"""
When I run "seeing_is_believing --xmpfilter-style --line-length 19 xmpfilter_line_lengths.rb"
Then stdout is:
"""
'1' * 30 # => "1...
# => "1111111111...
"""
Scenario: Errors on annotated lines
Given the file "xmpfilter_error_on_annotated_line.rb":
"""
raise "ZOMG\n!!!!" # =>
"""
When I run "seeing_is_believing --xmpfilter-style xmpfilter_error_on_annotated_line.rb"
Then stderr is empty
And the exit status is 1
Then stdout is:
"""
raise "ZOMG\n!!!!" # => RuntimeError: ZOMG\n!!!!
# ~> RuntimeError
# ~> ZOMG
# ~> !!!!
# ~>
# ~> xmpfilter_error_on_annotated_line.rb:1:in `<main>'
"""
Scenario: Errors on unannotated lines
Given the file "xmpfilter_error_on_unannotated_line.rb":
"""
raise "ZOMG\n!!!!"
"""
When I run "seeing_is_believing --xmpfilter-style xmpfilter_error_on_unannotated_line.rb"
Then stderr is empty
And the exit status is 1
Then stdout is:
"""
raise "ZOMG\n!!!!" # ~> RuntimeError: ZOMG\n!!!!
# ~> RuntimeError
# ~> ZOMG
# ~> !!!!
# ~>
# ~> xmpfilter_error_on_unannotated_line.rb:1:in `<main>'
"""
Scenario: Cleaning previous output does not clean the xmpfilter annotations
Given the file "xmpfilter_cleaning.rb":
"""
# commented out # => previous annotation
1 # => "1...
# => "1111111111...
# "1111111111...
# normal comment
{foo: 42, bar: {baz: 1, buz: 2, fuz: 3}, wibble: {magic_word: "xyzzy"}}
# => {:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}}
"""
When I run "seeing_is_believing --xmpfilter-style --clean xmpfilter_cleaning.rb"
Then stdout is:
"""
# commented out # => previous annotation
1 # =>
# =>
# normal comment
{foo: 42, bar: {baz: 1, buz: 2, fuz: 3}, wibble: {magic_word: "xyzzy"}}
# =>
"""
# Not totally in love with this, but it'll do unless I can think of something better.
Scenario: Error raised on an annotated line preserves the annotation
Given the file "error_on_annotated_line.a.rb":
"""
"a"+1 # =>
# =>
"""
When I run "seeing_is_believing --xmpfilter-style error_on_annotated_line.a.rb"
Then stdout includes:
"""
"a"+1 # => TypeError:
"""
And stdout includes:
"""
# =>
# ~> TypeError
"""
Given the file "error_on_annotated_line.b.rb":
"""
"a"+"1" # => TypeError: no implicit conversion of Fixnum into String
# =>
# ~> TypeError
# ~> no implicit conversion of Fixnum into String
"""
When I run "seeing_is_believing --xmpfilter-style error_on_annotated_line.b.rb"
Then stdout is:
"""
"a"+"1" # => "a1"
# => "a1"
"""
# maybe can't fix this as it depends on the implementation of PP.pp
@not-implemented
Scenario: It can record values even when method is overridden
Given the file "pretty_inspect_with_method_overridden.rb":
"""
def method()end; self # =>
# =>
"""
When I run "seeing_is_believing --xmpfilter-style pretty_inspect_with_method_overridden.rb"
Then stdout is:
"""
def method()end; self # => main
# => main
"""
# Choosing this output style b/c it's what xmpfilter chooses,
# and it works conveniently with what's already in place.
#
# It looks better with the comma on the preceding line, but harder to identify the individual results.
#
# It looks better with an empty line between the results, but if the user strips trailing whitespace inbetween runs,
# it will confuse the annotations for normal comments.
#
# Might be cool to have it do a value comment before each result, instead of a comma.
# But at present, it doesn't wipe out "useless" value comments,
# e.g. cleaning this would leave three value markers after the hash.
Scenario: Multiline output that is repeatedly invoked
Given the file "mutltiline_output_repeatedly_invoked.rb":
"""
3.times do
{foo: 42, bar: {baz: 1, buz: 2, fuz: 3}, wibble: {magic_word: "xyzzy"}}
# =>
end
"""
When I run "seeing_is_believing -x mutltiline_output_repeatedly_invoked.rb"
Then stdout is:
"""
3.times do
{foo: 42, bar: {baz: 1, buz: 2, fuz: 3}, wibble: {magic_word: "xyzzy"}}
# => {:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}}
# ,{:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}}
# ,{:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}}
end
"""
When I run "seeing_is_believing -x mutltiline_output_repeatedly_invoked.rb | seeing_is_believing -x"
Then stdout is:
"""
3.times do
{foo: 42, bar: {baz: 1, buz: 2, fuz: 3}, wibble: {magic_word: "xyzzy"}}
# => {:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}}
# ,{:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}}
# ,{:foo=>42,
# :bar=>{:baz=>1, :buz=>2, :fuz=>3},
# :wibble=>{:magic_word=>"xyzzy"}}
end
"""
Scenario: Multiline values where the first line is indented more than the successive lines use a nonbreaking space
Given the file "inspect_tree.rb":
"""
bst = Object.new
def bst.inspect
" 4\n"\
" 2 6\n"\
"1 3 5 7\n"
end
bst
# =>
"""
When I run "seeing_is_believing --xmpfilter-style inspect_tree.rb"
# NOTE: The first space after the => is a nonbreaking space
Then stdout is:
"""
bst = Object.new
def bst.inspect
" 4\n"\
" 2 6\n"\
"1 3 5 7\n"
end
bst
# => 4
# 2 6
# 1 3 5 7
"""
Scenario: Leading whitespace on nextline, but not multiline uses normal spaces
Given the file "nextline_with_leading_whitespace_but_not_multiline.rb":
"""
o = Object.new
def o.inspect; " o" end
o
# =>
"""
When I run "seeing_is_believing --xmpfilter-style nextline_with_leading_whitespace_but_not_multiline.rb"
Then stdout is:
"""
o = Object.new
def o.inspect; " o" end
o
# => o
"""
Scenario: When there are no results for the previous line it looks further back (#77)
Given the file "heredocs_and_blank_lines.rb":
"""
# =>
<<DOC
1
DOC
# =>
2
# =>
if true
3
# =>
else
4
# =>
end
"""
When I run "seeing_is_believing --xmpfilter-style heredocs_and_blank_lines.rb"
Then stdout is:
"""
# =>
<<DOC
1
DOC
# => "1\n"
2
# => 2
if true
3
# => 3
else
4
# =>
end
"""
Scenario: Xmpfilter uses the same comment formatting as normal
Given the file "xmpfilter_result_lengths.rb":
"""
$stdout.puts "a"*100
$stderr.puts "a"*100
"a" # =>
"aa" # =>
"aaa" # =>
"aaaa" # =>
{foo: 42, bar: {baz: 1, buz: 2, fuz: 3}, wibble: {magic_word: "xyzzy"}}
# =>
raise "a"*100
"""
When I run "seeing_is_believing -x --result-length 10 xmpfilter_result_lengths.rb"
Then stderr is empty
And stdout is:
"""
$stdout.puts "a"*100
$stderr.puts "a"*100
"a" # => "a"
"aa" # => "aa"
"aaa" # => "aaa"
"aaaa" # => "a...
{foo: 42, bar: {baz: 1, buz: 2, fuz: 3}, wibble: {magic_word: "xyzzy"}}
# => {:...
# :...
# :...
raise "a"*100 # ~> Ru...
# >> aa...
# !> aa...
# ~> Ru...
# ~> aa...
# ~>
# ~> xm...
"""
Scenario: --interline-align and --no-interline-align determine whether adjacent lines with the same number of results get lined up, it defaults to --align
Given the file "xmpfilter_interline_alignment.rb":
"""
3.times do |num|
num # =>
.to_s # =>
end
"""
When I run "seeing_is_believing -x xmpfilter_interline_alignment.rb"
Then stderr is empty
And the exit status is 0
And stdout is:
"""
3.times do |num|
num # => 0, 1, 2
.to_s # => "0", "1", "2"
end
"""
When I run "seeing_is_believing -x --interline-align xmpfilter_interline_alignment.rb"
Then stderr is empty
And the exit status is 0
And stdout is:
"""
3.times do |num|
num # => 0, 1, 2
.to_s # => "0", "1", "2"
end
"""
When I run "seeing_is_believing -x --no-interline-align xmpfilter_interline_alignment.rb"
Then stderr is empty
And the exit status is 0
And stdout is:
"""
3.times do |num|
num # => 0, 1, 2
.to_s # => "0", "1", "2"
end
"""