@@ -475,7 +475,7 @@ def testClear(env):
475
475
r .expect ('JSON.CLEAR' , 'test' , '$.arr[2].n' ).equal (1 )
476
476
r .expect ('JSON.CLEAR' , 'test' , '$.arr[3].n2.n' ).equal (1 )
477
477
478
- # Fail clear on inappropriate path (not obj or arr)
478
+ # No clear on inappropriate path (not obj or arr or numeric )
479
479
r .expect ('JSON.CLEAR' , 'test' , '$.arr[1]' ).equal (0 )
480
480
481
481
# Make sure specific obj content was cleared
@@ -516,6 +516,35 @@ def testClear(env):
516
516
# Key doesn't exist
517
517
r .expect ('JSON.CLEAR' , 'not_test_key' , '$' ).raiseError ()
518
518
519
+ def testClearScalar (env ):
520
+ """Test JSON.CLEAR command for scalars"""
521
+
522
+ r = env
523
+ r .assertOk (r .execute_command ('JSON.SET' , 'test' , '$' , json .dumps (docs ['basic' ])))
524
+ # Clear numeric values
525
+ r .assertEqual (r .execute_command ('JSON.CLEAR' , 'test' , '$.int' ), 1 )
526
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test' , '$.int' ), '[0]' )
527
+
528
+ r .assertEqual (r .execute_command ('JSON.CLEAR' , 'test' , '$.num' ), 1 )
529
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test' , '$.num' ), '[0]' )
530
+
531
+ r .assertEqual (r .execute_command ('JSON.CLEAR' , 'test' , '$..a' ), 1 )
532
+ r .assertEqual (r .execute_command ('JSON.GET' , 'test' , '$..a' ), '[0]' )
533
+
534
+ r .assertOk (r .execute_command ('JSON.SET' , 'test' , '$' , json .dumps (docs ['scalars' ])))
535
+ r .assertEqual (r .execute_command ('JSON.CLEAR' , 'test' , '$.*' ), 2 )
536
+ res = r .execute_command ('JSON.GET' , 'test' , '$.*' )
537
+ r .assertEqual (json .loads (res ), ['string value' , None , True ,0 , 0 ])
538
+
539
+ # Do not clear already cleared values
540
+ r .assertEqual (r .execute_command ('JSON.CLEAR' , 'test' , '$.*' ), 0 )
541
+
542
+ # Do not clear other scalars
543
+ r .assertEqual (r .execute_command ('JSON.CLEAR' , 'test' , '$.none' ), 0 )
544
+ r .assertEqual (r .execute_command ('JSON.CLEAR' , 'test' , '$.bool' ), 0 )
545
+ r .assertEqual (r .execute_command ('JSON.CLEAR' , 'test' , '$.string' ), 0 )
546
+
547
+
519
548
def testArrayCRUD (env ):
520
549
"""Test JSON Array CRUDness"""
521
550
0 commit comments