forked from github/octocatalog-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_spec.rb
57 lines (49 loc) · 1.97 KB
/
parser_spec.rb
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
require_relative '../options_helper'
describe OctocatalogDiff::CatalogDiff::Cli::Options do
describe '#opt_parser' do
@parser_args = ['--parser', '--parser-from', '--parser-to']
@supported_parsers = %w(default future)
@parser_args.each do |arg|
it "should raise error if #{arg} has no argument" do
expect { run_optparse([arg]) }.to raise_error(OptionParser::MissingArgument)
end
end
@supported_parsers.each do |parser|
@parser_args.each do |arg|
it "should accept #{arg} '#{parser}' as argument" do
result = run_optparse([arg, parser])
if arg == '--parser'
expect(result[:parser_from]).to eq(parser.to_sym)
expect(result[:parser_to]).to eq(parser.to_sym)
else
arg_key = arg.sub(/^--/, '').tr('-', '_').to_sym
expect(result[arg_key]).to eq(parser.to_sym)
end
end
end
end
@parser_args.each do |arg|
it "should reject invalid #{arg}" do
expect { run_optparse([arg, 'lsdkfslkdaf']) }.to raise_error(ArgumentError)
end
end
it 'should disallow --parser and --parser-from from conflicting' do
args = ['--parser', 'future', '--parser-from', 'default']
expect { run_optparse(args) }.to raise_error(ArgumentError)
end
it 'should disallow --parser and --parser-to from conflicting' do
args = ['--parser', 'future', '--parser-to', 'default']
expect { run_optparse(args) }.to raise_error(ArgumentError)
end
it 'should allow --parser and --parser-from to be used together if matching' do
args = ['--parser', 'default', '--parser-from', 'default']
result = run_optparse(args)
expect(result[:parser_from]).to eq(:default)
end
it 'should disallow --parser and --parser-to to be used together if matching' do
args = ['--parser', 'future', '--parser-to', 'future']
result = run_optparse(args)
expect(result[:parser_to]).to eq(:future)
end
end
end