@@ -49,13 +49,15 @@ pub enum CommandKind {
4949 Has ,
5050 Count ,
5151 Is ,
52+ Set ,
5253}
5354
5455impl CommandKind {
5556 fn validate ( & self , args : & [ String ] , command_num : usize , lineno : usize ) -> bool {
5657 let count = match self {
5758 CommandKind :: Has => ( 1 ..=3 ) . contains ( & args. len ( ) ) ,
5859 CommandKind :: Count | CommandKind :: Is => 3 == args. len ( ) ,
60+ CommandKind :: Set => 4 == args. len ( ) ,
5961 } ;
6062
6163 if !count {
@@ -85,6 +87,7 @@ impl fmt::Display for CommandKind {
8587 CommandKind :: Has => "has" ,
8688 CommandKind :: Count => "count" ,
8789 CommandKind :: Is => "is" ,
90+ CommandKind :: Set => "set" ,
8891 } ;
8992 write ! ( f, "{}" , text)
9093 }
@@ -130,6 +133,7 @@ fn get_commands(template: &str) -> Result<Vec<Command>, ()> {
130133 "has" => CommandKind :: Has ,
131134 "count" => CommandKind :: Count ,
132135 "is" => CommandKind :: Is ,
136+ "set" => CommandKind :: Set ,
133137 _ => {
134138 print_err ( & format ! ( "Unrecognized command name `@{}`" , cmd) , lineno) ;
135139 errors = true ;
@@ -236,6 +240,23 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
236240 Err ( _) => false ,
237241 }
238242 }
243+ // FIXME, Figure out semantics for @!set
244+ CommandKind :: Set => {
245+ // @set <name> = <path> <jsonpath>
246+ assert_eq ! ( command. args. len( ) , 4 ) ;
247+ assert_eq ! ( command. args[ 1 ] , "=" , "Expected an `=`" ) ;
248+ 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 ) ;
253+ let r = cache. variables . insert ( command. args [ 0 ] . clone ( ) , results[ 0 ] . clone ( ) ) ;
254+ assert ! ( r. is_none( ) , "Name collision" ) ;
255+ true
256+ }
257+ Err ( _) => false ,
258+ }
259+ }
239260 } ;
240261
241262 if result == command. negated {
0 commit comments