Skip to content

Commit

Permalink
Move compiler test inside test functions and throw XCTSkip
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Nov 21, 2024
1 parent f6f7576 commit 4cf7b20
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Tests/NIOCoreTests/ByteBufferTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1315,29 +1315,37 @@ class ByteBufferTest: XCTestCase {
XCTAssertEqual("a", buf.readString(length: 1))
}

#if compiler(>=6)
@available(macOS 15, iOS 18, tvOS 18, watchOS 11, *)
func testReadUTF8ValidatedString() throws {
#if compiler(>=6)
buf.clear()
let expected = "hello"
buf.writeString(expected)
let actual = try buf.readUTF8ValidatedString(length: expected.utf8.count)
XCTAssertEqual(expected, actual)
XCTAssertEqual("", try buf.readUTF8ValidatedString(length: 0))
XCTAssertNil(try buf.readUTF8ValidatedString(length: 1))
#else
throw XCTSkip("'readUTF8ValidatedString' is only available in Swift 6 and later")
#endif // compiler(>=6)
}

@available(macOS 15, iOS 18, tvOS 18, watchOS 11, *)
func testGetUTF8ValidatedString() throws {
#if compiler(>=6)
buf.clear()
let expected = "hello, goodbye"
buf.writeString(expected)
let actual = try buf.getUTF8ValidatedString(at: 7, length: 7)
XCTAssertEqual("goodbye", actual)
#else
throw XCTSkip("'getUTF8ValidatedString' is only available in Swift 6 and later")
#endif // compiler(>=6)
}

@available(macOS 15, iOS 18, tvOS 18, watchOS 11, *)
func testReadUTF8InvalidString() throws {
#if compiler(>=6)
buf.clear()
buf.writeBytes([UInt8](repeating: 255, count: 16))
XCTAssertThrowsError(try buf.readUTF8ValidatedString(length: 16)) { error in
Expand All @@ -1349,8 +1357,10 @@ class ByteBufferTest: XCTestCase {
}
}
XCTAssertEqual(buf.readableBytes, 16)
#else
throw XCTSkip("'readUTF8ValidatedString' is only available in Swift 6 and later")
#endif // compiler(>=6)
}
#endif // compiler(>=6)

func testSetIntegerBeyondCapacity() throws {
var buf = ByteBufferAllocator().buffer(capacity: 32)
Expand Down

0 comments on commit 4cf7b20

Please sign in to comment.