@@ -232,12 +232,15 @@ final class Test_FieldMask: XCTestCase, PBTestHelpers {
232
232
// 2. Valid nested path.
233
233
// 3. Invalid primitive path.
234
234
// 4, 5. Invalid nested path.
235
+ // 6, 7. Invalid path after map and repeated.
235
236
func testIsPathValid( ) {
236
237
XCTAssertTrue ( SwiftProtoTesting_TestAllTypes . isPathValid ( " optional_int32 " ) )
237
238
XCTAssertTrue ( SwiftProtoTesting_TestAllTypes . isPathValid ( " optional_nested_message.bb " ) )
238
239
XCTAssertFalse ( SwiftProtoTesting_TestAllTypes . isPathValid ( " optional_int " ) )
239
240
XCTAssertFalse ( SwiftProtoTesting_TestAllTypes . isPathValid ( " optional_nested_message.bc " ) )
240
241
XCTAssertFalse ( SwiftProtoTesting_TestAllTypes . isPathValid ( " optional_nested_message.bb.a " ) )
242
+ XCTAssertFalse ( SwiftProtoTesting_TestAllTypes . isPathValid ( " repeatedInt32.a " ) )
243
+ XCTAssertFalse ( SwiftProtoTesting_Fuzz_Message . isPathValid ( " map_bool_int32.a " ) )
241
244
}
242
245
243
246
// Checks `isValid` func of FieldMask.
@@ -549,51 +552,73 @@ final class Test_FieldMask: XCTestCase, PBTestHelpers {
549
552
550
553
// Checks merge could be done for non-optional paths.
551
554
func testMergeNonOptionalValues( ) throws {
552
- let mask = Google_Protobuf_FieldMask ( protoPaths: [ " value " ] )
553
-
554
- var m1 = Google_Protobuf_DoubleValue ( 1 )
555
- let m2 = Google_Protobuf_DoubleValue ( )
556
- try m1. merge ( with: m2, fieldMask: mask)
557
- XCTAssertEqual ( m1. value, m2. value)
558
-
559
- var m3 = Google_Protobuf_FloatValue ( 1 )
560
- let m4 = Google_Protobuf_FloatValue ( )
561
- try m3. merge ( with: m4, fieldMask: mask)
562
- XCTAssertEqual ( m3. value, m4. value)
563
-
564
- var m5 = Google_Protobuf_Int64Value ( 1 )
565
- let m6 = Google_Protobuf_Int64Value ( )
566
- try m5. merge ( with: m6, fieldMask: mask)
567
- XCTAssertEqual ( m5. value, m6. value)
568
-
569
- var m7 = Google_Protobuf_Int32Value ( 1 )
570
- let m8 = Google_Protobuf_Int32Value ( )
571
- try m7. merge ( with: m8, fieldMask: mask)
572
- XCTAssertEqual ( m7. value, m8. value)
573
-
574
- var m9 = Google_Protobuf_UInt64Value ( 1 )
575
- let m10 = Google_Protobuf_UInt64Value ( )
576
- try m9. merge ( with: m10, fieldMask: mask)
577
- XCTAssertEqual ( m9. value, m10. value)
578
-
579
- var m11 = Google_Protobuf_UInt32Value ( 1 )
580
- let m12 = Google_Protobuf_UInt32Value ( )
581
- try m11. merge ( with: m12, fieldMask: mask)
582
- XCTAssertEqual ( m11. value, m12. value)
583
-
584
- var m13 = Google_Protobuf_BoolValue ( true )
585
- let m14 = Google_Protobuf_BoolValue ( )
586
- try m13. merge ( with: m14, fieldMask: mask)
587
- XCTAssertEqual ( m13. value, m14. value)
588
-
589
- var m15 = Google_Protobuf_StringValue ( " str " )
590
- let m16 = Google_Protobuf_StringValue ( )
591
- try m15. merge ( with: m16, fieldMask: mask)
592
- XCTAssertEqual ( m15. value, m16. value)
593
-
594
- var m17 = Google_Protobuf_BytesValue ( " str " . data ( using: . utf8) ?? . init( ) )
595
- let m18 = Google_Protobuf_BytesValue ( )
596
- try m17. merge ( with: m18, fieldMask: mask)
597
- XCTAssertEqual ( m17. value, m18. value)
555
+ var m1 = try SwiftProtoTesting_Proto3_TestAllTypes . with { m in
556
+ m. optionalInt32 = 1
557
+ m. optionalInt64 = 1
558
+ m. optionalDouble = 1
559
+ m. optionalFloat = 1
560
+ m. optionalString = " str "
561
+ m. optionalBool = true
562
+ m. optionalBytes = try XCTUnwrap ( " str " . data ( using: . utf8) )
563
+ m. optionalUint32 = 1
564
+ m. optionalUint64 = 1
565
+ m. optionalSint32 = 1
566
+ m. optionalSint64 = 1
567
+ m. optionalFixed32 = 1
568
+ m. optionalFixed64 = 1
569
+ m. optionalSfixed32 = 1
570
+ m. optionalSfixed64 = 1
571
+ m. optionalNestedEnum = . bar
572
+ }
573
+ let m2 = SwiftProtoTesting_Proto3_TestAllTypes ( )
574
+ try m1. merge ( with: m2, fieldMask: . init( protoPaths: [
575
+ " optional_int32 " ,
576
+ " optional_int64 " ,
577
+ " optional_double " ,
578
+ " optional_float " ,
579
+ " optional_string " ,
580
+ " optional_bool " ,
581
+ " optional_bytes " ,
582
+ " optional_uint32 " ,
583
+ " optional_uint64 " ,
584
+ " optional_sint32 " ,
585
+ " optional_sint64 " ,
586
+ " optional_fixed32 " ,
587
+ " optional_fixed64 " ,
588
+ " optional_sfixed32 " ,
589
+ " optional_sfixed64 " ,
590
+ " optional_nested_enum "
591
+ ] ) )
592
+ XCTAssertEqual ( m1. optionalInt32, m2. optionalInt32)
593
+ XCTAssertEqual ( m1. optionalInt64, m2. optionalInt64)
594
+ XCTAssertEqual ( m1. optionalDouble, m2. optionalDouble)
595
+ XCTAssertEqual ( m1. optionalFloat, m2. optionalFloat)
596
+ XCTAssertEqual ( m1. optionalString, m2. optionalString)
597
+ XCTAssertEqual ( m1. optionalBool, m2. optionalBool)
598
+ XCTAssertEqual ( m1. optionalBytes, m2. optionalBytes)
599
+ XCTAssertEqual ( m1. optionalUint32, m2. optionalUint32)
600
+ XCTAssertEqual ( m1. optionalUint64, m2. optionalUint64)
601
+ XCTAssertEqual ( m1. optionalSint32, m2. optionalSint32)
602
+ XCTAssertEqual ( m1. optionalSint64, m2. optionalSint64)
603
+ XCTAssertEqual ( m1. optionalFixed32, m2. optionalFixed32)
604
+ XCTAssertEqual ( m1. optionalFixed64, m2. optionalFixed64)
605
+ XCTAssertEqual ( m1. optionalSfixed32, m2. optionalSfixed32)
606
+ XCTAssertEqual ( m1. optionalSfixed64, m2. optionalSfixed64)
607
+ XCTAssertEqual ( m1. optionalNestedEnum, m2. optionalNestedEnum)
608
+ XCTAssertEqual ( m1. optionalSint32, m2. optionalSint32)
609
+ }
610
+
611
+ // Checks if merge works with nested proto messages
612
+ func testMergeNestedMessages( ) throws {
613
+ var m1 = SwiftProtoTesting_Fuzz_Message ( )
614
+ let m2 = SwiftProtoTesting_Fuzz_Message . with { m in
615
+ m. singularMessage = . with { _m in
616
+ _m. singularMessage = . with { __m in
617
+ __m. singularInt32 = 1
618
+ }
619
+ }
620
+ }
621
+ try m1. merge ( with: m2, fieldMask: . init( protoPaths: [ " singular_message.singular_message.singular_int32 " ] ) )
622
+ XCTAssertEqual ( m1. singularMessage. singularMessage. singularInt32, Int32 ( 1 ) )
598
623
}
599
624
}
0 commit comments