Skip to content

Commit dec6123

Browse files
committed
Adopt the central style
Applies the central swift-format configuration: - swift-format: mechanical reflow to the central line-length/wrapping rules across Sources and Tests. - Judgment fix: rename the single-letter locals `a`/`A` to `lowerA`/`upperA` in INCITS_4_1986.CaseConversion Tests.swift (AlwaysUseLowerCamelCase residue) and clean up a stray trailing-comma argument list in the same file's `#expect(...)` call (both test-only; no semantic change). - swiftlint --strict was already 0 residual before any judgment fixes were needed. - No Benchmarks target/product stanzas present in Package.swift; nothing to remove there.
1 parent 3ff6c50 commit dec6123

14 files changed

Lines changed: 189 additions & 58 deletions

Sources/ASCII/StringProtocol+INCITS_4_1986.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ extension StringProtocol {
5757
_ s: S,
5858
to lineEnding: INCITS_4_1986.FormatEffectors.Line.Ending
5959
) -> S {
60-
return .init(decoding: INCITS_4_1986.normalized([UInt8](s.utf8), to: lineEnding), as: UTF8.self)
60+
return .init(
61+
decoding: INCITS_4_1986.normalized([UInt8](s.utf8), to: lineEnding),
62+
as: UTF8.self
63+
)
6164
}
6265
// swiftlint:enable prefer_self_in_static_references
6366

@@ -215,7 +218,8 @@ extension StringProtocol {
215218
/// let s = String(ascii: codes) // "Hello"
216219
/// ```
217220
@inlinable
218-
public init<Codes: Sequence>(ascii codes: Codes) where Codes.Element == ASCII_Primitives.ASCII.Code {
221+
public init<Codes: Sequence>(ascii codes: Codes)
222+
where Codes.Element == ASCII_Primitives.ASCII.Code {
219223
self.init(decoding: codes.lazy.map(\.underlying), as: UTF8.self)
220224
}
221225

Tests/ASCII Tests/BrutalEdgeCases Tests.swift

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,48 @@ struct `Brutal` {
3535
func `exhaustive byte classification`(byte: UInt8) {
3636
// Every byte must be either ASCII or not - no exceptions
3737
let isASCII = byte <= 0x7F
38-
#expect(isAllASCII([Byte(byte)]) == isASCII, "Byte 0x\(String(byte, radix: 16)) classification inconsistent")
38+
#expect(
39+
isAllASCII([Byte(byte)]) == isASCII,
40+
"Byte 0x\(String(byte, radix: 16)) classification inconsistent"
41+
)
3942

4043
// Predicates must be consistent for all bytes
4144
if byte.ascii.isControl {
4245
// Control characters are never letters/digits
43-
#expect(!byte.ascii.isLetter, "Control byte 0x\(String(byte, radix: 16)) cannot be letter")
44-
#expect(!byte.ascii.isDigit, "Control byte 0x\(String(byte, radix: 16)) cannot be digit")
46+
#expect(
47+
!byte.ascii.isLetter,
48+
"Control byte 0x\(String(byte, radix: 16)) cannot be letter"
49+
)
50+
#expect(
51+
!byte.ascii.isDigit,
52+
"Control byte 0x\(String(byte, radix: 16)) cannot be digit"
53+
)
4554
}
4655

4756
// Visible implies printable
4857
if byte.ascii.isVisible {
49-
#expect(byte.ascii.isPrintable, "Visible byte 0x\(String(byte, radix: 16)) must be printable")
58+
#expect(
59+
byte.ascii.isPrintable,
60+
"Visible byte 0x\(String(byte, radix: 16)) must be printable"
61+
)
5062
}
5163
}
5264

5365
@Test(arguments: Array(UInt8(0)...UInt8(255)))
5466
func `case conversion idempotence for every byte`(byte: UInt8) {
5567
let upper = byte.ascii(case: .upper)
5668
let upperAgain = upper.ascii(case: .upper)
57-
#expect(upper == upperAgain, "Uppercase idempotence failed for 0x\(String(byte, radix: 16))")
69+
#expect(
70+
upper == upperAgain,
71+
"Uppercase idempotence failed for 0x\(String(byte, radix: 16))"
72+
)
5873

5974
let lower = byte.ascii(case: .lower)
6075
let lowerAgain = lower.ascii(case: .lower)
61-
#expect(lower == lowerAgain, "Lowercase idempotence failed for 0x\(String(byte, radix: 16))")
76+
#expect(
77+
lower == lowerAgain,
78+
"Lowercase idempotence failed for 0x\(String(byte, radix: 16))"
79+
)
6280
}
6381

