style: bring four files back under the swiftformat gate

swiftformat --lint failed on these pre-existing files and the pre-push
hook checks the whole tree, blocking every push until they conform.
The wrapped if bodies pushed YAMLTestSuiteGapsTests over the 400-line
lint limit, so its private JSONStreamScanner helper moves to its own
support file.
This commit is contained in:
Mihaela Mihaljevic 2026-07-12 13:29:05 +02:00
parent 20f080a9f7
commit 6fa49b7ffc
5 changed files with 94 additions and 67 deletions

View File

@ -120,10 +120,18 @@ extension PureYAML.Parsing.LibYAML.Scanner {
}
private func utf8Width(of octet: UInt8) -> Int {
if octet & 0x80 == 0x00 { return 1 }
if octet & 0xE0 == 0xC0 { return 2 }
if octet & 0xF0 == 0xE0 { return 3 }
if octet & 0xF8 == 0xF0 { return 4 }
if octet & 0x80 == 0x00 {
return 1
}
if octet & 0xE0 == 0xC0 {
return 2
}
if octet & 0xF0 == 0xE0 {
return 3
}
if octet & 0xF8 == 0xF0 {
return 4
}
return 0
}

View File

@ -127,8 +127,12 @@ enum CanonicalEventCorpus {
static func props(_ anchor: String?, _ tag: String?) -> String {
var result = ""
if let anchor { result += " &" + anchor }
if let tag { result += " <" + tag + ">" }
if let anchor {
result += " &" + anchor
}
if let tag {
result += " <" + tag + ">"
}
return result
}

View File

@ -63,7 +63,11 @@ struct YAMLTestSuiteConformanceTests {
let parsed = thrown == nil
if testCase.expectsError {
errExpected += 1
if parsed { shouldRejectFailures.append(testCase.id) } else { errPassed += 1 }
if parsed {
shouldRejectFailures.append(testCase.id)
} else {
errPassed += 1
}
} else {
okExpected += 1
if parsed {
@ -116,7 +120,11 @@ struct YAMLTestSuiteConformanceTests {
continue
}
eligible += 1
if actual == expected { matched += 1 } else { mismatches.append(testCase.id) }
if actual == expected {
matched += 1
} else {
mismatches.append(testCase.id)
}
}
report("""
YAML test-suite value-level: \(matched)/\(eligible) (\(percent(matched, eligible))) of comparable cases

View File

@ -0,0 +1,66 @@
/// Minimal JSON value-stream scanner used by the yaml-test-suite gap
/// tests to split concatenated in-JSON expectation documents.
struct JSONStreamScanner {
let text: String
var out: [String] = []
var depth = 0
var inString = false
var escaped = false
var start: String.Index?
mutating func scan() -> [String] {
var index = text.startIndex
while index < text.endIndex {
if inString {
stepInString(text[index])
} else {
stepStructural(text[index], at: index)
}
index = text.index(after: index)
}
if let begin = start {
out.append(String(text[begin...]))
}
return out.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.filter { !$0.isEmpty }
}
private mutating func stepInString(_ character: Character) {
if escaped {
escaped = false
} else if character == "\\" {
escaped = true
} else if character == "\"" {
inString = false
}
}
private mutating func stepStructural(_ character: Character, at index: String.Index) {
switch character {
case "\"":
if start == nil {
start = index
}
inString = true
case "{", "[":
if start == nil {
start = index
}
depth += 1
case "}", "]":
depth -= 1
if depth == 0, let begin = start {
out.append(String(text[begin ... index]))
start = nil
}
case " ", "\n", "\r", "\t":
if depth == 0, let begin = start {
out.append(String(text[begin ..< index]))
start = nil
}
default:
if depth == 0, start == nil {
start = index
}
}
}
}

View File

@ -260,65 +260,6 @@ func splitJSONStream(_ text: String) -> [String] {
return scanner.scan()
}
private struct JSONStreamScanner {
let text: String
var out: [String] = []
var depth = 0
var inString = false
var escaped = false
var start: String.Index?
mutating func scan() -> [String] {
var index = text.startIndex
while index < text.endIndex {
if inString {
stepInString(text[index])
} else {
stepStructural(text[index], at: index)
}
index = text.index(after: index)
}
if let begin = start {
out.append(String(text[begin...]))
}
return out.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.filter { !$0.isEmpty }
}
private mutating func stepInString(_ character: Character) {
if escaped {
escaped = false
} else if character == "\\" {
escaped = true
} else if character == "\"" {
inString = false
}
}
private mutating func stepStructural(_ character: Character, at index: String.Index) {
switch character {
case "\"":
if start == nil { start = index }
inString = true
case "{", "[":
if start == nil { start = index }
depth += 1
case "}", "]":
depth -= 1
if depth == 0, let begin = start {
out.append(String(text[begin ... index]))
start = nil
}
case " ", "\n", "\r", "\t":
if depth == 0, let begin = start {
out.append(String(text[begin ..< index]))
start = nil
}
default:
if depth == 0, start == nil { start = index }
}
}
}
func equalValue(_ value: PureYAML.Model.Value, _ json: YAMLTestSuiteJSON) -> Bool {
switch (value, json) {
case let (.sequence(lhs), .array(rhs)):