@@ -229,18 +229,21 @@ final class Test_FieldMask: XCTestCase, PBTestHelpers {
229
229
230
230
// Checks `isPathValid` func
231
231
// 1. Valid primitive path.
232
- // 2. Valid nested path.
233
- // 3. Invalid primitive path.
234
- // 4, 5. Invalid nested path.
235
- // 6, 7. Invalid path after map and repeated.
232
+ // 2, 3. Valid nested path. (for message and group)
233
+ // 4. Invalid primitive path.
234
+ // 5, 6. Invalid nested path.
235
+ // 7, 8. Invalid path after map and repeated.
236
+ // 9. Invalid path after group.
236
237
func testIsPathValid( ) {
237
238
XCTAssertTrue ( SwiftProtoTesting_TestAllTypes . isPathValid ( " optional_int32 " ) )
238
239
XCTAssertTrue ( SwiftProtoTesting_TestAllTypes . isPathValid ( " optional_nested_message.bb " ) )
240
+ XCTAssertTrue ( SwiftProtoTesting_Fuzz_Message . isPathValid ( " SingularGroup.group_field " ) )
239
241
XCTAssertFalse ( SwiftProtoTesting_TestAllTypes . isPathValid ( " optional_int " ) )
240
242
XCTAssertFalse ( SwiftProtoTesting_TestAllTypes . isPathValid ( " optional_nested_message.bc " ) )
241
243
XCTAssertFalse ( SwiftProtoTesting_TestAllTypes . isPathValid ( " optional_nested_message.bb.a " ) )
242
244
XCTAssertFalse ( SwiftProtoTesting_TestAllTypes . isPathValid ( " repeatedInt32.a " ) )
243
245
XCTAssertFalse ( SwiftProtoTesting_Fuzz_Message . isPathValid ( " map_bool_int32.a " ) )
246
+ XCTAssertFalse ( SwiftProtoTesting_Fuzz_Message . isPathValid ( " SingularGroup.a " ) )
244
247
}
245
248
246
249
// Checks `isValid` func of FieldMask.
@@ -530,6 +533,148 @@ final class Test_FieldMask: XCTestCase, PBTestHelpers {
530
533
XCTAssertEqual ( m1. mapInt32Message, m2. mapInt32Message)
531
534
}
532
535
536
+ // Checks whether a group of fields could be merged without merging the others.
537
+ func testMergeFieldsPartially( ) throws {
538
+ var m1 = SwiftProtoTesting_Fuzz_Message ( )
539
+ let m2 = SwiftProtoTesting_Fuzz_Message . with { m in
540
+ m. singularInt32 = 1
541
+ m. singularInt64 = 1
542
+ m. singularUint32 = 1
543
+ m. singularUint64 = 1
544
+ m. singularSint32 = 1
545
+ m. singularSint64 = 1
546
+ m. singularFixed32 = 1
547
+ m. singularFixed64 = 1
548
+ m. singularSfixed32 = 1
549
+ m. singularSfixed64 = 1
550
+ m. singularFloat = 1
551
+ m. singularDouble = 1
552
+ m. singularBool = true
553
+ m. singularString = " str "
554
+ m. singularBytes = " str " . data ( using: . utf8) ?? . init( )
555
+ m. singularEnum = . two
556
+ m. singularGroup = . with { $0. groupField = 1 }
557
+ m. singularMessage = . with { $0. singularInt32 = 1 }
558
+ m. repeatedInt32 = [ 1 ]
559
+ m. repeatedInt64 = [ 1 ]
560
+ m. repeatedUint32 = [ 1 ]
561
+ m. repeatedUint64 = [ 1 ]
562
+ m. repeatedSint32 = [ 1 ]
563
+ m. repeatedSint64 = [ 1 ]
564
+ m. repeatedFixed32 = [ 1 ]
565
+ m. repeatedFixed64 = [ 1 ]
566
+ m. repeatedSfixed32 = [ 1 ]
567
+ m. repeatedSfixed64 = [ 1 ]
568
+ m. repeatedFloat = [ 1 ]
569
+ m. repeatedDouble = [ 1 ]
570
+ m. repeatedBool = [ true ]
571
+ m. repeatedString = [ " str " ]
572
+ m. repeatedBytes = [ " str " . data ( using: . utf8) ?? . init( ) ]
573
+ m. repeatedEnum = [ . two]
574
+ m. repeatedGroup = [ . with { $0. groupField = 1 } ]
575
+ m. repeatedMessage = [ . with { $0. singularInt32 = 1 } ]
576
+ m. o = . oneofInt32( 1 )
577
+ m. repeatedPackedInt32 = [ 1 ]
578
+ m. repeatedPackedInt64 = [ 1 ]
579
+ m. repeatedPackedUint32 = [ 1 ]
580
+ m. repeatedPackedUint64 = [ 1 ]
581
+ m. repeatedPackedSint32 = [ 1 ]
582
+ m. repeatedPackedSint64 = [ 1 ]
583
+ m. repeatedPackedFixed32 = [ 1 ]
584
+ m. repeatedPackedFixed64 = [ 1 ]
585
+ m. repeatedPackedSfixed32 = [ 1 ]
586
+ m. repeatedPackedSfixed64 = [ 1 ]
587
+ m. repeatedPackedFloat = [ 1 ]
588
+ m. repeatedPackedDouble = [ 1 ]
589
+ m. repeatedPackedBool = [ true ]
590
+ m. repeatedPackedEnum = [ . two]
591
+ m. mapInt32Int32 = [ 1 : 1 ]
592
+ m. mapInt32Int64 = [ 1 : 1 ]
593
+ m. mapInt32Uint32 = [ 1 : 1 ]
594
+ m. mapInt32Uint64 = [ 1 : 1 ]
595
+ m. mapInt32Sint32 = [ 1 : 1 ]
596
+ m. mapInt32Sint64 = [ 1 : 1 ]
597
+ m. mapInt32Fixed32 = [ 1 : 1 ]
598
+ m. mapInt32Fixed64 = [ 1 : 1 ]
599
+ m. mapInt32AnEnum = [ 1 : . one]
600
+ m. mapInt32Message = [ 1 : . init( ) ]
601
+ }
602
+ let mask = Google_Protobuf_FieldMask ( protoPaths: [
603
+ " singular_int32 " ,
604
+ " singular_int64 " ,
605
+ " singular_uint32 " ,
606
+ " singular_uint64 " ,
607
+ " singular_sint32 " ,
608
+ " singular_sint64 " ,
609
+ " singular_fixed32 " ,
610
+ " singular_fixed64 " ,
611
+ " singular_sfixed32 " ,
612
+ " singular_sfixed64 "
613
+ ] )
614
+ try m1. merge ( with: m2, fieldMask: mask)
615
+ XCTAssertEqual ( m1. singularInt32, m2. singularInt32)
616
+ XCTAssertEqual ( m1. singularInt64, m2. singularInt64)
617
+ XCTAssertEqual ( m1. singularUint32, m2. singularUint32)
618
+ XCTAssertEqual ( m1. singularUint64, m2. singularUint64)
619
+ XCTAssertEqual ( m1. singularSint32, m2. singularSint32)
620
+ XCTAssertEqual ( m1. singularSint64, m2. singularSint64)
621
+ XCTAssertEqual ( m1. singularFixed32, m2. singularFixed32)
622
+ XCTAssertEqual ( m1. singularFixed64, m2. singularFixed64)
623
+ XCTAssertEqual ( m1. singularSfixed32, m2. singularSfixed32)
624
+ XCTAssertEqual ( m1. singularSfixed64, m2. singularSfixed64)
625
+ XCTAssertNotEqual ( m1. singularFloat, m2. singularFloat)
626
+ XCTAssertNotEqual ( m1. singularDouble, m2. singularDouble)
627
+ XCTAssertNotEqual ( m1. singularBool, m2. singularBool)
628
+ XCTAssertNotEqual ( m1. singularString, m2. singularString)
629
+ XCTAssertNotEqual ( m1. singularBytes, m2. singularBytes)
630
+ XCTAssertNotEqual ( m1. singularEnum, m2. singularEnum)
631
+ XCTAssertNotEqual ( m1. singularGroup, m2. singularGroup)
632
+ XCTAssertNotEqual ( m1. singularMessage, m2. singularMessage)
633
+ XCTAssertNotEqual ( m1. repeatedInt32, m2. repeatedInt32)
634
+ XCTAssertNotEqual ( m1. repeatedInt64, m2. repeatedInt64)
635
+ XCTAssertNotEqual ( m1. repeatedUint32, m2. repeatedUint32)
636
+ XCTAssertNotEqual ( m1. repeatedUint64, m2. repeatedUint64)
637
+ XCTAssertNotEqual ( m1. repeatedSint32, m2. repeatedSint32)
638
+ XCTAssertNotEqual ( m1. repeatedSint64, m2. repeatedSint64)
639
+ XCTAssertNotEqual ( m1. repeatedFixed32, m2. repeatedFixed32)
640
+ XCTAssertNotEqual ( m1. repeatedFixed64, m2. repeatedFixed64)
641
+ XCTAssertNotEqual ( m1. repeatedSfixed32, m2. repeatedSfixed32)
642
+ XCTAssertNotEqual ( m1. repeatedSfixed64, m2. repeatedSfixed64)
643
+ XCTAssertNotEqual ( m1. repeatedFloat, m2. repeatedFloat)
644
+ XCTAssertNotEqual ( m1. repeatedDouble, m2. repeatedDouble)
645
+ XCTAssertNotEqual ( m1. repeatedBool, m2. repeatedBool)
646
+ XCTAssertNotEqual ( m1. repeatedString, m2. repeatedString)
647
+ XCTAssertNotEqual ( m1. repeatedBytes, m2. repeatedBytes)
648
+ XCTAssertNotEqual ( m1. repeatedEnum, m2. repeatedEnum)
649
+ XCTAssertNotEqual ( m1. repeatedGroup, m2. repeatedGroup)
650
+ XCTAssertNotEqual ( m1. repeatedMessage, m2. repeatedMessage)
651
+ XCTAssertNotEqual ( m1. o, m2. o)
652
+ XCTAssertNotEqual ( m1. repeatedPackedInt32, m2. repeatedPackedInt32)
653
+ XCTAssertNotEqual ( m1. repeatedPackedInt64, m2. repeatedPackedInt64)
654
+ XCTAssertNotEqual ( m1. repeatedPackedUint32, m2. repeatedPackedUint32)
655
+ XCTAssertNotEqual ( m1. repeatedPackedUint64, m2. repeatedPackedUint64)
656
+ XCTAssertNotEqual ( m1. repeatedPackedSint32, m2. repeatedPackedSint32)
657
+ XCTAssertNotEqual ( m1. repeatedPackedSint64, m2. repeatedPackedSint64)
658
+ XCTAssertNotEqual ( m1. repeatedPackedFixed32, m2. repeatedPackedFixed32)
659
+ XCTAssertNotEqual ( m1. repeatedPackedFixed64, m2. repeatedPackedFixed64)
660
+ XCTAssertNotEqual ( m1. repeatedPackedSfixed32, m2. repeatedPackedSfixed32)
661
+ XCTAssertNotEqual ( m1. repeatedPackedSfixed64, m2. repeatedPackedSfixed64)
662
+ XCTAssertNotEqual ( m1. repeatedPackedFloat, m2. repeatedPackedFloat)
663
+ XCTAssertNotEqual ( m1. repeatedPackedDouble, m2. repeatedPackedDouble)
664
+ XCTAssertNotEqual ( m1. repeatedPackedBool, m2. repeatedPackedBool)
665
+ XCTAssertNotEqual ( m1. repeatedPackedEnum, m2. repeatedPackedEnum)
666
+ XCTAssertNotEqual ( m1. mapInt32Int32, m2. mapInt32Int32)
667
+ XCTAssertNotEqual ( m1. mapInt32Int64, m2. mapInt32Int64)
668
+ XCTAssertNotEqual ( m1. mapInt32Uint32, m2. mapInt32Uint32)
669
+ XCTAssertNotEqual ( m1. mapInt32Uint64, m2. mapInt32Uint64)
670
+ XCTAssertNotEqual ( m1. mapInt32Sint32, m2. mapInt32Sint32)
671
+ XCTAssertNotEqual ( m1. mapInt32Sint64, m2. mapInt32Sint64)
672
+ XCTAssertNotEqual ( m1. mapInt32Fixed32, m2. mapInt32Fixed32)
673
+ XCTAssertNotEqual ( m1. mapInt32Fixed64, m2. mapInt32Fixed64)
674
+ XCTAssertNotEqual ( m1. mapInt32AnEnum, m2. mapInt32AnEnum)
675
+ XCTAssertNotEqual ( m1. mapInt32Message, m2. mapInt32Message)
676
+ }
677
+
533
678
// Checks merge could be done for an optional path with nil value.
534
679
func testMergeOptionalValue( ) throws {
535
680
var m1 = SwiftProtoTesting_Fuzz_Message . with { m in
@@ -618,7 +763,28 @@ final class Test_FieldMask: XCTestCase, PBTestHelpers {
618
763
}
619
764
}
620
765
}
621
- try m1. merge ( with: m2, fieldMask: . init( protoPaths: [ " singular_message.singular_message.singular_int32 " ] ) )
766
+ let m3 = SwiftProtoTesting_Fuzz_Message . with { m in
767
+ m. singularMessage = . with { _m in
768
+ _m. singularMessage = . with { __m in
769
+ __m. singularInt32 = 2
770
+ }
771
+ }
772
+ }
773
+ try m1. merge ( with: m2, fieldMask: . init( protoPaths: [ " singular_message.singular_message " ] ) )
622
774
XCTAssertEqual ( m1. singularMessage. singularMessage. singularInt32, Int32 ( 1 ) )
775
+ try m1. merge ( with: m3, fieldMask: . init( protoPaths: [ " singular_message.singular_message.singular_int32 " ] ) )
776
+ XCTAssertEqual ( m1. singularMessage. singularMessage. singularInt32, Int32 ( 2 ) )
777
+ }
778
+
779
+ // Checks merging nested path inside groups
780
+ func testMergeNestedGroups( ) throws {
781
+ var m1 = SwiftProtoTesting_Fuzz_Message ( )
782
+ let m2 = SwiftProtoTesting_Fuzz_Message . with { m in
783
+ m. singularGroup = . with { _m in
784
+ _m. groupField = 1
785
+ }
786
+ }
787
+ try m1. merge ( with: m2, fieldMask: . init( protoPaths: [ " SingularGroup.group_field " ] ) )
788
+ XCTAssertEqual ( m1. singularGroup. groupField, m2. singularGroup. groupField)
623
789
}
624
790
}
0 commit comments