@@ -171,4 +171,50 @@ defmodule OptionParserTest do
171
171
assert OptionParser . parse ( args )
172
172
== { [ source: "from_docs/" , verbose: true ] , [ "test/enum_test.exs" ] , [ ] }
173
173
end
174
+
175
+ test "next strict: good options" do
176
+ config = [ switches: [ str: :string , int: :integer , bool: :boolean ] , strict: true ]
177
+ assert OptionParser . next ( [ "--str" , "hello" , "..." ] , config )
178
+ == { :ok , :str , "hello" , [ "..." ] }
179
+ assert OptionParser . next ( [ "--int=13" , "..." ] , config )
180
+ == { :ok , :int , 13 , [ "..." ] }
181
+ assert OptionParser . next ( [ "--bool=false" , "..." ] , config )
182
+ == { :ok , :bool , false , [ "..." ] }
183
+ assert OptionParser . next ( [ "--no-bool" , "..." ] , config )
184
+ == { :ok , :bool , false , [ "..." ] }
185
+ assert OptionParser . next ( [ "--bool" , "..." ] , config )
186
+ == { :ok , :bool , true , [ "..." ] }
187
+ assert OptionParser . next ( [ "..." ] , config )
188
+ == { :error , [ "..." ] }
189
+ end
190
+
191
+ test "next strict: unknown options" do
192
+ config = [ switches: [ bool: :boolean ] , strict: true ]
193
+ assert OptionParser . next ( [ "--str" , "13" , "..." ] , config )
194
+ == { :error , { :undefined , :str , nil } , [ "13" , "..." ] }
195
+ assert OptionParser . next ( [ "--int=hello" , "..." ] , config )
196
+ == { :error , { :undefined , :int , "hello" } , [ "..." ] }
197
+ end
198
+
199
+ test "next strict: bad type" do
200
+ config = [ switches: [ str: :string , int: :integer , bool: :boolean ] , strict: true ]
201
+ assert OptionParser . next ( [ "--str" , "13" , "..." ] , config )
202
+ == { :ok , :str , "13" , [ "..." ] }
203
+ assert OptionParser . next ( [ "--int=hello" , "..." ] , config )
204
+ == { :error , { :value , :int , "hello" } , [ "..." ] }
205
+ assert OptionParser . next ( [ "--int" , "hello" , "..." ] , config )
206
+ == { :error , { :value , :int , "hello" } , [ "..." ] }
207
+ assert OptionParser . next ( [ "--bool=other" , "..." ] , config )
208
+ == { :error , { :value , :bool , "other" } , [ "..." ] }
209
+ end
210
+
211
+ test "next strict: missing value" do
212
+ config = [ switches: [ str: :string , int: :integer , bool: :boolean ] , strict: true ]
213
+ assert OptionParser . next ( [ "--str" ] , config )
214
+ == { :error , { :value , :str , nil } , [ ] }
215
+ assert OptionParser . next ( [ "--int" ] , config )
216
+ == { :error , { :value , :int , nil } , [ ] }
217
+ assert OptionParser . next ( [ "--bool=" , "..." ] , config )
218
+ == { :error , { :value , :bool , "" } , [ "..." ] }
219
+ end
174
220
end
0 commit comments