6482
@Test(arguments: Array(UInt8(0)...UInt8(255)))
@@ -88,9 +106,15 @@ struct `Brutal` {
88106
if byte == UInt8.ascii.sp.underlying {
89107
#expect(!isControl && isPrintable)
90108
} else if byte <= 0x1F || byte == 0x7F {
91-
#expect(isControl && !isPrintable, "0x\(String(byte, radix: 16)) should be control, not printable")
109+
#expect(
110+
isControl && !isPrintable,
111+
"0x\(String(byte, radix: 16)) should be control, not printable"
112+
)
92113
} else {
93-
#expect(!isControl && isPrintable, "0x\(String(byte, radix: 16)) should be printable, not control")
114+
#expect(
115+
!isControl && isPrintable,
116+
"0x\(String(byte, radix: 16)) should be printable, not control"
117+
)
94118
}
95119
}
96120

@@ -109,14 +133,20 @@ struct `Brutal` {
109133
@Test(arguments: Array(UInt8(0)...UInt8(127)))
110134
func `letter implies alphanumeric`(byte: UInt8) {
111135
if byte.ascii.isLetter {
112-
#expect(byte.ascii.isAlphanumeric, "Letter 0x\(String(byte, radix: 16)) must be alphanumeric")
136+
#expect(
137+
byte.ascii.isAlphanumeric,
138+
"Letter 0x\(String(byte, radix: 16)) must be alphanumeric"
139+
)
113140
}
114141
}
115142

116143
@Test(arguments: Array(UInt8(0)...UInt8(127)))
117144
func `digit implies alphanumeric`(byte: UInt8) {
118145
if byte.ascii.isDigit {
119-
#expect(byte.ascii.isAlphanumeric, "Digit 0x\(String(byte, radix: 16)) must be alphanumeric")
146+
#expect(
147+
byte.ascii.isAlphanumeric,
148+
"Digit 0x\(String(byte, radix: 16)) must be alphanumeric"
149+
)
120150
}
121151
}
122152

@@ -126,13 +156,22 @@ struct `Brutal` {
126156
let isLower = byte.ascii.isLowercase
127157

128158
// Cannot be both
129-
#expect(!(isUpper && isLower), "Byte 0x\(String(byte, radix: 16)) cannot be both upper and lower")
159+
#expect(
160+
!(isUpper && isLower),
161+
"Byte 0x\(String(byte, radix: 16)) cannot be both upper and lower"
162+
)
130163

131164
// If letter, must be exactly one
132165
if byte.ascii.isLetter {
133-
#expect(isUpper != isLower, "Letter 0x\(String(byte, radix: 16)) must be exactly one of upper or lower")
166+
#expect(
167+
isUpper != isLower,
168+
"Letter 0x\(String(byte, radix: 16)) must be exactly one of upper or lower"
169+
)
134170
} else {
135-
#expect(!isUpper && !isLower, "Non-letter 0x\(String(byte, radix: 16)) cannot be upper or lower")
171+
#expect(
172+
!isUpper && !isLower,
173+
"Non-letter 0x\(String(byte, radix: 16)) cannot be upper or lower"
174+
)
136175
}
137176
}
138177
}
@@ -151,7 +190,10 @@ struct `Brutal` {
151190
]
152191

153192
for seq in multiByteSequences {
154-
#expect(!isAllASCII(seq), "Multi-byte UTF-8 \(seq.map { String($0.underlying, radix: 16) }) should fail")
193+
#expect(
194+
!isAllASCII(seq),
195+
"Multi-byte UTF-8 \(seq.map { String($0.underlying, radix: 16) }) should fail"
196+
)
155197
}
156198
}
157199

@@ -174,7 +216,10 @@ struct `Brutal` {
174216
func `look-alike characters not confused with ASCII`() {
175217
// Cyrillic 'а' looks like Latin 'a' but is U+0430 (multi-byte UTF-8)
176218
let cyrillicA = "а" // U+0430
177-
#expect(UInt8(ascii: Character(cyrillicA)) == nil, "Cyrillic 'а' should not convert to ASCII")
219+
#expect(
220+
UInt8(ascii: Character(cyrillicA)) == nil,
221+
"Cyrillic 'а' should not convert to ASCII"
222+
)
178223

179224
// Greek 'Α' looks like Latin 'A' but is U+0391
180225
let greekA = "Α" // U+0391
@@ -184,14 +229,20 @@ struct `Brutal` {
184229
@Test
185230
func `zero-width characters rejected`() {
186231
let zeroWidth = "\u{200B}" // Zero-width space
187-
#expect(UInt8(ascii: Character(zeroWidth)) == nil, "Zero-width space should be rejected")
232+
#expect(
233+
UInt8(ascii: Character(zeroWidth)) == nil,
234+
"Zero-width space should be rejected"
235+
)
188236
}
189237

190238
@Test
191239
func `combining characters rejected`() {
192240
// Combining diacritical marks
193241
let combining = "\u{0301}" // Combining acute accent
194-
#expect(UInt8(ascii: Character(combining)) == nil, "Combining character should be rejected")
242+
#expect(
243+
UInt8(ascii: Character(combining)) == nil,
244+
"Combining character should be rejected"
245+
)
195246
}
196247

