@@ -3646,6 +3646,140 @@ test_decimal128_overflowing_exponent (void)
3646
3646
}
3647
3647
}
3648
3648
3649
+ static void
3650
+ test_parse_array (void )
3651
+ {
3652
+ {
3653
+ bson_t * b1 ;
3654
+ {
3655
+ const char * json = BSON_STR ([ {"$code" : "A "} ]);
3656
+ bson_error_t error ;
3657
+ b1 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3658
+ ASSERT_OR_PRINT (b1 , error );
3659
+ }
3660
+
3661
+ bson_t * b2 ;
3662
+ {
3663
+ const char * json = BSON_STR ({"0" : {"$code" : "A "}});
3664
+ bson_error_t error ;
3665
+ b2 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3666
+ ASSERT_OR_PRINT (b2 , error );
3667
+ }
3668
+
3669
+ ASSERT (bson_equal (b1 , b2 ));
3670
+ bson_destroy (b2 );
3671
+ bson_destroy (b1 );
3672
+ }
3673
+
3674
+ {
3675
+ bson_t * b1 ;
3676
+ {
3677
+ const char * json = BSON_STR ([ {"$code" : "A "}, {" $code " : " B "} ]);
3678
+ bson_error_t error ;
3679
+ b1 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3680
+ ASSERT_OR_PRINT (b1 , error );
3681
+ }
3682
+
3683
+ bson_t * b2 ;
3684
+ {
3685
+ const char * json =
3686
+ BSON_STR ({"0" : {"$code" : "A "}}, {" 1 " : {" $code " : " B "}});
3687
+ bson_error_t error ;
3688
+ b2 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3689
+ ASSERT_OR_PRINT (b2 , error );
3690
+ }
3691
+
3692
+ ASSERT (bson_equal (b1 , b2 ));
3693
+ bson_destroy (b2 );
3694
+ bson_destroy (b1 );
3695
+ }
3696
+
3697
+ {
3698
+ bson_t * b1 ;
3699
+ {
3700
+ const char * json = BSON_STR ([ {
3701
+ "$dbPointer" :
3702
+ {"$ref" : "foo ",
3703
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}}
3704
+ } ]);
3705
+ bson_error_t error ;
3706
+ b1 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3707
+ ASSERT_OR_PRINT (b1 , error );
3708
+ }
3709
+
3710
+ bson_t * b2 ;
3711
+ {
3712
+ const char * json = BSON_STR ({
3713
+ "0" : {
3714
+ "$dbPointer" : {
3715
+ "$ref" : "foo ",
3716
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}
3717
+ }
3718
+ }
3719
+ });
3720
+ bson_error_t error ;
3721
+ b2 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3722
+ ASSERT_OR_PRINT (b2 , error );
3723
+ }
3724
+
3725
+ ASSERT (bson_equal (b1 , b2 ));
3726
+ bson_destroy (b2 );
3727
+ bson_destroy (b1 );
3728
+ }
3729
+
3730
+ {
3731
+ bson_t * b1 ;
3732
+ {
3733
+ const char * json = BSON_STR ([
3734
+ {
3735
+ "$dbPointer" : {
3736
+ "$ref" : "foo ",
3737
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}
3738
+ }
3739
+ },
3740
+ {
3741
+ " $dbPointer " : {
3742
+ " $ref " : " foo ",
3743
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}
3744
+ }
3745
+ }
3746
+ ]);
3747
+ bson_error_t error ;
3748
+ b1 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3749
+ ASSERT_OR_PRINT (b1 , error );
3750
+ }
3751
+
3752
+ bson_t * b2 ;
3753
+ {
3754
+ const char * json = BSON_STR (
3755
+ {
3756
+ "0" : {
3757
+ "$dbPointer" : {
3758
+ "$ref" : "foo ",
3759
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}
3760
+ }
3761
+ }
3762
+ },
3763
+ {
3764
+ " 1 " : {
3765
+ " $dbPointer " : {
3766
+ " $ref " : " foo ",
3767
+ " $id " : {" $oid " : " 01234567890 abcdef0123456 "}
3768
+ }
3769
+ }
3770
+ });
3771
+
3772
+ bson_error_t error ;
3773
+ b2 = bson_new_from_json ((const uint8_t * ) json , -1 , & error );
3774
+ ASSERT_OR_PRINT (b2 , error );
3775
+ }
3776
+
3777
+ ASSERT (bson_equal (b1 , b2 ));
3778
+ bson_destroy (b2 );
3779
+ bson_destroy (b1 );
3780
+ }
3781
+ }
3782
+
3649
3783
void
3650
3784
test_json_install (TestSuite * suite )
3651
3785
{
@@ -3839,6 +3973,7 @@ test_json_install (TestSuite *suite)
3839
3973
TestSuite_Add (suite ,
3840
3974
"/bson/as_json_with_opts/all_types" ,
3841
3975
test_bson_as_json_with_opts_all_types );
3976
+ TestSuite_Add (suite , "/bson/parse_array" , test_parse_array );
3842
3977
TestSuite_Add (suite ,
3843
3978
"/bson/decimal128_overflowing_exponent" ,
3844
3979
test_decimal128_overflowing_exponent );
0 commit comments