seeing_is_believing 2.2.0 → 3.0.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'seeing_is_believing/binary/comment_lines'
|
3
3
|
|
4
|
-
describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each commentable line and the line number, and adds the returned text (whitespace+comment) to the end' do
|
4
|
+
RSpec.describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each commentable line and the line number, and adds the returned text (whitespace+comment) to the end' do
|
5
5
|
def call(code, &block)
|
6
6
|
described_class.call code, &block
|
7
7
|
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
require 'seeing_is_believing/binary/parse_args'
|
2
|
+
require 'seeing_is_believing/binary/interpret_flags'
|
3
|
+
|
4
|
+
class SeeingIsBelieving
|
5
|
+
module Binary
|
6
|
+
RSpec.describe 'SeeingIsBelieving::Binary::InterpretFlags' do
|
7
|
+
let(:stdin_data) { 'stdin data' }
|
8
|
+
let(:stdin) { double 'stdin', read: stdin_data }
|
9
|
+
let(:stdout) { double 'stdout' }
|
10
|
+
|
11
|
+
let(:file_body) { 'good file body' }
|
12
|
+
let(:nonexisting_filename) { 'badfilename' }
|
13
|
+
let(:existing_filename) { 'goodfilename' }
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow(File).to receive(:exist?).and_return(false)
|
17
|
+
allow(File).to receive(:exist?).with(existing_filename).and_return(true)
|
18
|
+
allow(File).to receive(:exist?).with(nonexisting_filename).and_return(false)
|
19
|
+
allow(File).to receive(:read).with(existing_filename).and_return(file_body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(overrides={})
|
23
|
+
flags = ParseArgs.call []
|
24
|
+
InterpretFlags.new(flags.merge(overrides), stdin, stdout)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'annotator' do
|
28
|
+
it 'annotates every line by default' do
|
29
|
+
expect(call.annotator).to eq AnnotateEveryLine
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'annotates xmpfilter-style if xmpfilter_style was set' do
|
33
|
+
expect(call.annotator).to eq AnnotateEveryLine
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'help' do
|
38
|
+
let(:overrides) { {short_help_screen: 'short help screen',
|
39
|
+
long_help_screen: 'long help screen'} }
|
40
|
+
|
41
|
+
context 'when the value is not set' do
|
42
|
+
before { overrides[:help] = nil }
|
43
|
+
|
44
|
+
it 'does not set print_help?' do
|
45
|
+
expect(call(overrides).print_help?).to eq false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when the value is "help"' do
|
50
|
+
before { overrides[:help] = 'help' }
|
51
|
+
|
52
|
+
it 'sets print_help?' do
|
53
|
+
expect(call(overrides).print_help?).to eq true
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'sets the help_screen to the short one' do
|
57
|
+
expect(call(overrides).help_screen).to eq 'short help screen'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when the value is "help+"' do
|
62
|
+
before { overrides[:help] = 'help+' }
|
63
|
+
|
64
|
+
it 'sets print_help?' do
|
65
|
+
expect(call(overrides).print_help?).to eq true
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'sets the help screen to the long one' do
|
69
|
+
expect(call(overrides).help_screen).to eq 'long help screen'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'debug' do
|
75
|
+
it 'sts a null debugger when false' do
|
76
|
+
expect(call(debug: false).debugger).to_not be_enabled
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'sets a debugger to the output stream when true' do
|
80
|
+
expect(call(debug: true).debugger).to be_enabled
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'markers' do
|
85
|
+
# TODO: fix this later to use objs
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'timeout' do
|
89
|
+
it 'sets timeout to the value' do
|
90
|
+
expect(call(timeout: 0).timeout).to eq 0 # TODO: Should the interpretation of 0 move up from flags to here?
|
91
|
+
expect(call(timeout: 1).timeout).to eq 1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'shebang' do
|
96
|
+
it 'sets shebang to the value' do
|
97
|
+
expect(call(shebang: 'whatevz').shebang).to eq 'whatevz'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'filename' do
|
102
|
+
it 'sets this as the filename' do
|
103
|
+
expect(call(filename: 'somefilename').filename).to eq 'somefilename'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'filenames' do
|
108
|
+
it 'sets an error if more than one filename was provided' do
|
109
|
+
expect(call(filenames: []).errors.join).to_not match /filename/
|
110
|
+
expect(call(filenames: ['a']).errors.join).to_not match /filename/
|
111
|
+
expect(call(filenames: ['a', 'b']).errors.join).to match /filename/
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'sets an error if there is a filename and the program was also passed on stdin' do
|
115
|
+
matcher = /also specified the filename/
|
116
|
+
expect(call(filename: 'f', program_from_args: 'prog').errors.join).to match matcher
|
117
|
+
expect(call(filename: nil, program_from_args: 'prog').errors.join).to_not match matcher
|
118
|
+
expect(call(filename: 'f', program_from_args: nil ).errors.join).to_not match matcher
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'predicates' do
|
123
|
+
it 'sets print_version? when version is true' do
|
124
|
+
expect(call(version: false).print_version?).to eq false
|
125
|
+
expect(call(version: true).print_version?).to eq true
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'sets inherit_exit_status when inherit_exit_status is true' do
|
129
|
+
expect(call(inherit_exit_status: false).inherit_exit_status?).to eq false
|
130
|
+
expect(call(inherit_exit_status: true).inherit_exit_status?).to eq true
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'sets result_as_json when result_as_json is true' do
|
134
|
+
expect(call(result_as_json: false).result_as_json?).to eq false
|
135
|
+
expect(call(result_as_json: true).result_as_json?).to eq true
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'sets print_help when help has a value' do
|
139
|
+
expect(call(help: nil).print_help?).to eq false
|
140
|
+
expect(call(help: 'help').print_help?).to eq true
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'sets print_cleaned when clean is set' do
|
144
|
+
expect(call(clean: false).print_cleaned?).to eq false
|
145
|
+
expect(call(clean: true).print_cleaned?).to eq true
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'sets provided_filename_dne when there is a filename and that file does not exist' do
|
149
|
+
expect(call(filename: nonexisting_filename).provided_filename_dne?).to eq true
|
150
|
+
expect(call(filename: existing_filename).provided_filename_dne?).to eq false
|
151
|
+
expect(call(filename: nil).provided_filename_dne?).to eq false
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'sets file_is_on_stdin when there is no filename and the program is not provided in the args' do
|
155
|
+
expect(call(filename: nil, program_from_args: nil).file_is_on_stdin?).to eq true
|
156
|
+
expect(call(filename: 'f', program_from_args: nil).file_is_on_stdin?).to eq false
|
157
|
+
expect(call(filename: nil, program_from_args: 'p').file_is_on_stdin?).to eq false
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'body' do
|
162
|
+
it 'is an empty string if we\'re going to print the version or help instead of the program' do
|
163
|
+
expect(call(version: true).body).to eq ''
|
164
|
+
expect(call(help: true).body).to eq ''
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'is the program_from_args if this is provided' do
|
168
|
+
expect(call(program_from_args: 'prog').body).to eq 'prog'
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'is stdin if there is no file and no program_from_args' do
|
172
|
+
expect(call(filename: nil, program_from_args: nil).body).to eq stdin_data
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'is the file body if the filename is provded and exists' do
|
176
|
+
expect(call(filename: existing_filename).body).to eq file_body
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'is an empty string if the provided filename dne' do
|
180
|
+
expect(call(filename: nonexisting_filename).body).to eq ""
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'prepared_body' do
|
185
|
+
it 'is the body after being run throught he annotator\'s prepare method' do
|
186
|
+
expect(call(program_from_args: '1+1 # => ').prepared_body).to eq '1+1'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'lib_options' do
|
191
|
+
def call(overrides={})
|
192
|
+
super(overrides).lib_options
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'returns a hash to be passed to the evaluator' do
|
196
|
+
expect(call).to be_a_kind_of Hash
|
197
|
+
end
|
198
|
+
|
199
|
+
specify 'evaluate_with is EvaluateByMovingFiles by default' do
|
200
|
+
expect(call[:evaluate_with]).to eq EvaluateByMovingFiles
|
201
|
+
end
|
202
|
+
|
203
|
+
specify 'evaluate_with is EvaluateWithEvalIn if safe is set' do
|
204
|
+
expect(call(safe: true)[:evaluate_with]).to eq EvaluateWithEvalIn
|
205
|
+
end
|
206
|
+
|
207
|
+
specify 'filename is the as option or the provided filename' do
|
208
|
+
expect(call(filename: 'from_fn')[:filename]).to eq 'from_fn'
|
209
|
+
expect(call(as: 'from_as')[:filename]).to eq 'from_as'
|
210
|
+
expect(call(as: 'from_as', filename: 'from_fn')[:filename]).to eq 'from_as'
|
211
|
+
end
|
212
|
+
|
213
|
+
specify 'ruby_executable is the shebang' do
|
214
|
+
expect(call(shebang: 'shebangprog')[:ruby_executable]).to eq 'shebangprog'
|
215
|
+
end
|
216
|
+
|
217
|
+
specify 'stdin is empty when the program is on stdin, and is stdin otherwise' do
|
218
|
+
# NOTE: the lib will normalize this into a stream
|
219
|
+
expect(call(filename: nil, program_from_args: nil)[:stdin]).to eq ''
|
220
|
+
expect(call(filename: nil, program_from_args: '1')[:stdin]).to eq stdin
|
221
|
+
end
|
222
|
+
|
223
|
+
# TODO: Add cuke where required file prints
|
224
|
+
specify 'require includes the matrix first, plus any other required files' do
|
225
|
+
expect(call(require: ['somefile'])[:require]).to eq ['seeing_is_believing/the_matrix', 'somefile']
|
226
|
+
end
|
227
|
+
|
228
|
+
# TODO: This is prob not ture for eval_in... maybe let the evaluators provide defaults?
|
229
|
+
specify 'load_path is the load_path, with the full path to sib\'s lib added' do
|
230
|
+
path_to_lib = File.expand_path('../../../lib', __FILE__)
|
231
|
+
expect(call(load_path: ['somepath'])[:load_path]).to eq [path_to_lib, 'somepath']
|
232
|
+
end
|
233
|
+
|
234
|
+
# TODO: Default this to utf-8
|
235
|
+
specify 'encoding is set to the encoding' do
|
236
|
+
expect(call(encoding: 'someencoding')[:encoding]).to eq 'someencoding'
|
237
|
+
end
|
238
|
+
|
239
|
+
specify 'timeout is set to timeout' do
|
240
|
+
expect(call(timeout: 1.2)[:timeout]).to eq 1.2
|
241
|
+
end
|
242
|
+
|
243
|
+
specify 'debugger is the same as the toplevel debugger' do
|
244
|
+
options = InterpretFlags.new(ParseArgs.call([]), stdin, stdout)
|
245
|
+
expect(options.lib_options[:debugger]).to equal options.debugger
|
246
|
+
end
|
247
|
+
|
248
|
+
specify 'number_of_captures is number_of_captures' do
|
249
|
+
expect(call(number_of_captures: 12345)[:number_of_captures]).to eq 12345
|
250
|
+
end
|
251
|
+
|
252
|
+
specify 'record_expressions is the annotator\'s expression wrapper' do
|
253
|
+
expect(call[:record_expressions]).to eq InspectExpressions
|
254
|
+
expect(call(xmpfilter_style: true)[:record_expressions]).to be_a_kind_of Proc
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'annotator_options' do
|
259
|
+
def call(overrides={})
|
260
|
+
super(overrides).annotator_options
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'sets alignment_strategy to the provided alignment strategy' do
|
264
|
+
expect(call(alignment_strategy: 'chunk')[:alignment_strategy]).to eq AlignChunk
|
265
|
+
expect(call(alignment_strategy: 'file' )[:alignment_strategy]).to eq AlignFile
|
266
|
+
expect(call(alignment_strategy: 'line' )[:alignment_strategy]).to eq AlignLine
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'sets an error if the requested alignment strategy is not known, or not provided' do
|
270
|
+
flags = ParseArgs.call([])
|
271
|
+
options = InterpretFlags.new(flags.merge(alignment_strategy: 'chunk'), stdin, stdout)
|
272
|
+
expect(options.errors.join).to_not include 'alignment-strategy'
|
273
|
+
|
274
|
+
options = InterpretFlags.new(flags.merge(alignment_strategy: 'nonsense'), stdin, stdout)
|
275
|
+
expect(options.errors.join).to include 'alignment-strategy does not know'
|
276
|
+
|
277
|
+
options = InterpretFlags.new(flags.merge(alignment_strategy: nil), stdin, stdout)
|
278
|
+
expect(options.errors.join).to include 'alignment-strategy expected an alignment strategy'
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'sets the debugger to the toplevel debugger' do
|
282
|
+
options = InterpretFlags.new(ParseArgs.call([]), stdin, stdout)
|
283
|
+
expect(options.annotator_options[:debugger]).to equal options.debugger
|
284
|
+
end
|
285
|
+
|
286
|
+
# TODO: markers
|
287
|
+
it 'sets max_line_length to the max_line_length' do
|
288
|
+
expect(call(max_line_length: 123321)[:max_line_length]).to eq 123321
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'sets max_result_length to the max_result_length' do
|
292
|
+
expect(call(max_result_length: 99889)[:max_result_length]).to eq 99889
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'has a fancy inspect that shows predicates and attributes on multiple lines' do
|
297
|
+
inspected = call.inspect
|
298
|
+
expect(inspected).to include "PREDICATES"
|
299
|
+
expect(inspected).to include "ATTRIBUTES"
|
300
|
+
expect(inspected.lines.to_a.length).to be > 1
|
301
|
+
inspected.lines.each do |line|
|
302
|
+
expect(line.length).to be < 80 # truncate output so it doesn't get spammy
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'seeing_is_believing/binary/parse_args'
|
3
3
|
|
4
|
-
describe SeeingIsBelieving::Binary::ParseArgs do
|
4
|
+
RSpec.describe SeeingIsBelieving::Binary::ParseArgs do
|
5
5
|
RSpec::Matchers.define :have_error do |error_assertion|
|
6
6
|
match do |options|
|
7
7
|
options[:errors].find do |error|
|
@@ -23,8 +23,12 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def parse(args
|
27
|
-
SeeingIsBelieving::Binary::ParseArgs.call args
|
26
|
+
def parse(args)
|
27
|
+
SeeingIsBelieving::Binary::ParseArgs.call args
|
28
|
+
end
|
29
|
+
|
30
|
+
def matrix_file
|
31
|
+
'seeing_is_believing/the_matrix'
|
28
32
|
end
|
29
33
|
|
30
34
|
shared_examples 'it requires a positive int argument' do |flags|
|
@@ -56,18 +60,33 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
63
|
+
it 'does not mutate the input array' do
|
64
|
+
ary = ['a']
|
65
|
+
parse(ary)
|
66
|
+
expect(ary).to eq ['a']
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'can interpret conjoined short-flags' do
|
70
|
+
expect(parse(['-hjg'])).to eq parse(['-h', '-j', '-g'])
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'can interpret conjoined short-flags where one of them is h+' do
|
74
|
+
expect(parse(['-h+jg'])).to eq parse(['-h+', '-j', '-g'])
|
75
|
+
expect(parse(['-jh+g'])).to eq parse(['-j', '-h+', '-g'])
|
76
|
+
expect(parse(['-jgh+'])).to eq parse(['-j', '-g', '-h+'])
|
77
|
+
end
|
78
|
+
|
59
79
|
specify 'unknown options set an error' do
|
60
|
-
expect(parse(['--xyz'])).to have_error 'Unknown option: "--xyz"'
|
61
|
-
expect(parse(['-y'])).to have_error 'Unknown option: "-y"'
|
80
|
+
expect(parse(['--xyz' ])).to have_error 'Unknown option: "--xyz"'
|
81
|
+
expect(parse(['-y' ])).to have_error 'Unknown option: "-y"'
|
62
82
|
expect(parse(['-y', 'b'])).to have_error 'Unknown option: "-y"'
|
83
|
+
expect(parse(['-+h' ])).to have_error 'Unknown option: "-+"'
|
63
84
|
end
|
64
85
|
|
65
86
|
example 'example: multiple args' do
|
66
|
-
options = parse(%w[filename -
|
87
|
+
options = parse(%w[filename -h -r torequire])
|
67
88
|
expect(options[:filename]).to eq 'filename'
|
68
|
-
expect(options[:
|
69
|
-
expect(options[:end_line]).to eq 20
|
70
|
-
expect(options[:require]).to eq ['torequire']
|
89
|
+
expect(options[:require]).to include 'torequire'
|
71
90
|
expect(options[:help]).to be_a_kind_of String
|
72
91
|
expect(options[:errors]).to be_empty
|
73
92
|
end
|
@@ -83,42 +102,11 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
83
102
|
expect(parse(['a', '-x'])[:filename]).to eq 'a'
|
84
103
|
end
|
85
104
|
|
86
|
-
it '
|
87
|
-
expect(parse([])).
|
88
|
-
expect(parse(['a'])).
|
89
|
-
expect(parse(['a', 'b'])).to
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe ':start_line' do
|
94
|
-
it 'defaults to 1' do
|
95
|
-
expect(parse([])[:start_line]).to equal 1
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'is set with -l and --start-line' do
|
99
|
-
expect(parse(['-l', '1'])[:start_line]).to eq 1
|
100
|
-
expect(parse(['--start-line', '12'])[:start_line]).to eq 12
|
105
|
+
it 'records all filenames it sees' do
|
106
|
+
expect(parse([])[:filenames]).to eq []
|
107
|
+
expect(parse(['a'])[:filenames]).to eq ['a']
|
108
|
+
expect(parse(['a', 'b'])[:filenames]).to eq ['a', 'b']
|
101
109
|
end
|
102
|
-
|
103
|
-
it_behaves_like 'it requires a positive int argument', ['-l', '--start-line']
|
104
|
-
end
|
105
|
-
|
106
|
-
describe ':end_line' do
|
107
|
-
it 'defaults to infinity' do
|
108
|
-
expect(parse([])[:end_line]).to equal Float::INFINITY
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'is set with -L and --end-line' do
|
112
|
-
expect(parse(['-L', '1'])[:end_line]).to eq 1
|
113
|
-
expect(parse(['--end-line', '12'])[:end_line]).to eq 12
|
114
|
-
end
|
115
|
-
|
116
|
-
it_behaves_like 'it requires a positive int argument', ['-L', '--end-line']
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'swaps start and end line around if they are out of order' do
|
120
|
-
expect(parse(%w[-l 2 -L 1])[:start_line]).to eq 1
|
121
|
-
expect(parse(%w[-l 2 -L 1])[:end_line]).to eq 2
|
122
110
|
end
|
123
111
|
|
124
112
|
describe ':result_length' do
|
@@ -148,12 +136,12 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
148
136
|
end
|
149
137
|
|
150
138
|
describe :require do
|
151
|
-
it 'defaults to
|
152
|
-
expect(parse([])[:require]).to
|
139
|
+
it 'defaults to the matrix file array' do
|
140
|
+
expect(parse([])[:require]).to eq [matrix_file]
|
153
141
|
end
|
154
142
|
|
155
143
|
it '-r and --require sets each required file into the result array' do
|
156
|
-
expect(parse(%w[-r f1 --require f2])[:require]).to eq
|
144
|
+
expect(parse(%w[-r f1 --require f2])[:require]).to eq [matrix_file, 'f1', 'f2']
|
157
145
|
end
|
158
146
|
|
159
147
|
it 'sets an error if not provided with a filename' do
|
@@ -168,31 +156,37 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
168
156
|
expect(parse([])[:help]).to be_nil
|
169
157
|
end
|
170
158
|
|
171
|
-
it 'is set to
|
172
|
-
expect(parse(['-h'])[:help]).to
|
173
|
-
expect(parse(['--help'])[:help]).to
|
174
|
-
|
175
|
-
expect(parse(['-h'])[:help]).to_not include 'Examples:'
|
176
|
-
expect(parse(['--help'])[:help]).to_not include 'Examples:'
|
159
|
+
it 'is set to "help" with -h and --help and -help' do
|
160
|
+
expect(parse(['-h'])[:help]).to eq 'help'
|
161
|
+
expect(parse(['--help'])[:help]).to eq 'help'
|
177
162
|
end
|
178
163
|
|
179
|
-
it 'is set to
|
180
|
-
expect(parse(['-h+'])[:help]).to
|
181
|
-
expect(parse(['--help+'])[:help]).to
|
164
|
+
it 'is set to "help+" with examples help screen with --help+ and -h+' do
|
165
|
+
expect(parse(['-h+'])[:help]).to eq 'help+'
|
166
|
+
expect(parse(['--help+'])[:help]).to eq 'help+'
|
167
|
+
end
|
168
|
+
end
|
182
169
|
|
183
|
-
|
184
|
-
|
170
|
+
describe 'short and long help_screen' do
|
171
|
+
specify 'they are the short and long help screens' do
|
172
|
+
short = parse([])[:short_help_screen]
|
173
|
+
long = parse([])[:long_help_screen]
|
174
|
+
expect(short.length).to be < long.length
|
175
|
+
expect(short).to include 'Usage'
|
176
|
+
expect(long).to include 'Usage'
|
177
|
+
expect(short).to_not include 'Examples'
|
178
|
+
expect(long).to include 'Examples'
|
185
179
|
end
|
186
180
|
end
|
187
181
|
|
188
|
-
describe ':
|
182
|
+
describe ':program_from_args' do
|
189
183
|
it 'defaults to nil' do
|
190
|
-
expect(parse([])[:
|
184
|
+
expect(parse([])[:program_from_args]).to be_nil
|
191
185
|
end
|
192
186
|
|
193
187
|
it 'is set with -e or --program, and takes the next arg' do
|
194
|
-
expect(parse(['-e', '1'])[:
|
195
|
-
expect(parse(['--program', '1'])[:
|
188
|
+
expect(parse(['-e', '1'])[:program_from_args]).to eq '1'
|
189
|
+
expect(parse(['--program', '1'])[:program_from_args]).to eq '1'
|
196
190
|
end
|
197
191
|
|
198
192
|
it 'sets an error if not given a program' do
|
@@ -201,11 +195,6 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
201
195
|
expect(parse(['-e'])).to have_error /-e/
|
202
196
|
expect(parse(['--program'])).to have_error /--program/
|
203
197
|
end
|
204
|
-
|
205
|
-
it 'sets an error if a filename is also give' do
|
206
|
-
expect(parse(['-e', '1'])).to_not have_error /-e/
|
207
|
-
expect(parse(['-e', '1', 'abc'])).to have_error /"abc"/
|
208
|
-
end
|
209
198
|
end
|
210
199
|
|
211
200
|
describe':load_path' do
|
@@ -297,30 +286,24 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
297
286
|
end
|
298
287
|
|
299
288
|
describe ':alignment_strategy' do
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
# maybe change the default?
|
305
|
-
it 'defaults to AlignChunk' do
|
306
|
-
expect(parse([])[:alignment_strategy]).to eq AlignChunk
|
289
|
+
# TODO: maybe change the default?
|
290
|
+
it 'defaults to "chunk"' do
|
291
|
+
expect(parse([])[:alignment_strategy]).to eq 'chunk'
|
307
292
|
end
|
308
293
|
|
309
294
|
specify '-s and --alignment-strategy sets the alignment strategy' do
|
310
|
-
expect(parse(['-s', 'chunk'])[:alignment_strategy]).to eq
|
311
|
-
expect(parse(['--alignment-strategy', 'chunk'])[:alignment_strategy]).to eq
|
295
|
+
expect(parse(['-s', 'chunk'])[:alignment_strategy]).to eq 'chunk'
|
296
|
+
expect(parse(['--alignment-strategy', 'chunk'])[:alignment_strategy]).to eq 'chunk'
|
312
297
|
end
|
313
298
|
|
314
299
|
it 'accepts values: file, line, chunk' do
|
315
|
-
expect(parse(['-s', 'file'])[:alignment_strategy]).to eq
|
316
|
-
expect(parse(['-s', 'line'])[:alignment_strategy]).to eq
|
317
|
-
expect(parse(['-s', 'chunk'])[:alignment_strategy]).to eq
|
300
|
+
expect(parse(['-s', 'file'])[:alignment_strategy]).to eq 'file'
|
301
|
+
expect(parse(['-s', 'line'])[:alignment_strategy]).to eq 'line'
|
302
|
+
expect(parse(['-s', 'chunk'])[:alignment_strategy]).to eq 'chunk'
|
318
303
|
end
|
319
304
|
|
320
|
-
it 'sets an error if not provided with a strategy
|
305
|
+
it 'sets an error if not provided with a strategy' do
|
321
306
|
expect(parse(['-s', 'file'])).to_not have_error /alignment-strategy/
|
322
|
-
expect(parse(['-s', 'abc'])).to have_error /alignment-strategy/
|
323
|
-
expect(parse(['-s' ])).to have_error /alignment-strategy/
|
324
307
|
end
|
325
308
|
end
|
326
309
|
|
@@ -346,18 +329,14 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
346
329
|
end
|
347
330
|
end
|
348
331
|
|
349
|
-
describe ':
|
350
|
-
it 'defaults to a
|
351
|
-
expect(parse([]
|
332
|
+
describe ':debug' do
|
333
|
+
it 'defaults to a false' do
|
334
|
+
expect(parse([])[:debug]).to eq false
|
352
335
|
end
|
353
336
|
|
354
337
|
it 'can be enabled with --debug or -g' do
|
355
|
-
expect(parse(['--debug']
|
356
|
-
expect(parse(['-g']
|
357
|
-
end
|
358
|
-
|
359
|
-
it 'sets the stream to the one passed in' do
|
360
|
-
expect(parse(['-g'], :fake_stream)[:debugger].stream).to eq :fake_stream
|
338
|
+
expect(parse(['--debug'])[:debug]).to eq true
|
339
|
+
expect(parse(['-g'])[:debug]).to eq true
|
361
340
|
end
|
362
341
|
end
|
363
342
|
|
@@ -399,5 +378,28 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
399
378
|
expect(parse(['-j'])[:result_as_json]).to eq true
|
400
379
|
end
|
401
380
|
end
|
381
|
+
|
382
|
+
describe ':markers' do
|
383
|
+
it 'defaults to a hash with :value, :exception, :stdout, :stderr, and :nextline' do
|
384
|
+
expect(parse([])[:markers].keys).to eq [:value, :exception, :stdout, :stderr, :nextline]
|
385
|
+
end
|
386
|
+
|
387
|
+
def assert_default(marker_name, value)
|
388
|
+
expect(parse([])[:markers][marker_name]).to eq value
|
389
|
+
end
|
390
|
+
|
391
|
+
it('defaults :value to "# => "') { assert_default :value , "# => " }
|
392
|
+
it('defaults :exception to "# ~> "') { assert_default :exception , "# ~> " }
|
393
|
+
it('defaults :stdout to "# >> "') { assert_default :stdout , "# >> " }
|
394
|
+
it('defaults :stderr to "# !> "') { assert_default :stderr , "# !> " }
|
395
|
+
it('defaults :nextline to "# "') { assert_default :nextline , "# " }
|
396
|
+
|
397
|
+
# TODO: When things get a little more stable, don't feel like adding all the cukes to play with this right now
|
398
|
+
it 'overrides :value with --value-marker'
|
399
|
+
it 'overrides :exception with --exception-marker'
|
400
|
+
it 'overrides :stdout with --stdout-marker'
|
401
|
+
it 'overrides :stderr with --stderr-marker'
|
402
|
+
it 'overrides :nextline with --xmpfilter-nextline-marker'
|
403
|
+
end
|
402
404
|
end
|
403
405
|
|