@@ -197,22 +197,15 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
197197 // @has <path> <jsonpath> = check path exists
198198 2 => {
199199 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 ( )
205202 }
206203 // @has <path> <jsonpath> <value> = check *any* item matched by path equals value
207204 3 => {
208205 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 ( ) )
216209 }
217210 _ => unreachable ! ( ) ,
218211 }
@@ -223,38 +216,37 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
223216 let expected: usize = command. args [ 2 ] . parse ( ) . unwrap ( ) ;
224217
225218 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
230221 }
231222 CommandKind :: Is => {
232223 // @has <path> <jsonpath> <value> = check *exactly one* item matched by path, and it equals value
233224 assert_eq ! ( command. args. len( ) , 3 ) ;
234225 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 ( )
242229 }
243- // FIXME, Figure out semantics for @!set
244230 CommandKind :: Set => {
245231 // @set <name> = <path> <jsonpath>
246232 assert_eq ! ( command. args. len( ) , 4 ) ;
247233 assert_eq ! ( command. args[ 1 ] , "=" , "Expected an `=`" ) ;
248234 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 => {
253240 let r = cache. variables . insert ( command. args [ 0 ] . clone ( ) , results[ 0 ] . clone ( ) ) ;
254241 assert ! ( r. is_none( ) , "Name collision: {} is duplicated" , command. args[ 0 ] ) ;
255242 true
256243 }
257- Err ( _) => false ,
244+ _ => {
245+ panic ! (
246+ "Got multiple results in `@set` for `{}`: {:?}" ,
247+ & command. args[ 3 ] , results
248+ ) ;
249+ }
258250 }
259251 }
260252 } ;
0 commit comments