mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
Motivation: ByteBufferView isn't a mutable collection, but it probably should be. Modifications: - Add `copyBytes(at:to:length)` to `ByteBuffer` to copy bytes from a readable region of a buffer to another part of the buffer - Conform `ByteBufferView` to `MutableCollection`, `RangeReplaceableCollection` and `MutableDataProtocol` - Add an allocation counting test Result: `ByteBufferView` is now mutable.
36 lines
1.0 KiB
Swift
36 lines
1.0 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2019 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import Foundation
|
|
import XCTest
|
|
import NIO
|
|
import NIOFoundationCompat
|
|
|
|
class ByteBufferViewDataProtocolTests: XCTestCase {
|
|
|
|
func testResetBytes() {
|
|
var view = ByteBufferView()
|
|
view.resetBytes(in: view.indices)
|
|
XCTAssertTrue(view.elementsEqual([]))
|
|
|
|
view.replaceSubrange(view.indices, with: [1, 2, 3, 4, 5])
|
|
|
|
view.resetBytes(in: 0..<2)
|
|
XCTAssertTrue(view.elementsEqual([0, 0, 3, 4, 5]))
|
|
|
|
view.resetBytes(in: 2...4)
|
|
XCTAssertTrue(view.elementsEqual([0, 0, 0, 0, 0]))
|
|
}
|
|
}
|