@@ -334,6 +334,15 @@ final class Test_FieldMask: XCTestCase, PBTestHelpers {
334
334
XCTAssertThrowsError ( try Google_Protobuf_FieldMask ( fieldNumbers: [ 10 ] , of: SwiftProtoTesting_TestAny . self) )
335
335
}
336
336
337
+ // Checks that json names of paths should not be contained in mask field with allFieldsOf init.
338
+ func testFieldMaskAllPathsWithUniqueName( ) {
339
+ let mask = Google_Protobuf_FieldMask ( allFieldsOf: SwiftProtoTesting_Fuzz_Message . self)
340
+ // proto name is included
341
+ XCTAssertTrue ( mask. paths. contains ( " SingularGroup " ) )
342
+ // json name is not included
343
+ XCTAssertFalse ( mask. paths. contains ( " singulargroup " ) )
344
+ }
345
+
337
346
// Checks `union` func of fieldMask.
338
347
func testUnionFieldMasks( ) throws {
339
348
let m1 = Google_Protobuf_FieldMask ( protoPaths: [ " a " , " b " ] )
@@ -787,4 +796,21 @@ final class Test_FieldMask: XCTestCase, PBTestHelpers {
787
796
try m1. merge ( with: m2, fieldMask: . init( protoPaths: [ " SingularGroup.group_field " ] ) )
788
797
XCTAssertEqual ( m1. singularGroup. groupField, m2. singularGroup. groupField)
789
798
}
799
+
800
+ // Checks that merging with json path should do nothing. Path should only be merged using proto names.
801
+ func testMergeFieldWithJSONName( ) throws {
802
+ var m1 = SwiftProtoTesting_Fuzz_Message ( )
803
+ let m2 = SwiftProtoTesting_Fuzz_Message . with { m in
804
+ m. singularGroup = . with { $0. groupField = 1 }
805
+ }
806
+ // should do nothing with json path (should not merge)
807
+ try m1. merge ( with: m2, fieldMask: . with( { $0. paths = [ " singulargroup " ] } ) )
808
+ XCTAssertNotEqual ( m1. singularGroup, m2. singularGroup)
809
+ // should merge with proto path
810
+ try m1. merge ( with: m2, fieldMask: . with( { $0. paths = [ " SingularGroup " ] } ) )
811
+ XCTAssertEqual ( m1. singularGroup, m2. singularGroup)
812
+ // should do nothing with json path (do not clear field)
813
+ try m1. merge ( with: m2, fieldMask: . with( { $0. paths = [ " singulargroup " ] } ) )
814
+ XCTAssertEqual ( m1. singularGroup, m2. singularGroup)
815
+ }
790
816
}
0 commit comments