@@ -197,22 +197,15 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
197
197
// @has <path> <jsonpath> = check path exists
198
198
2 => {
199
199
let val = cache. get_value ( & command. args [ 0 ] ) ?;
200
-
201
- match select ( & val, & command. args [ 1 ] ) {
202
- Ok ( results) => !results. is_empty ( ) ,
203
- Err ( _) => false ,
204
- }
200
+ let results = select ( & val, & command. args [ 1 ] ) . unwrap ( ) ;
201
+ !results. is_empty ( )
205
202
}
206
203
// @has <path> <jsonpath> <value> = check *any* item matched by path equals value
207
204
3 => {
208
205
let val = cache. get_value ( & command. args [ 0 ] ) ?;
209
- match select ( & val, & command. args [ 1 ] ) {
210
- Ok ( results) => {
211
- let pat = string_to_value ( & command. args [ 2 ] , cache) ;
212
- results. contains ( & pat. as_ref ( ) )
213
- }
214
- Err ( _) => false ,
215
- }
206
+ let results = select ( & val, & command. args [ 1 ] ) . unwrap ( ) ;
207
+ let pat = string_to_value ( & command. args [ 2 ] , cache) ;
208
+ results. contains ( & pat. as_ref ( ) )
216
209
}
217
210
_ => unreachable ! ( ) ,
218
211
}
@@ -223,38 +216,37 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
223
216
let expected: usize = command. args [ 2 ] . parse ( ) . unwrap ( ) ;
224
217
225
218
let val = cache. get_value ( & command. args [ 0 ] ) ?;
226
- match select ( & val, & command. args [ 1 ] ) {
227
- Ok ( results) => results. len ( ) == expected,
228
- Err ( _) => false ,
229
- }
219
+ let results = select ( & val, & command. args [ 1 ] ) . unwrap ( ) ;
220
+ results. len ( ) == expected
230
221
}
231
222
CommandKind :: Is => {
232
223
// @has <path> <jsonpath> <value> = check *exactly one* item matched by path, and it equals value
233
224
assert_eq ! ( command. args. len( ) , 3 ) ;
234
225
let val = cache. get_value ( & command. args [ 0 ] ) ?;
235
- match select ( & val, & command. args [ 1 ] ) {
236
- Ok ( results) => {
237
- let pat = string_to_value ( & command. args [ 2 ] , cache) ;
238
- results. len ( ) == 1 && results[ 0 ] == pat. as_ref ( )
239
- }
240
- Err ( _) => false ,
241
- }
226
+ let results = select ( & val, & command. args [ 1 ] ) . unwrap ( ) ;
227
+ let pat = string_to_value ( & command. args [ 2 ] , cache) ;
228
+ results. len ( ) == 1 && results[ 0 ] == pat. as_ref ( )
242
229
}
243
- // FIXME, Figure out semantics for @!set
244
230
CommandKind :: Set => {
245
231
// @set <name> = <path> <jsonpath>
246
232
assert_eq ! ( command. args. len( ) , 4 ) ;
247
233
assert_eq ! ( command. args[ 1 ] , "=" , "Expected an `=`" ) ;
248
234
let val = cache. get_value ( & command. args [ 2 ] ) ?;
249
-
250
- match select ( & val, & command. args [ 3 ] ) {
251
- Ok ( results) => {
252
- assert_eq ! ( results. len( ) , 1 ) ;
235
+ let results = select ( & val, & command. args [ 3 ] ) . unwrap ( ) ;
236
+ assert_eq ! ( results. len( ) , 1 ) ;
237
+ match results. len ( ) {
238
+ 0 => false ,
239
+ 1 => {
253
240
let r = cache. variables . insert ( command. args [ 0 ] . clone ( ) , results[ 0 ] . clone ( ) ) ;
254
241
assert ! ( r. is_none( ) , "Name collision: {} is duplicated" , command. args[ 0 ] ) ;
255
242
true
256
243
}
257
- Err ( _) => false ,
244
+ _ => {
245
+ panic ! (
246
+ "Got multiple results in `@set` for `{}`: {:?}" ,
247
+ & command. args[ 3 ] , results
248
+ ) ;
249
+ }
258
250
}
259
251
}
260
252
} ;
0 commit comments