mirror of
https://github.com/apple/swift-system
synced 2026-11-23 04:34:26 +00:00
The platform character type is different across Unix and Windows. Explicitly convert the value to the expected type.
40 lines
1019 B
Swift
40 lines
1019 B
Swift
/*
|
|
This source file is part of the Swift System open source project
|
|
|
|
Copyright (c) 2020 - 2021 Apple Inc. and the Swift System project authors
|
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
|
|
|
See https://swift.org/LICENSE.txt for license information
|
|
*/
|
|
|
|
import XCTest
|
|
|
|
#if SYSTEM_PACKAGE
|
|
@testable import SystemPackage
|
|
#else
|
|
@testable import System
|
|
#endif
|
|
|
|
final class SystemCharTest: XCTestCase {
|
|
func testIsLetter() {
|
|
let valid = SystemString(
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
for char in valid {
|
|
XCTAssertTrue(char.isLetter)
|
|
}
|
|
|
|
// non printable
|
|
for value in 0..<(UInt8(ascii: " ")) {
|
|
XCTAssertFalse(SystemChar(codeUnit: CInterop.PlatformUnicodeEncoding.CodeUnit(value)).isLetter)
|
|
}
|
|
XCTAssertFalse(SystemChar(codeUnit: 0x7F).isLetter) // DEL
|
|
|
|
// misc other
|
|
let invalid = SystemString(
|
|
##" !"#$%&'()*+,-./0123456789:;<=>?@[\]^_`{|}~"##)
|
|
for char in invalid {
|
|
XCTAssertFalse(char.isLetter)
|
|
}
|
|
}
|
|
}
|