@@ -54,6 +54,20 @@ fn test_handle_json_with_args() {
5454 assert ! ( is_truthy) ;
5555}
5656
57+ #[ test]
58+ fn test_handle_json_input_overrides_arg_with_same_name ( ) {
59+ let program = Program :: compile ( "this.value" ) . unwrap ( ) ;
60+ let mut args = BTreeMap :: new ( ) ;
61+ args. insert ( "this" . to_string ( ) , CelValue :: Int ( 999 ) ) ;
62+ let json = r#"{"value": 50}"# ;
63+ let params = default_params ( ) ;
64+
65+ let ( output, is_truthy) = handle_json ( & program, & args, & params, Some ( json) ) . unwrap ( ) ;
66+
67+ assert ! ( output. contains( "50" ) ) ;
68+ assert ! ( is_truthy) ;
69+ }
70+
5771#[ test]
5872fn test_handle_json_args_and_json ( ) {
5973 let program = Program :: compile ( "x + this.value" ) . unwrap ( ) ;
@@ -114,6 +128,36 @@ fn test_handle_json_truthiness_empty_string() {
114128 assert ! ( !is_truthy) ;
115129}
116130
131+ #[ test]
132+ fn test_handle_json_raw_output_for_string ( ) {
133+ let program = Program :: compile ( r#""hello""# ) . unwrap ( ) ;
134+ let args = BTreeMap :: new ( ) ;
135+ let mut params = default_params ( ) ;
136+ params. raw_output = true ;
137+
138+ let ( output, is_truthy) = handle_json ( & program, & args, & params, None ) . unwrap ( ) ;
139+
140+ assert_eq ! ( output, "hello" ) ;
141+ assert ! ( is_truthy) ;
142+ }
143+
144+ #[ test]
145+ fn test_handle_json_sorted_pretty_output ( ) {
146+ let program = Program :: compile ( r#"{"z": {"b": 2, "a": 1}, "a": 0}"# ) . unwrap ( ) ;
147+ let args = BTreeMap :: new ( ) ;
148+ let mut params = default_params ( ) ;
149+ params. sort_keys = true ;
150+ params. pretty_print = true ;
151+
152+ let ( output, is_truthy) = handle_json ( & program, & args, & params, None ) . unwrap ( ) ;
153+
154+ assert_eq ! (
155+ output,
156+ "{\n \" a\" : 0,\n \" z\" : {\n \" a\" : 1,\n \" b\" : 2\n }\n }"
157+ ) ;
158+ assert ! ( is_truthy) ;
159+ }
160+
117161#[ test]
118162fn test_handle_json_invalid_json ( ) {
119163 let program = Program :: compile ( "this.x" ) . unwrap ( ) ;
@@ -239,3 +283,20 @@ fn test_handle_buffer_skip_empty_lines() {
239283 assert ! ( results[ 1 ] . 0 . contains( "2" ) ) ;
240284 assert ! ( results[ 2 ] . 0 . contains( "3" ) ) ;
241285}
286+
287+ #[ test]
288+ fn test_handle_buffer_custom_root_var ( ) {
289+ let program = Program :: compile ( "request.x" ) . unwrap ( ) ;
290+ let args = BTreeMap :: new ( ) ;
291+ let input = r#"{"x": 42}"# ;
292+ let cursor = Cursor :: new ( input. as_bytes ( ) ) ;
293+ let reader = BufReader :: new ( cursor) ;
294+ let mut params = default_params ( ) ;
295+ params. root_var = "request" . to_string ( ) ;
296+
297+ let results = handle_buffer ( & program, & args, & params, reader) . unwrap ( ) ;
298+
299+ assert_eq ! ( results. len( ) , 1 ) ;
300+ assert_eq ! ( results[ 0 ] . 0 , "42" ) ;
301+ assert ! ( results[ 0 ] . 1 ) ;
302+ }
0 commit comments