summaryrefslogtreecommitdiff
path: root/tests/extended.zig
diff options
context:
space:
mode:
Diffstat (limited to 'tests/extended.zig')
-rw-r--r--tests/extended.zig68
1 files changed, 32 insertions, 36 deletions
diff --git a/tests/extended.zig b/tests/extended.zig
index 78c319e..3dbb87d 100644
--- a/tests/extended.zig
+++ b/tests/extended.zig
@@ -29,18 +29,14 @@ pub fn Test(comptime Expect: type) type {
29 pub fn success(args: []const []const u8, expected: *const Expect) Self { 29 pub fn success(args: []const []const u8, expected: *const Expect) Self {
30 return Self{ 30 return Self{
31 .args = args, 31 .args = args,
32 .kind = Kind{ 32 .kind = Kind{ .Success = expected.* },
33 .Success = expected.*,
34 },
35 }; 33 };
36 } 34 }
37 35
38 pub fn fail(args: []const []const u8, err: error) Self { 36 pub fn fail(args: []const []const u8, err: error) Self {
39 return Self{ 37 return Self{
40 .args = args, 38 .args = args,
41 .kind = Kind{ 39 .kind = Kind{ .Fail = err },
42 .Fail = err,
43 },
44 }; 40 };
45 } 41 }
46 42
@@ -86,74 +82,74 @@ test "clap.extended: short" {
86 break :p res; 82 break :p res;
87 }, 83 },
88 Param.option("b", Names.short('b'), &Parser.int(u8, 10)), 84 Param.option("b", Names.short('b'), &Parser.int(u8, 10)),
89 } 85 },
90 }; 86 };
91 87
92 const T = Test(S); 88 const T = Test(S);
93 const tests = []T{ 89 const tests = []T{
94 T.success( 90 T.success(
95 [][]const u8 { "-a" }, 91 [][]const u8{"-a"},
96 S{ 92 S{
97 .a = true, 93 .a = true,
98 .b = 0, 94 .b = 0,
99 }, 95 },
100 ), 96 ),
101 T.success( 97 T.success(
102 [][]const u8 { "-a", "-b", "100" }, 98 [][]const u8{ "-a", "-b", "100" },
103 S{ 99 S{
104 .a = true, 100 .a = true,
105 .b = 100, 101 .b = 100,
106 }, 102 },
107 ), 103 ),
108 T.success( 104 T.success(
109 [][]const u8 { "-a", "-b=100" }, 105 [][]const u8{ "-a", "-b=100" },
110 S{ 106 S{
111 .a = true, 107 .a = true,
112 .b = 100, 108 .b = 100,
113 }, 109 },
114 ), 110 ),
115 T.success( 111 T.success(
116 [][]const u8 { "-a", "-b100" }, 112 [][]const u8{ "-a", "-b100" },
117 S{ 113 S{
118 .a = true, 114 .a = true,
119 .b = 100, 115 .b = 100,
120 }, 116 },
121 ), 117 ),
122 T.success( 118 T.success(
123 [][]const u8 { "-ab", "100" }, 119 [][]const u8{ "-ab", "100" },
124 S{ 120 S{
125 .a = true, 121 .a = true,
126 .b = 100, 122 .b = 100,
127 }, 123 },
128 ), 124 ),
129 T.success( 125 T.success(
130 [][]const u8 { "-ab=100" }, 126 [][]const u8{"-ab=100"},
131 S{ 127 S{
132 .a = true, 128 .a = true,
133 .b = 100, 129 .b = 100,
134 }, 130 },
135 ), 131 ),
136 T.success( 132 T.success(
137 [][]const u8 { "-ab100" }, 133 [][]const u8{"-ab100"},
138 S{ 134 S{
139 .a = true, 135 .a = true,
140 .b = 100, 136 .b = 100,
141 }, 137 },
142 ), 138 ),
143 T.fail( 139 T.fail(
144 [][]const u8 { "-q" }, 140 [][]const u8{"-q"},
145 error.InvalidArgument, 141 error.InvalidArgument,
146 ), 142 ),
147 T.fail( 143 T.fail(
148 [][]const u8 { "--a" }, 144 [][]const u8{"--a"},
149 error.InvalidArgument, 145 error.InvalidArgument,
150 ), 146 ),
151 T.fail( 147 T.fail(
152 [][]const u8 { "-b=100" }, 148 [][]const u8{"-b=100"},
153 error.ParamNotHandled, 149 error.ParamNotHandled,
154 ), 150 ),
155 T.fail( 151 T.fail(
156 [][]const u8 { "-b=100", "-a" }, 152 [][]const u8{ "-b=100", "-a" },
157 error.InvalidArgument, 153 error.InvalidArgument,
158 ), 154 ),
159 }; 155 };
@@ -182,50 +178,50 @@ test "clap.extended: long" {
182 break :p res; 178 break :p res;
183 }, 179 },
184 Param.option("b", Names.long('b'), &Parser.int(u8, 10)), 180 Param.option("b", Names.long('b'), &Parser.int(u8, 10)),
185 } 181 },
186 }; 182 };
187 183
188 const T = Test(S); 184 const T = Test(S);
189 const tests = []T{ 185 const tests = []T{
190 T.success( 186 T.success(
191 [][]const u8 { "--a" }, 187 [][]const u8{"--a"},
192 S{ 188 S{
193 .a = true, 189 .a = true,
194 .b = 0, 190 .b = 0,
195 }, 191 },
196 ), 192 ),
197 T.success( 193 T.success(
198 [][]const u8 { "--a", "--b", "100" }, 194 [][]const u8{ "--a", "--b", "100" },
199 S{ 195 S{
200 .a = true, 196 .a = true,
201 .b = 100, 197 .b = 100,
202 }, 198 },
203 ), 199 ),
204 T.success( 200 T.success(
205 [][]const u8 { "--a", "--b=100" }, 201 [][]const u8{ "--a", "--b=100" },
206 S{ 202 S{
207 .a = true, 203 .a = true,
208 .b = 100, 204 .b = 100,
209 }, 205 },
210 ), 206 ),
211 T.fail( 207 T.fail(
212 [][]const u8 { "--a=100" }, 208 [][]const u8{"--a=100"},
213 error.DoesntTakeValue, 209 error.DoesntTakeValue,
214 ), 210 ),
215 T.fail( 211 T.fail(
216 [][]const u8 { "--q" }, 212 [][]const u8{"--q"},
217 error.InvalidArgument, 213 error.InvalidArgument,
218 ), 214 ),
219 T.fail( 215 T.fail(
220 [][]const u8 { "-a" }, 216 [][]const u8{"-a"},
221 error.InvalidArgument, 217 error.InvalidArgument,
222 ), 218 ),
223 T.fail( 219 T.fail(
224 [][]const u8 { "--b=100" }, 220 [][]const u8{"--b=100"},
225 error.ParamNotHandled, 221 error.ParamNotHandled,
226 ), 222 ),
227 T.fail( 223 T.fail(
228 [][]const u8 { "--b=100", "--a" }, 224 [][]const u8{ "--b=100", "--a" },
229 error.InvalidArgument, 225 error.InvalidArgument,
230 ), 226 ),
231 }; 227 };
@@ -254,50 +250,50 @@ test "clap.extended: bare" {
254 break :p res; 250 break :p res;
255 }, 251 },
256 Param.option("b", Names.bare('b'), &Parser.int(u8, 10)), 252 Param.option("b", Names.bare('b'), &Parser.int(u8, 10)),
257 } 253 },
258 }; 254 };
259 255
260 const T = Test(S); 256 const T = Test(S);
261 const tests = []T{ 257 const tests = []T{
262 T.success( 258 T.success(
263 [][]const u8 { "a" }, 259 [][]const u8{"a"},
264 S{ 260 S{
265 .a = true, 261 .a = true,
266 .b = 0, 262 .b = 0,
267 }, 263 },
268 ), 264 ),
269 T.success( 265 T.success(
270 [][]const u8 { "a", "b", "100" }, 266 [][]const u8{ "a", "b", "100" },
271 S{ 267 S{
272 .a = true, 268 .a = true,
273 .b = 100, 269 .b = 100,
274 }, 270 },
275 ), 271 ),
276 T.success( 272 T.success(
277 [][]const u8 { "a", "b=100" }, 273 [][]const u8{ "a", "b=100" },
278 S{ 274 S{
279 .a = true, 275 .a = true,
280 .b = 100, 276 .b = 100,
281 }, 277 },
282 ), 278 ),
283 T.fail( 279 T.fail(
284 [][]const u8 { "a=100" }, 280 [][]const u8{"a=100"},
285 error.DoesntTakeValue, 281 error.DoesntTakeValue,
286 ), 282 ),
287 T.fail( 283 T.fail(
288 [][]const u8 { "--a" }, 284 [][]const u8{"--a"},
289 error.InvalidArgument, 285 error.InvalidArgument,
290 ), 286 ),
291 T.fail( 287 T.fail(
292 [][]const u8 { "-a" }, 288 [][]const u8{"-a"},
293 error.InvalidArgument, 289 error.InvalidArgument,
294 ), 290 ),
295 T.fail( 291 T.fail(
296 [][]const u8 { "b=100" }, 292 [][]const u8{"b=100"},
297 error.ParamNotHandled, 293 error.ParamNotHandled,
298 ), 294 ),
299 T.fail( 295 T.fail(
300 [][]const u8 { "b=100", "--a" }, 296 [][]const u8{ "b=100", "--a" },
301 error.InvalidArgument, 297 error.InvalidArgument,
302 ), 298 ),
303 }; 299 };