197248
@Test
@@ -210,15 +261,20 @@ struct `Brutal` {
210261

211262
@Suite
212263
struct `Brutal - Buffer Boundaries` {
213-
@Test(arguments: [0, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 127, 128, 255, 256, 511, 512, 1023, 1024])
264+
@Test(arguments: [
265+
0, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, 127, 128, 255, 256, 511, 512, 1023, 1024,
266+
])
214267
func `validation at power-of-2 boundaries`(size: Int) {
215268
let validASCII: [Byte] = Array(repeating: Byte.ascii.A, count: size)
216269
#expect(isAllASCII(validASCII), "Valid ASCII array of size \(size) should pass")
217270

218271
var invalidASCII = validASCII
219272
if size > 0 {
220273
invalidASCII[size - 1] = 0x80
221-
#expect(!isAllASCII(invalidASCII), "Invalid ASCII array of size \(size) should fail")
274+
#expect(
275+
!isAllASCII(invalidASCII),
276+
"Invalid ASCII array of size \(size) should fail"
277+
)
222278
}
223279
}
224280

Tests/ASCII Tests/Character+INCITS_4_1986 Tests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ struct `Character Tests` {
6464
#expect(char.ascii.isAlphanumeric, "Character '\(char)' should be alphanumeric")
6565
}
6666

67-
@Test(arguments: [" ", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "+", "="])
67+
@Test(arguments: [
68+
" ", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "+", "=",
69+
])
6870
func `special characters are not alphanumeric`(char: Character) {
6971
#expect(!char.ascii.isAlphanumeric)
7072
}

Tests/ASCII Tests/EdgeCases Tests.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,20 @@ struct `Edge Cases Tests` {
228228
@Test
229229
func `all extended ASCII bytes invalid`() {
230230
for value in UInt8(0x80)...UInt8(0xFF) {
231-
#expect(!isAllASCII([Byte(value)]), "Byte 0x\(String(value, radix: 16)) should be invalid")
231+
#expect(
232+
!isAllASCII([Byte(value)]),
233+
"Byte 0x\(String(value, radix: 16)) should be invalid"
234+
)
232235
}
233236
}
234237

235238
@Test
236239
func `all standard ASCII bytes valid`() {
237240
// `Byte` is not Strideable per [API-BYTE-002]; iterate on UInt8
238241
// and bridge to Byte at the lift site.
239-
let allASCII: [Byte] = (UInt8.ascii.nul.underlying...UInt8.ascii.del.underlying).map(Byte.init)
242+
let allASCII: [Byte] = (UInt8.ascii.nul.underlying...UInt8.ascii.del.underlying).map(
243+
Byte.init
244+
)
240245
#expect(isAllASCII(allASCII))
241246
}
242247
}

Tests/ASCII Tests/INCITS_4_1986.CaseConversion Tests.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ struct `Case Conversion Tests` {
137137
struct `Case Conversion - Mathematical Properties` {
138138
@Test
139139
func `conversion offset is exactly 32`() {
140-
let a = UInt8(ascii: "a")!
141-
let A = UInt8(ascii: "A")!
142-
#expect(a - A == 32)
143-
#expect(a - A == INCITS_4_1986.Case.Conversion.offset)
140+
let lowerA = UInt8(ascii: "a")!
141+
let upperA = UInt8(ascii: "A")!
142+
#expect(lowerA - upperA == 32)
143+
#expect(lowerA - upperA == INCITS_4_1986.Case.Conversion.offset)
144144
}
145145

146146
@Test(
@@ -155,10 +155,7 @@ struct `Case Conversion Tests` {
155155
// Range iteration requires Strideable; `ASCII.Code` is not Strideable
156156
// per [API-BYTE-002], so drop to `.underlying` (UInt8) for the
157157
// a...z / A...Z enumeration.
158-
#expect(
159-
lower - upper == 32,
160-
161-
)
158+
#expect(lower - upper == 32)
162159
}
163160
}
164161
}

0 commit comments

Comments
 (0)