From 2a6cb0cb4c7c212151addc677e3707655f40222b Mon Sep 17 00:00:00 2001 From: wesleyel <48174882+wesleyel@users.noreply.github.com> Date: Tue, 7 Apr 2026 10:04:11 +0800 Subject: [PATCH] Fix boundary handling in Parser and update tests for empty cases --- .../SwiftUIMath/Internal/Syntax/Parser.swift | 12 +++++++++++ .../Internal/Syntax/ParserTests.swift | 20 +++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Sources/SwiftUIMath/Internal/Syntax/Parser.swift b/Sources/SwiftUIMath/Internal/Syntax/Parser.swift index aa9cb1b..af01f93 100644 --- a/Sources/SwiftUIMath/Internal/Syntax/Parser.swift +++ b/Sources/SwiftUIMath/Internal/Syntax/Parser.swift @@ -764,6 +764,12 @@ extension Math { // reinstate the old inner atom. let newInner = currentInnerAtom currentInnerAtom = oldInner + if newInner?.leftBoundary?.nucleus.isEmpty == true { + newInner?.leftBoundary = nil + } + if newInner?.rightBoundary?.nucleus.isEmpty == true { + newInner?.rightBoundary = nil + } return newInner } else if command == "overline" { // The overline command has 1 arguments @@ -1162,6 +1168,12 @@ extension Math { } let newInner = self.currentInnerAtom currentInnerAtom = oldInner + if newInner?.leftBoundary?.nucleus.isEmpty == true { + newInner?.leftBoundary = nil + } + if newInner?.rightBoundary?.nucleus.isEmpty == true { + newInner?.rightBoundary = nil + } return newInner } else if command == "overline" { let over = Overline() diff --git a/Tests/SwiftUIMathTests/Internal/Syntax/ParserTests.swift b/Tests/SwiftUIMathTests/Internal/Syntax/ParserTests.swift index cb37f17..2aa782a 100644 --- a/Tests/SwiftUIMathTests/Internal/Syntax/ParserTests.swift +++ b/Tests/SwiftUIMathTests/Internal/Syntax/ParserTests.swift @@ -594,13 +594,21 @@ struct ParserTests { let innerList = try #require(inner.innerList) checkAtomTypes(innerList, types: testCase.type2) - let leftBoundary = try #require(inner.leftBoundary) - #expect(leftBoundary.type == .boundary) - #expect(leftBoundary.nucleus == testCase.left) + if testCase.left.isEmpty { + #expect(inner.leftBoundary == nil) + } else { + let leftBoundary = try #require(inner.leftBoundary) + #expect(leftBoundary.type == .boundary) + #expect(leftBoundary.nucleus == testCase.left) + } - let rightBoundary = try #require(inner.rightBoundary) - #expect(rightBoundary.type == .boundary) - #expect(rightBoundary.nucleus == testCase.right) + if testCase.right.isEmpty { + #expect(inner.rightBoundary == nil) + } else { + let rightBoundary = try #require(inner.rightBoundary) + #expect(rightBoundary.type == .boundary) + #expect(rightBoundary.nucleus == testCase.right) + } // convert it back to latex let latex = Math.Parser.atomListToString(list)