lucy-goosey 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lucy-goosey.rb +2 -1
- data/lib/lucy-goosey/version.rb +1 -1
- data/test/combinatorial_test.rb +74 -0
- data/test/options_parsing_test.rb +5 -67
- metadata +5 -3
data/lib/lucy-goosey.rb
CHANGED
@@ -8,6 +8,7 @@ module Lucy
|
|
8
8
|
|
9
9
|
|
10
10
|
def self.leading_word?(word)
|
11
|
+
return unless word
|
11
12
|
! (word.match(UNIX_DOUBLE_FLAG) || word.match(UNIX_SINGLE_FLAG) || word.match(EQUAL))
|
12
13
|
end
|
13
14
|
|
@@ -17,7 +18,7 @@ module Lucy
|
|
17
18
|
config = {}
|
18
19
|
|
19
20
|
raise ArgumentError, 'must be an array' unless _args.is_a? Array
|
20
|
-
return config if
|
21
|
+
return config if args.empty?
|
21
22
|
|
22
23
|
args = args[1..-1] while leading_word?(args.first)
|
23
24
|
|
data/lib/lucy-goosey/version.rb
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'lucy-goosey'
|
3
|
+
|
4
|
+
describe Lucy::Goosey do
|
5
|
+
describe "::parse_options" do
|
6
|
+
describe "combinatorial tests" do
|
7
|
+
before do
|
8
|
+
def tester(raw_string, result)
|
9
|
+
case raw_string
|
10
|
+
when /foo/ then result['foo'].must_equal 'bar'
|
11
|
+
when /--n/ then result['n'].must_equal '1'
|
12
|
+
when /tru/ then result['truth'].must_equal true
|
13
|
+
when /a=b/ then result['a'].must_equal 'b'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
first_level = ['-foo bar', '--n 1', '--truth', 'a=b', '-f']
|
19
|
+
|
20
|
+
first_level.each do |first|
|
21
|
+
second_level = first_level - [first]
|
22
|
+
second_level.each do |second|
|
23
|
+
test_string = "#{first} #{second}"
|
24
|
+
# two levels deep
|
25
|
+
it "understands #{test_string}" do
|
26
|
+
result = Lucy::Goosey.parse_options(test_string.split(' '))
|
27
|
+
tester(first, result)
|
28
|
+
tester(second, result)
|
29
|
+
end
|
30
|
+
|
31
|
+
# third level - its getting a little crazy in here
|
32
|
+
third_level = second_level - [second]
|
33
|
+
third_level.each do |third|
|
34
|
+
test_string = "#{first} #{second} #{third}"
|
35
|
+
|
36
|
+
it "understands #{test_string}" do
|
37
|
+
result = Lucy::Goosey.parse_options(test_string.split(' '))
|
38
|
+
tester(first, result)
|
39
|
+
tester(second, result)
|
40
|
+
tester(third, result)
|
41
|
+
end
|
42
|
+
|
43
|
+
# fourth level - now we're having fun!
|
44
|
+
fourth_level = third_level - [third]
|
45
|
+
fourth_level.each do |fourth|
|
46
|
+
test_string = "#{first} #{second} #{third} #{fourth}"
|
47
|
+
|
48
|
+
it "understands #{test_string}" do
|
49
|
+
result = Lucy::Goosey.parse_options(test_string.split(' '))
|
50
|
+
tester(first, result)
|
51
|
+
tester(second, result)
|
52
|
+
tester(third, result)
|
53
|
+
tester(fourth, result)
|
54
|
+
end
|
55
|
+
|
56
|
+
# fifth level - cus we're not fucking around
|
57
|
+
fifth = (fourth_level - [fourth]).first
|
58
|
+
test_string = "#{first} #{second} #{third} #{fourth} #{fifth}"
|
59
|
+
|
60
|
+
it "understands #{test_string}" do
|
61
|
+
result = Lucy::Goosey.parse_options(test_string.split(' '))
|
62
|
+
tester(first, result)
|
63
|
+
tester(second, result)
|
64
|
+
tester(third, result)
|
65
|
+
tester(fourth, result)
|
66
|
+
tester(fifth, result)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -36,73 +36,6 @@ describe Lucy::Goosey do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
describe "combinatorial tests" do
|
40
|
-
before do
|
41
|
-
def tester(raw_string, result)
|
42
|
-
case raw_string
|
43
|
-
when /foo/ then result['foo'].must_equal 'bar'
|
44
|
-
when /--n/ then result['n'].must_equal '1'
|
45
|
-
when /tru/ then result['truth'].must_equal true
|
46
|
-
when /a=b/ then result['a'].must_equal 'b'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
first_level = ['-foo bar', '--n 1', '--truth', 'a=b', '-f']
|
52
|
-
|
53
|
-
first_level.each do |first|
|
54
|
-
second_level = first_level - [first]
|
55
|
-
second_level.each do |second|
|
56
|
-
test_string = "#{first} #{second}"
|
57
|
-
# two levels deep
|
58
|
-
it "understands #{test_string}" do
|
59
|
-
result = Lucy::Goosey.parse_options(test_string.split(' '))
|
60
|
-
tester(first, result)
|
61
|
-
tester(second, result)
|
62
|
-
end
|
63
|
-
|
64
|
-
# third level - its getting a little crazy in here
|
65
|
-
third_level = second_level - [second]
|
66
|
-
third_level.each do |third|
|
67
|
-
test_string = "#{first} #{second} #{third}"
|
68
|
-
|
69
|
-
it "understands #{test_string}" do
|
70
|
-
result = Lucy::Goosey.parse_options(test_string.split(' '))
|
71
|
-
tester(first, result)
|
72
|
-
tester(second, result)
|
73
|
-
tester(third, result)
|
74
|
-
end
|
75
|
-
|
76
|
-
# fourth level - now we're having fun!
|
77
|
-
fourth_level = third_level - [third]
|
78
|
-
fourth_level.each do |fourth|
|
79
|
-
test_string = "#{first} #{second} #{third} #{fourth}"
|
80
|
-
|
81
|
-
it "understands #{test_string}" do
|
82
|
-
result = Lucy::Goosey.parse_options(test_string.split(' '))
|
83
|
-
tester(first, result)
|
84
|
-
tester(second, result)
|
85
|
-
tester(third, result)
|
86
|
-
tester(fourth, result)
|
87
|
-
end
|
88
|
-
|
89
|
-
# fifth level - cus we're not fucking around
|
90
|
-
fifth = (fourth_level - [fourth]).first
|
91
|
-
test_string = "#{first} #{second} #{third} #{fourth} #{fifth}"
|
92
|
-
|
93
|
-
it "understands #{test_string}" do
|
94
|
-
result = Lucy::Goosey.parse_options(test_string.split(' '))
|
95
|
-
tester(first, result)
|
96
|
-
tester(second, result)
|
97
|
-
tester(third, result)
|
98
|
-
tester(fourth, result)
|
99
|
-
tester(fifth, result)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
39
|
|
107
40
|
describe "bad input" do
|
108
41
|
it "expects an array" do
|
@@ -110,6 +43,11 @@ describe Lucy::Goosey do
|
|
110
43
|
Lucy::Goosey.parse_options('')
|
111
44
|
end
|
112
45
|
end
|
46
|
+
|
47
|
+
it "is ok with only leading words" do
|
48
|
+
result = Lucy::Goosey.parse_options(%w(wtf bbq))
|
49
|
+
result.must_equal({})
|
50
|
+
end
|
113
51
|
end
|
114
52
|
|
115
53
|
describe "edge cases" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lucy-goosey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/lucy-goosey.rb
|
60
60
|
- lib/lucy-goosey/version.rb
|
61
61
|
- lucy-goosey.gemspec
|
62
|
+
- test/combinatorial_test.rb
|
62
63
|
- test/options_parsing_test.rb
|
63
64
|
homepage: ''
|
64
65
|
licenses: []
|
@@ -74,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
75
|
version: '0'
|
75
76
|
segments:
|
76
77
|
- 0
|
77
|
-
hash: -
|
78
|
+
hash: -1157995687993160958
|
78
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
80
|
none: false
|
80
81
|
requirements:
|
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
84
|
version: '0'
|
84
85
|
segments:
|
85
86
|
- 0
|
86
|
-
hash: -
|
87
|
+
hash: -1157995687993160958
|
87
88
|
requirements: []
|
88
89
|
rubyforge_project:
|
89
90
|
rubygems_version: 1.8.23
|
@@ -92,4 +93,5 @@ specification_version: 3
|
|
92
93
|
summary: Takes an array, returns a hash. Expects the array to consist of unix style
|
93
94
|
flags or values, much like the command line arguments in ARGV
|
94
95
|
test_files:
|
96
|
+
- test/combinatorial_test.rb
|
95
97
|
- test/options_parsing_test.rb
|