Skip to content

Commit 9e15359

Browse files
author
Pouya Yarandi
committed
Add a test for trim with extensible messages
1 parent 03f5f0d commit 9e15359

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Tests/SwiftProtobufTests/Test_FieldMask.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ final class Test_FieldMask: XCTestCase, PBTestHelpers {
195195
XCTAssertEqual(message.optionalInt32, 0)
196196
XCTAssertEqual(message.optionalNestedMessage.bb, 2)
197197

198-
// Checks trim should does nothing with an empty fieldMask.
198+
// Checks trim should do nothing with an empty fieldMask.
199199
let r2 = message.trim(fieldMask: .init())
200200
XCTAssertFalse(r2)
201201

@@ -208,6 +208,25 @@ final class Test_FieldMask: XCTestCase, PBTestHelpers {
208208
XCTAssertFalse(r4)
209209
}
210210

211+
// Checks trim functionality for field masks when applies on a extensible message.
212+
func testTrimFieldsOfMessageWithExtension() throws {
213+
var message = SwiftProtoTesting_Fuzz_Message()
214+
message.singularInt32 = 1
215+
message.SwiftProtoTesting_Fuzz_singularInt32Ext = 1
216+
let mask = Google_Protobuf_FieldMask(protoPaths: ["singularString"])
217+
218+
// Checks trim should retain extensions while removes other fields.
219+
let r1 = message.trim(fieldMask: mask)
220+
XCTAssertTrue(r1)
221+
XCTAssertEqual(message.SwiftProtoTesting_Fuzz_singularInt32Ext, .init(1))
222+
XCTAssertEqual(message.singularInt32, .init(0))
223+
224+
// Checks trim should do nothing (fields are already removed) and still retain extension fields.
225+
let r2 = message.trim(fieldMask: mask)
226+
XCTAssertFalse(r2)
227+
XCTAssertEqual(message.SwiftProtoTesting_Fuzz_singularInt32Ext, .init(1))
228+
}
229+
211230
// Checks `isPathValid` func
212231
// 1. Valid primitive path.
213232
// 2. Valid nested path.

0 commit comments

Comments
 (0)