@@ -18,7 +18,7 @@ class OptionsWithEnumProtocolSpec: QuickSpec {
1818 func tryArguments( _ arguments: String ... ) -> Result < TestEnumOptions , CommandantError < NoError > > {
1919 return TestEnumOptions . evaluate ( . arguments( ArgumentParser ( arguments) ) )
2020 }
21-
21+
2222 it ( " should fail if a required argument is missing " ) {
2323 expect ( tryArguments ( ) . value) . to ( beNil ( ) )
2424 }
@@ -30,78 +30,78 @@ class OptionsWithEnumProtocolSpec: QuickSpec {
3030 it ( " should fail if an option is missing a value " ) {
3131 expect ( tryArguments ( " required " , " --strictStringValue " , " drop " ) . value) . to ( beNil ( ) )
3232 }
33-
33+
3434 it ( " should fail if an optional strict int parameter is wrong " ) {
3535 expect ( tryArguments ( " required " , " 256 " ) . value) . to ( beNil ( ) )
3636 }
37-
37+
3838 it ( " should succeed without optional string arguments " ) {
3939 let value = tryArguments ( " required " ) . value
4040 let expected = TestEnumOptions ( strictIntValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . min, requiredName: " required " , arguments: [ ] )
4141 expect ( value) . to ( equal ( expected) )
4242 }
43-
43+
4444 it ( " should succeed without optional strict int value " ) {
4545 let value = tryArguments ( " required " , " 5 " ) . value
4646 let expected = TestEnumOptions ( strictIntValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . giveFive, requiredName: " required " , arguments: [ ] )
4747 expect ( value) . to ( equal ( expected) )
4848 }
49-
49+
5050 it ( " should succeed with some strings array arguments separated by comma " ) {
5151 let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --optionalStrictStringValue " , " baz " , " 255 " , " --strictStringsArray " , " a,b,c " ) . value
5252 let expected = TestEnumOptions ( strictIntValue: . three, strictStringValue: . foobar, strictStringsArray: [ . a, . b, . c] , optionalStrictStringsArray: nil , optionalStrictStringValue: . baz, optionalStrictInt: . max, requiredName: " required " , arguments: [ ] )
5353 expect ( value) . to ( equal ( expected) )
5454 }
55-
55+
5656 it ( " should succeed with some strings array arguments separated by space " ) {
5757 let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --optionalStrictStringValue " , " baz " , " --strictStringsArray " , " a b c " , " 255 " ) . value
5858 let expected = TestEnumOptions ( strictIntValue: . three, strictStringValue: . foobar, strictStringsArray: [ . a, . b, . c] , optionalStrictStringsArray: nil , optionalStrictStringValue: . baz, optionalStrictInt: . max, requiredName: " required " , arguments: [ ] )
5959 expect ( value) . to ( equal ( expected) )
6060 }
61-
61+
6262 it ( " should succeed with some strings array arguments separated by comma and space " ) {
6363 let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --optionalStrictStringValue " , " baz " , " --strictStringsArray " , " a, b, c " , " 255 " ) . value
6464 let expected = TestEnumOptions ( strictIntValue: . three, strictStringValue: . foobar, strictStringsArray: [ . a, . b, . c] , optionalStrictStringsArray: nil , optionalStrictStringValue: . baz, optionalStrictInt: . max, requiredName: " required " , arguments: [ ] )
6565 expect ( value) . to ( equal ( expected) )
6666 }
67-
67+
6868 it ( " should succeed with some optional string arguments " ) {
6969 let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --optionalStrictStringValue " , " baz " , " 255 " ) . value
7070 let expected = TestEnumOptions ( strictIntValue: . three, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: . baz, optionalStrictInt: . max, requiredName: " required " , arguments: [ ] )
7171 expect ( value) . to ( equal ( expected) )
7272 }
73-
73+
7474 it ( " should succeed without optional array arguments " ) {
7575 let value = tryArguments ( " required " ) . value
7676 let expected = TestEnumOptions ( strictIntValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . min, requiredName: " required " , arguments: [ ] )
7777 expect ( value) . to ( equal ( expected) )
7878 }
79-
79+
8080 it ( " should succeed with some optional array arguments " ) {
8181 let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --optionalStrictStringsArray " , " one, two " , " 255 " ) . value
8282 let expected = TestEnumOptions ( strictIntValue: . three, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: [ . one, . two] , optionalStrictStringValue: nil , optionalStrictInt: . max, requiredName: " required " , arguments: [ ] )
8383 expect ( value) . to ( equal ( expected) )
8484 }
85-
85+
8686 it ( " should override previous optional arguments " ) {
8787 let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --strictStringValue " , " fuzzbuzz " , " --strictIntValue " , " 5 " , " --strictStringValue " , " bazbuzz " ) . value
8888 let expected = TestEnumOptions ( strictIntValue: . giveFive, strictStringValue: . bazbuzz, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . min, requiredName: " required " , arguments: [ ] )
8989 expect ( value) . to ( equal ( expected) )
9090 }
91-
91+
9292 it ( " should consume the rest of positional arguments " ) {
9393 let value = tryArguments ( " required " , " 255 " , " value1 " , " value2 " ) . value
9494 let expected = TestEnumOptions ( strictIntValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . max, requiredName: " required " , arguments: [ " value1 " , " value2 " ] )
9595 expect ( value) . to ( equal ( expected) )
9696 }
97-
97+
9898 it ( " should treat -- as the end of valued options " ) {
9999 let value = tryArguments ( " -- " , " --strictIntValue " ) . value
100100 let expected = TestEnumOptions ( strictIntValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . min, requiredName: " --strictIntValue " , arguments: [ ] )
101101 expect ( value) . to ( equal ( expected) )
102102 }
103103 }
104-
104+
105105 describe ( " CommandMode.Usage " ) {
106106 it ( " should return an error containing usage information " ) {
107107 let error = TestEnumOptions . evaluate ( . usage) . error
@@ -123,15 +123,15 @@ struct TestEnumOptions: OptionsProtocol, Equatable {
123123 let optionalStrictInt : StrictIntValue
124124 let requiredName : String
125125 let arguments : [ String ]
126-
126+
127127 typealias ClientError = NoError
128-
128+
129129 static func create( _ a: StrictIntValue ) -> ( StrictStringValue ) -> ( [ StrictStringValue ] ) -> ( [ StrictStringValue ] ? ) -> ( StrictStringValue ? ) -> ( String ) -> ( StrictIntValue ) -> ( [ String ] ) -> TestEnumOptions {
130130 return { b in { c in { d in { e in { f in { g in { h in
131131 return self . init ( strictIntValue: a, strictStringValue: b, strictStringsArray: c, optionalStrictStringsArray: d, optionalStrictStringValue: e, optionalStrictInt: g, requiredName: f, arguments: h)
132132 } } } } } } }
133133 }
134-
134+
135135 static func evaluate( _ m: CommandMode ) -> Result < TestEnumOptions , CommandantError < NoError > > {
136136 return create
137137 <*> m <| Option ( key: " strictIntValue " , defaultValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, usage: " `0` - zero, `255` - max, `3` - three, `5` - five or `42` - The Answer " )
@@ -157,7 +157,7 @@ extension TestEnumOptions: CustomStringConvertible {
157157
158158enum StrictStringValue : String , ArgumentProtocol {
159159 static var name : String = " Strict string value: `foobar`, `bazbuzz`, `one`, `two`, `baz`, `a`, `b` or `c` "
160-
160+
161161 case foobar
162162 case bazbuzz
163163 case one
@@ -170,7 +170,7 @@ enum StrictStringValue: String, ArgumentProtocol {
170170
171171enum StrictIntValue : UInt8 , ArgumentProtocol {
172172 static var name : String = " Strict int value: `3`, `5`, `42`, `0`, `255` "
173-
173+
174174 case min = 0
175175 case three = 3
176176 case giveFive = 5
0 commit comments