From 6fa49b7ffca39b76ff5d225111e721a0e05540e2 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Sun, 12 Jul 2026 13:29:05 +0200 Subject: [PATCH] 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. --- Sources/Parsing/LibYAML.Scanner.Tag.swift | 16 ++++-- Tests/CanonicalEventConformanceTests.swift | 8 ++- Tests/YAMLTestSuiteConformanceTests.swift | 12 +++- Tests/YAMLTestSuiteGapsSupport.swift | 66 ++++++++++++++++++++++ Tests/YAMLTestSuiteGapsTests.swift | 59 ------------------- 5 files changed, 94 insertions(+), 67 deletions(-) create mode 100644 Tests/YAMLTestSuiteGapsSupport.swift diff --git a/Sources/Parsing/LibYAML.Scanner.Tag.swift b/Sources/Parsing/LibYAML.Scanner.Tag.swift index a3fd681..97bf696 100644 --- a/Sources/Parsing/LibYAML.Scanner.Tag.swift +++ b/Sources/Parsing/LibYAML.Scanner.Tag.swift @@ -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 } diff --git a/Tests/CanonicalEventConformanceTests.swift b/Tests/CanonicalEventConformanceTests.swift index 57e038e..7227698 100644 --- a/Tests/CanonicalEventConformanceTests.swift +++ b/Tests/CanonicalEventConformanceTests.swift @@ -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 } diff --git a/Tests/YAMLTestSuiteConformanceTests.swift b/Tests/YAMLTestSuiteConformanceTests.swift index 426d18e..c733cef 100644 --- a/Tests/YAMLTestSuiteConformanceTests.swift +++ b/Tests/YAMLTestSuiteConformanceTests.swift @@ -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 diff --git a/Tests/YAMLTestSuiteGapsSupport.swift b/Tests/YAMLTestSuiteGapsSupport.swift new file mode 100644 index 0000000..96498b1 --- /dev/null +++ b/Tests/YAMLTestSuiteGapsSupport.swift @@ -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 + } + } + } +} diff --git a/Tests/YAMLTestSuiteGapsTests.swift b/Tests/YAMLTestSuiteGapsTests.swift index 7ab9339..deac2da 100644 --- a/Tests/YAMLTestSuiteGapsTests.swift +++ b/Tests/YAMLTestSuiteGapsTests.swift @@ -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)):