diff --git a/Sources/NIOHTTP2/HTTP2StreamID.swift b/Sources/NIOHTTP2/HTTP2StreamID.swift index 7a4a13c..ce748c9 100644 --- a/Sources/NIOHTTP2/HTTP2StreamID.swift +++ b/Sources/NIOHTTP2/HTTP2StreamID.swift @@ -104,6 +104,20 @@ extension HTTP2StreamID: ExpressibleByIntegerLiteral { } +// MARK:- Strideable conformance for HTTP2StreamID +extension HTTP2StreamID: Strideable { + public typealias Stride = Int + + public func advanced(by n: Stride) -> HTTP2StreamID { + return HTTP2StreamID(self.networkStreamID + Int32(n)) + } + + public func distance(to other: HTTP2StreamID) -> Stride { + return Int(other.networkStreamID - self.networkStreamID) + } +} + + // MARK:- Helper initializers for integer conversion. public extension Int { /// Create an Int holding the integer value of this streamID. diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index d0789ef..7e1e72b 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -43,5 +43,6 @@ import XCTest testCase(OutboundFlowControlBufferTests.allTests), testCase(ReentrancyTests.allTests), testCase(SimpleClientServerTests.allTests), + testCase(StreamIDTests.allTests), ]) #endif diff --git a/Tests/NIOHTTP2Tests/StreamIDTests+XCTest.swift b/Tests/NIOHTTP2Tests/StreamIDTests+XCTest.swift new file mode 100644 index 0000000..54523f4 --- /dev/null +++ b/Tests/NIOHTTP2Tests/StreamIDTests+XCTest.swift @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftNIO open source project +// +// Copyright (c) 2017-2018 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 +// +//===----------------------------------------------------------------------===// +// +// StreamIDTests+XCTest.swift +// +import XCTest + +/// +/// NOTE: This file was generated by generate_linux_tests.rb +/// +/// Do NOT edit this file directly as it will be regenerated automatically when needed. +/// + +extension StreamIDTests { + + static var allTests : [(String, (StreamIDTests) -> () throws -> Void)] { + return [ + ("testStreamIDsAreStrideable", testStreamIDsAreStrideable), + ] + } +} + diff --git a/Tests/NIOHTTP2Tests/StreamIDTests.swift b/Tests/NIOHTTP2Tests/StreamIDTests.swift new file mode 100644 index 0000000..f9a3e62 --- /dev/null +++ b/Tests/NIOHTTP2Tests/StreamIDTests.swift @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 XCTest +import NIOHTTP2 + + +final class StreamIDTests: XCTestCase { + func testStreamIDsAreStrideable() { + XCTAssertEqual(Array(HTTP2StreamID(1)..