@@ -18,7 +18,7 @@ class OptionsWithEnumProtocolSpec: QuickSpec {
18
18
func tryArguments( _ arguments: String ... ) -> Result < TestEnumOptions , CommandantError < NoError > > {
19
19
return TestEnumOptions . evaluate ( . arguments( ArgumentParser ( arguments) ) )
20
20
}
21
-
21
+
22
22
it ( " should fail if a required argument is missing " ) {
23
23
expect ( tryArguments ( ) . value) . to ( beNil ( ) )
24
24
}
@@ -30,78 +30,78 @@ class OptionsWithEnumProtocolSpec: QuickSpec {
30
30
it ( " should fail if an option is missing a value " ) {
31
31
expect ( tryArguments ( " required " , " --strictStringValue " , " drop " ) . value) . to ( beNil ( ) )
32
32
}
33
-
33
+
34
34
it ( " should fail if an optional strict int parameter is wrong " ) {
35
35
expect ( tryArguments ( " required " , " 256 " ) . value) . to ( beNil ( ) )
36
36
}
37
-
37
+
38
38
it ( " should succeed without optional string arguments " ) {
39
39
let value = tryArguments ( " required " ) . value
40
40
let expected = TestEnumOptions ( strictIntValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . min, requiredName: " required " , arguments: [ ] )
41
41
expect ( value) . to ( equal ( expected) )
42
42
}
43
-
43
+
44
44
it ( " should succeed without optional strict int value " ) {
45
45
let value = tryArguments ( " required " , " 5 " ) . value
46
46
let expected = TestEnumOptions ( strictIntValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . giveFive, requiredName: " required " , arguments: [ ] )
47
47
expect ( value) . to ( equal ( expected) )
48
48
}
49
-
49
+
50
50
it ( " should succeed with some strings array arguments separated by comma " ) {
51
51
let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --optionalStrictStringValue " , " baz " , " 255 " , " --strictStringsArray " , " a,b,c " ) . value
52
52
let expected = TestEnumOptions ( strictIntValue: . three, strictStringValue: . foobar, strictStringsArray: [ . a, . b, . c] , optionalStrictStringsArray: nil , optionalStrictStringValue: . baz, optionalStrictInt: . max, requiredName: " required " , arguments: [ ] )
53
53
expect ( value) . to ( equal ( expected) )
54
54
}
55
-
55
+
56
56
it ( " should succeed with some strings array arguments separated by space " ) {
57
57
let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --optionalStrictStringValue " , " baz " , " --strictStringsArray " , " a b c " , " 255 " ) . value
58
58
let expected = TestEnumOptions ( strictIntValue: . three, strictStringValue: . foobar, strictStringsArray: [ . a, . b, . c] , optionalStrictStringsArray: nil , optionalStrictStringValue: . baz, optionalStrictInt: . max, requiredName: " required " , arguments: [ ] )
59
59
expect ( value) . to ( equal ( expected) )
60
60
}
61
-
61
+
62
62
it ( " should succeed with some strings array arguments separated by comma and space " ) {
63
63
let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --optionalStrictStringValue " , " baz " , " --strictStringsArray " , " a, b, c " , " 255 " ) . value
64
64
let expected = TestEnumOptions ( strictIntValue: . three, strictStringValue: . foobar, strictStringsArray: [ . a, . b, . c] , optionalStrictStringsArray: nil , optionalStrictStringValue: . baz, optionalStrictInt: . max, requiredName: " required " , arguments: [ ] )
65
65
expect ( value) . to ( equal ( expected) )
66
66
}
67
-
67
+
68
68
it ( " should succeed with some optional string arguments " ) {
69
69
let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --optionalStrictStringValue " , " baz " , " 255 " ) . value
70
70
let expected = TestEnumOptions ( strictIntValue: . three, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: . baz, optionalStrictInt: . max, requiredName: " required " , arguments: [ ] )
71
71
expect ( value) . to ( equal ( expected) )
72
72
}
73
-
73
+
74
74
it ( " should succeed without optional array arguments " ) {
75
75
let value = tryArguments ( " required " ) . value
76
76
let expected = TestEnumOptions ( strictIntValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . min, requiredName: " required " , arguments: [ ] )
77
77
expect ( value) . to ( equal ( expected) )
78
78
}
79
-
79
+
80
80
it ( " should succeed with some optional array arguments " ) {
81
81
let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --optionalStrictStringsArray " , " one, two " , " 255 " ) . value
82
82
let expected = TestEnumOptions ( strictIntValue: . three, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: [ . one, . two] , optionalStrictStringValue: nil , optionalStrictInt: . max, requiredName: " required " , arguments: [ ] )
83
83
expect ( value) . to ( equal ( expected) )
84
84
}
85
-
85
+
86
86
it ( " should override previous optional arguments " ) {
87
87
let value = tryArguments ( " required " , " --strictIntValue " , " 3 " , " --strictStringValue " , " fuzzbuzz " , " --strictIntValue " , " 5 " , " --strictStringValue " , " bazbuzz " ) . value
88
88
let expected = TestEnumOptions ( strictIntValue: . giveFive, strictStringValue: . bazbuzz, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . min, requiredName: " required " , arguments: [ ] )
89
89
expect ( value) . to ( equal ( expected) )
90
90
}
91
-
91
+
92
92
it ( " should consume the rest of positional arguments " ) {
93
93
let value = tryArguments ( " required " , " 255 " , " value1 " , " value2 " ) . value
94
94
let expected = TestEnumOptions ( strictIntValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . max, requiredName: " required " , arguments: [ " value1 " , " value2 " ] )
95
95
expect ( value) . to ( equal ( expected) )
96
96
}
97
-
97
+
98
98
it ( " should treat -- as the end of valued options " ) {
99
99
let value = tryArguments ( " -- " , " --strictIntValue " ) . value
100
100
let expected = TestEnumOptions ( strictIntValue: . theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: . foobar, strictStringsArray: [ ] , optionalStrictStringsArray: nil , optionalStrictStringValue: nil , optionalStrictInt: . min, requiredName: " --strictIntValue " , arguments: [ ] )
101
101
expect ( value) . to ( equal ( expected) )
102
102
}
103
103
}
104
-
104
+
105
105
describe ( " CommandMode.Usage " ) {
106
106
it ( " should return an error containing usage information " ) {
107
107
let error = TestEnumOptions . evaluate ( . usage) . error
@@ -123,15 +123,15 @@ struct TestEnumOptions: OptionsProtocol, Equatable {
123
123
let optionalStrictInt : StrictIntValue
124
124
let requiredName : String
125
125
let arguments : [ String ]
126
-
126
+
127
127
typealias ClientError = NoError
128
-
128
+
129
129
static func create( _ a: StrictIntValue ) -> ( StrictStringValue ) -> ( [ StrictStringValue ] ) -> ( [ StrictStringValue ] ? ) -> ( StrictStringValue ? ) -> ( String ) -> ( StrictIntValue ) -> ( [ String ] ) -> TestEnumOptions {
130
130
return { b in { c in { d in { e in { f in { g in { h in
131
131
return self . init ( strictIntValue: a, strictStringValue: b, strictStringsArray: c, optionalStrictStringsArray: d, optionalStrictStringValue: e, optionalStrictInt: g, requiredName: f, arguments: h)
132
132
} } } } } } }
133
133
}
134
-
134
+
135
135
static func evaluate( _ m: CommandMode ) -> Result < TestEnumOptions , CommandantError < NoError > > {
136
136
return create
137
137
<*> 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 {
157
157
158
158
enum StrictStringValue : String , ArgumentProtocol {
159
159
static var name : String = " Strict string value: `foobar`, `bazbuzz`, `one`, `two`, `baz`, `a`, `b` or `c` "
160
-
160
+
161
161
case foobar
162
162
case bazbuzz
163
163
case one
@@ -170,7 +170,7 @@ enum StrictStringValue: String, ArgumentProtocol {
170
170
171
171
enum StrictIntValue : UInt8 , ArgumentProtocol {
172
172
static var name : String = " Strict int value: `3`, `5`, `42`, `0`, `255` "
173
-
173
+
174
174
case min = 0
175
175
case three = 3
176
176
case giveFive = 5
0 commit comments