Skip to content

Commit 350f7a7

Browse files
authored
Test case for NSMutableData replace range with nil
1 parent b29e914 commit 350f7a7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

TestFoundation/TestNSData.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class TestNSData: XCTestCase {
8787
("test_rangeOfData",test_rangeOfData),
8888
("test_initMutableDataWithLength", test_initMutableDataWithLength),
8989
("test_replaceBytes", test_replaceBytes),
90+
("test_replaceBytesWithNil", test_replaceBytesWithNil),
9091
("test_initDataWithCapacity", test_initDataWithCapacity),
9192
("test_initDataWithCount", test_initDataWithCount),
9293
("test_emptyStringToData", test_emptyStringToData),
@@ -426,6 +427,17 @@ class TestNSData: XCTestCase {
426427
XCTAssertEqual(mData, expected)
427428
}
428429

430+
func test_replaceBytesWithNil() {
431+
func makeData(_ data: [UInt8]) -> NSMutableData {
432+
return NSMutableData(bytes: data, length: data.count)
433+
}
434+
435+
let mData = makeData([1, 2, 3, 4, 5])
436+
mData.replaceBytes(in: NSMakeRange(1, 3), withBytes: nil, length: 0)
437+
let expected = makeData([1, 5])
438+
XCTAssertEqual(mData, expected)
439+
}
440+
429441
func test_initDataWithCapacity() {
430442
let data = Data(capacity: 123)
431443
XCTAssertEqual(data.count, 0)

0 commit comments

Comments
 (0)