Skip to content

Commit e520e61

Browse files
rauhulmilseman
authored andcommitted
Fix SystemChar isLetter logic
- Fixes range expression in isLetter logic and adds test coverage.
1 parent 4f36710 commit e520e61

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

Sources/System/SystemString.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ extension SystemChar {
5353
internal var isLetter: Bool {
5454
guard isASCII else { return false }
5555
let asciiRaw: UInt8 = numericCast(rawValue)
56-
return (UInt8(ascii: "a") ..< UInt8(ascii: "z")).contains(asciiRaw) ||
57-
(UInt8(ascii: "A") ..< UInt8(ascii: "Z")).contains(asciiRaw)
56+
return (UInt8(ascii: "a") ... UInt8(ascii: "z")).contains(asciiRaw) ||
57+
(UInt8(ascii: "A") ... UInt8(ascii: "Z")).contains(asciiRaw)
5858
}
5959
}
6060

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
This source file is part of the Swift System open source project
3+
4+
Copyright (c) 2020 - 2021 Apple Inc. and the Swift System project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
*/
9+
10+
import XCTest
11+
12+
#if SYSTEM_PACKAGE
13+
@testable import SystemPackage
14+
#else
15+
@testable import System
16+
#endif
17+
18+
final class SystemCharTest: XCTestCase {
19+
func testIsLetter() {
20+
let valid = SystemString(
21+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
22+
for char in valid {
23+
XCTAssertTrue(char.isLetter)
24+
}
25+
26+
// non printable
27+
for value in 0..<(UInt8(ascii: " ")) {
28+
XCTAssertFalse(SystemChar(codeUnit: value).isLetter)
29+
}
30+
XCTAssertFalse(SystemChar(codeUnit: 0x7F).isLetter) // DEL
31+
32+
// misc other
33+
let invalid = SystemString(
34+
##" !"#$%&'()*+,-./0123456789:;<=>?@[\]^_`{|}~"##)
35+
for char in invalid {
36+
XCTAssertFalse(char.isLetter)
37+
}
38+
}
39+
}

Tests/SystemTests/XCTestManifests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ extension MockingTest {
9494
]
9595
}
9696

97+
extension SystemCharTest {
98+
// DO NOT MODIFY: This is autogenerated, use:
99+
// `swift test --generate-linuxmain`
100+
// to regenerate.
101+
static let __allTests__SystemCharTest = [
102+
("testIsLetter", testIsLetter),
103+
]
104+
}
105+
97106
extension SystemStringTest {
98107
// DO NOT MODIFY: This is autogenerated, use:
99108
// `swift test --generate-linuxmain`
@@ -115,6 +124,7 @@ public func __allTests() -> [XCTestCaseEntry] {
115124
testCase(FilePathTest.__allTests__FilePathTest),
116125
testCase(FilePermissionsTest.__allTests__FilePermissionsTest),
117126
testCase(MockingTest.__allTests__MockingTest),
127+
testCase(SystemCharTest.__allTests__SystemCharTest),
118128
testCase(SystemStringTest.__allTests__SystemStringTest),
119129
]
120130
}

0 commit comments

Comments
 (0)