@@ -891,6 +891,37 @@ func TestDocument(t *testing.T) {
891
891
}
892
892
}
893
893
})
894
+ t .Run ("ToExtJSON" , func (t * testing.T ) {
895
+ t .Run ("Marshaling Error" , func (t * testing.T ) {
896
+ var doc * Document
897
+ _ , err := doc .ToExtJSONErr (false )
898
+ if err != ErrNilDocument {
899
+ t .Errorf ("Did not receive expected error. got %v; want %v" , err , ErrNilDocument )
900
+ }
901
+ })
902
+ t .Run ("Canonical" , func (t * testing.T ) {
903
+ doc := NewDocument (EC .String ("hello" , "world" ), EC .Double ("pi" , 3.14159 ))
904
+ want := `{"hello":"world","pi":{"$numberDouble":"3.14159"}}`
905
+ got , err := doc .ToExtJSONErr (true )
906
+ if err != nil {
907
+ t .Errorf ("Unexpected error while converting document to extended json: %v" , err )
908
+ }
909
+ if got != want {
910
+ t .Errorf ("Did not recieve expected result. got %s; want %s" , got , want )
911
+ }
912
+ })
913
+ t .Run ("Relaxed" , func (t * testing.T ) {
914
+ doc := NewDocument (EC .String ("hello" , "world" ), EC .Double ("pi" , 3.14159 ))
915
+ want := `{"hello":"world","pi":3.14159}`
916
+ got , err := doc .ToExtJSONErr (false )
917
+ if err != nil {
918
+ t .Errorf ("Unexpected error while converting document to extended json: %v" , err )
919
+ }
920
+ if got != want {
921
+ t .Errorf ("Did not recieve expected result. got %s; want %s" , got , want )
922
+ }
923
+ })
924
+ })
894
925
}
895
926
896
927
func testDocumentKeys (t * testing.T ) {
0 commit comments