@@ -46,9 +46,9 @@ defmodule OptionParserTest do
46
46
assert OptionParser . parse ( [ "--no-bool" ] )
47
47
== { [ no_bool: true ] , [ ] , [ ] }
48
48
assert OptionParser . parse ( [ "--no-bool" ] , strict: [ ] )
49
- == { [ ] , [ ] , [ no_bool: nil ] }
49
+ == { [ ] , [ ] , [ { "--no-bool" , nil } ] }
50
50
assert OptionParser . parse ( [ "--no-bool=..." , "other" ] )
51
- == { [ ] , [ "other" ] , [ no_bool: "..." ] }
51
+ == { [ ] , [ "other" ] , [ { "--no-bool" , "..." } ] }
52
52
end
53
53
54
54
test "does not parse -- as an alias" do
@@ -58,7 +58,7 @@ defmodule OptionParserTest do
58
58
59
59
test "does not parse - as a switch" do
60
60
assert OptionParser . parse ( [ "-source=from_docs/" ] , aliases: [ s: :source ] )
61
- == { [ ] , [ ] , [ source: "from_docs/" ] }
61
+ == { [ ] , [ ] , [ { "- source" , "from_docs/" } ] }
62
62
end
63
63
64
64
test "parses configured booleans" do
@@ -67,18 +67,18 @@ defmodule OptionParserTest do
67
67
assert OptionParser . parse ( [ "--docs=true" ] , switches: [ docs: :boolean ] )
68
68
== { [ docs: true ] , [ ] , [ ] }
69
69
assert OptionParser . parse ( [ "--docs=other" ] , switches: [ docs: :boolean ] )
70
- == { [ ] , [ ] , [ docs: "other" ] }
70
+ == { [ ] , [ ] , [ { "-- docs" , "other" } ] }
71
71
assert OptionParser . parse ( [ "--docs=" ] , switches: [ docs: :boolean ] )
72
- == { [ ] , [ ] , [ docs: "" ] }
72
+ == { [ ] , [ ] , [ { "-- docs" , "" } ] }
73
73
74
74
assert OptionParser . parse ( [ "--docs" , "foo" ] , switches: [ docs: :boolean ] )
75
75
== { [ docs: true ] , [ "foo" ] , [ ] }
76
76
assert OptionParser . parse ( [ "--no-docs" , "foo" ] , switches: [ docs: :boolean ] )
77
77
== { [ docs: false ] , [ "foo" ] , [ ] }
78
78
assert OptionParser . parse ( [ "--no-docs=foo" , "bar" ] , switches: [ docs: :boolean ] )
79
- == { [ ] , [ "bar" ] , [ no_docs: "foo" ] }
79
+ == { [ ] , [ "bar" ] , [ { "--no-docs" , "foo" } ] }
80
80
assert OptionParser . parse ( [ "--no-docs=" , "bar" ] , switches: [ docs: :boolean ] )
81
- == { [ ] , [ "bar" ] , [ no_docs: "" ] }
81
+ == { [ ] , [ "bar" ] , [ { "--no-docs" , "" } ] }
82
82
end
83
83
84
84
test "does not set unparsed booleans" do
@@ -92,7 +92,7 @@ defmodule OptionParserTest do
92
92
== { [ require: "foo" , require: "bar" ] , [ "baz" ] , [ ] }
93
93
94
94
assert OptionParser . parse ( [ "--require" ] , switches: [ require: :keep ] )
95
- == { [ ] , [ ] , [ require: nil ] }
95
+ == { [ ] , [ ] , [ { "-- require" , nil } ] }
96
96
end
97
97
98
98
test "parses configured strings" do
@@ -101,9 +101,9 @@ defmodule OptionParserTest do
101
101
assert OptionParser . parse ( [ "--value=1" , "foo" ] , switches: [ value: :string ] )
102
102
== { [ value: "1" ] , [ "foo" ] , [ ] }
103
103
assert OptionParser . parse ( [ "--value" ] , switches: [ value: :string ] )
104
- == { [ ] , [ ] , [ value: nil ] }
104
+ == { [ ] , [ ] , [ { "-- value" , nil } ] }
105
105
assert OptionParser . parse ( [ "--no-value" ] , switches: [ value: :string ] )
106
- == { [ ] , [ ] , [ no_value: nil ] }
106
+ == { [ ] , [ ] , [ { "--no-value" , nil } ] }
107
107
end
108
108
109
109
test "parses configured integers" do
@@ -112,7 +112,7 @@ defmodule OptionParserTest do
112
112
assert OptionParser . parse ( [ "--value=1" , "foo" ] , switches: [ value: :integer ] )
113
113
== { [ value: 1 ] , [ "foo" ] , [ ] }
114
114
assert OptionParser . parse ( [ "--value" , "WAT" , "foo" ] , switches: [ value: :integer ] )
115
- == { [ ] , [ "foo" ] , [ value: "WAT" ] }
115
+ == { [ ] , [ "foo" ] , [ { "-- value" , "WAT" } ] }
116
116
end
117
117
118
118
test "parses configured integers with keep" do
@@ -131,7 +131,7 @@ defmodule OptionParserTest do
131
131
assert OptionParser . parse ( [ "--value=1.0" , "foo" ] , switches: [ value: :float ] )
132
132
== { [ value: 1.0 ] , [ "foo" ] , [ ] }
133
133
assert OptionParser . parse ( [ "--value" , "WAT" , "foo" ] , switches: [ value: :float ] )
134
- == { [ ] , [ "foo" ] , [ value: "WAT" ] }
134
+ == { [ ] , [ "foo" ] , [ { "-- value" , "WAT" } ] }
135
135
end
136
136
137
137
test "parses no switches as flags" do
@@ -184,7 +184,7 @@ defmodule OptionParserTest do
184
184
test "collects multiple invalid options" do
185
185
args = [ "--bad" , "opt" , "foo" , "-o" , "bad" , "bar" ]
186
186
assert OptionParser . parse ( args , switches: [ bad: :integer ] )
187
- == { [ ] , [ "foo" , "bar" ] , [ bad: "opt" , o: "bad" ] }
187
+ == { [ ] , [ "foo" , "bar" ] , [ { "-- bad" , "opt" } , { "-o" , "bad" } ] }
188
188
end
189
189
190
190
test "parses more than one key/value options using strict" do
@@ -194,16 +194,16 @@ defmodule OptionParserTest do
194
194
195
195
assert OptionParser . parse ( [ "--source" , "from_docs/" , "--doc" , "show" ] ,
196
196
strict: [ source: :string , docs: :string ] )
197
- == { [ source: "from_docs/" ] , [ "show" ] , [ doc: nil ] }
197
+ == { [ source: "from_docs/" ] , [ "show" ] , [ { "-- doc" , nil } ] }
198
198
199
199
assert OptionParser . parse ( [ "--source" , "from_docs/" , "--doc=show" ] ,
200
200
strict: [ source: :string , docs: :string ] )
201
- == { [ source: "from_docs/" ] , [ ] , [ doc: nil ] }
201
+ == { [ source: "from_docs/" ] , [ ] , [ { "-- doc" , nil } ] }
202
202
end
203
203
204
204
test "parses - as argument" do
205
205
assert OptionParser . parse ( [ "-a" , "-" , "-" , "-b" , "-" ] , aliases: [ b: :boo ] )
206
- == { [ boo: "-" ] , [ "-" ] , [ a: "-" ] }
206
+ == { [ boo: "-" ] , [ "-" ] , [ { "-a" , "-" } ] }
207
207
208
208
assert OptionParser . parse ( [ "--foo" , "-" , "-b" , "-" ] , strict: [ foo: :boolean , boo: :string ] , aliases: [ b: :boo ] )
209
209
== { [ foo: true , boo: "-" ] , [ "-" ] , [ ] }
@@ -228,34 +228,34 @@ defmodule OptionParserTest do
228
228
test "next strict: unknown options" do
229
229
config = [ strict: [ bool: :boolean ] ]
230
230
assert OptionParser . next ( [ "--str" , "13" , "..." ] , config )
231
- == { :undefined , : str, nil , [ "13" , "..." ] }
231
+ == { :undefined , "-- str" , nil , [ "13" , "..." ] }
232
232
assert OptionParser . next ( [ "--int=hello" , "..." ] , config )
233
- == { :undefined , : int, "hello" , [ "..." ] }
234
- assert OptionParser . next ( [ "-- no-bool=other" , "..." ] , config )
235
- == { :undefined , :no_bool , "other" , [ "..." ] }
233
+ == { :undefined , "-- int" , "hello" , [ "..." ] }
234
+ assert OptionParser . next ( [ "-no-bool=other" , "..." ] , config )
235
+ == { :undefined , "-no-bool" , "other" , [ "..." ] }
236
236
end
237
237
238
238
test "next strict: bad type" do
239
239
config = [ strict: [ str: :string , int: :integer , bool: :boolean ] ]
240
240
assert OptionParser . next ( [ "--str" , "13" , "..." ] , config )
241
241
== { :ok , :str , "13" , [ "..." ] }
242
242
assert OptionParser . next ( [ "--int=hello" , "..." ] , config )
243
- == { :invalid , : int, "hello" , [ "..." ] }
243
+ == { :invalid , "-- int" , "hello" , [ "..." ] }
244
244
assert OptionParser . next ( [ "--int" , "hello" , "..." ] , config )
245
- == { :invalid , : int, "hello" , [ "..." ] }
245
+ == { :invalid , "-- int" , "hello" , [ "..." ] }
246
246
assert OptionParser . next ( [ "--bool=other" , "..." ] , config )
247
- == { :invalid , : bool, "other" , [ "..." ] }
247
+ == { :invalid , "-- bool" , "other" , [ "..." ] }
248
248
end
249
249
250
250
test "next strict: missing value" do
251
251
config = [ strict: [ str: :string , int: :integer , bool: :boolean ] ]
252
252
assert OptionParser . next ( [ "--str" ] , config )
253
- == { :invalid , : str, nil , [ ] }
253
+ == { :invalid , "-- str" , nil , [ ] }
254
254
assert OptionParser . next ( [ "--int" ] , config )
255
- == { :invalid , : int, nil , [ ] }
255
+ == { :invalid , "-- int" , nil , [ ] }
256
256
assert OptionParser . next ( [ "--bool=" , "..." ] , config )
257
- == { :invalid , : bool, "" , [ "..." ] }
257
+ == { :invalid , "-- bool" , "" , [ "..." ] }
258
258
assert OptionParser . next ( [ "--no-bool=" , "..." ] , config )
259
- == { :undefined , :no_bool , "" , [ "..." ] }
259
+ == { :undefined , "--no-bool" , "" , [ "..." ] }
260
260
end
261
261
end
0 commit comments