@@ -3602,6 +3602,140 @@ test_decimal128_overflowing_exponent (void)
3602
3602
}
3603
3603
}
3604
3604
3605
+ static void
3606
+ test_parse_array (void )
3607
+ {
3608
+ {
3609
+ bson_t * b1 ;
3610
+ {
3611
+ const char * json = BSON_STR ([ {"$code" : "A "} ]);
3612
+ bson_error_t error ;
3613
+ b1 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3614
+ ASSERT_OR_PRINT (b1 , error );
3615
+ }
3616
+
3617
+ bson_t * b2 ;
3618
+ {
3619
+ const char * json = BSON_STR ({"0" : {"$code" : "A "}});
3620
+ bson_error_t error ;
3621
+ b2 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3622
+ ASSERT_OR_PRINT (b2 , error );
3623
+ }
3624
+
3625
+ ASSERT (bson_equal (b1 , b2 ));
3626
+ bson_destroy (b2 );
3627
+ bson_destroy (b1 );
3628
+ }
3629
+
3630
+ {
3631
+ bson_t * b1 ;
3632
+ {
3633
+ const char * json = BSON_STR ([ {"$code" : "A "}, {" $code " : " B "} ]);
3634
+ bson_error_t error ;
3635
+ b1 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3636
+ ASSERT_OR_PRINT (b1 , error );
3637
+ }
3638
+
3639
+ bson_t * b2 ;
3640
+ {
3641
+ const char * json =
3642
+ BSON_STR ({"0" : {"$code" : "A "}}, {" 1 " : {" $code " : " B "}});
3643
+ bson_error_t error ;
3644
+ b2 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3645
+ ASSERT_OR_PRINT (b2 , error );
3646
+ }
3647
+
3648
+ ASSERT (bson_equal (b1 , b2 ));
3649
+ bson_destroy (b2 );
3650
+ bson_destroy (b1 );
3651
+ }
3652
+
3653
+ {
3654
+ bson_t * b1 ;
3655
+ {
3656
+ const char * json = BSON_STR ([ {
3657
+ "$dbPointer" :
3658
+ {"$ref" : "foo ",
3659
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}}
3660
+ } ]);
3661
+ bson_error_t error ;
3662
+ b1 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3663
+ ASSERT_OR_PRINT (b1 , error );
3664
+ }
3665
+
3666
+ bson_t * b2 ;
3667
+ {
3668
+ const char * json = BSON_STR ({
3669
+ "0" : {
3670
+ "$dbPointer" : {
3671
+ "$ref" : "foo ",
3672
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}
3673
+ }
3674
+ }
3675
+ });
3676
+ bson_error_t error ;
3677
+ b2 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3678
+ ASSERT_OR_PRINT (b2 , error );
3679
+ }
3680
+
3681
+ ASSERT (bson_equal (b1 , b2 ));
3682
+ bson_destroy (b2 );
3683
+ bson_destroy (b1 );
3684
+ }
3685
+
3686
+ {
3687
+ bson_t * b1 ;
3688
+ {
3689
+ const char * json = BSON_STR ([
3690
+ {
3691
+ "$dbPointer" : {
3692
+ "$ref" : "foo ",
3693
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}
3694
+ }
3695
+ },
3696
+ {
3697
+ " $dbPointer " : {
3698
+ " $ref " : " foo ",
3699
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}
3700
+ }
3701
+ }
3702
+ ]);
3703
+ bson_error_t error ;
3704
+ b1 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3705
+ ASSERT_OR_PRINT (b1 , error );
3706
+ }
3707
+
3708
+ bson_t * b2 ;
3709
+ {
3710
+ const char * json = BSON_STR (
3711
+ {
3712
+ "0" : {
3713
+ "$dbPointer" : {
3714
+ "$ref" : "foo ",
3715
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}
3716
+ }
3717
+ }
3718
+ },
3719
+ {
3720
+ " 1 " : {
3721
+ " $dbPointer " : {
3722
+ " $ref " : " foo ",
3723
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}
3724
+ }
3725
+ }
3726
+ });
3727
+
3728
+ bson_error_t error ;
3729
+ b2 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3730
+ ASSERT_OR_PRINT (b2 , error );
3731
+ }
3732
+
3733
+ ASSERT (bson_equal (b1 , b2 ));
3734
+ bson_destroy (b2 );
3735
+ bson_destroy (b1 );
3736
+ }
3737
+ }
3738
+
3605
3739
void
3606
3740
test_json_install (TestSuite * suite )
3607
3741
{
@@ -3791,6 +3925,7 @@ test_json_install (TestSuite *suite)
3791
3925
TestSuite_Add (suite ,
3792
3926
"/bson/as_json_with_opts/all_types" ,
3793
3927
test_bson_as_json_with_opts_all_types );
3928
+ TestSuite_Add (suite , "/bson/parse_array" , test_parse_array );
3794
3929
TestSuite_Add (suite ,
3795
3930
"/bson/decimal128_overflowing_exponent" ,
3796
3931
test_decimal128_overflowing_exponent );
0 commit comments