Files
swift-nio/Tests/NIOFoundationCompatTests/ByteBufferView+MutableDataProtocol.swift
T
George Barnett 302dee3e1a Make ByteBufferView mutable (#1208)
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.
2019-11-27 10:25:15 +00:00

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]))
}
}