Add Parser tests

This commit is contained in:
Guille Gonzalez
2026-01-02 19:36:05 +01:00
parent 64b0090f3c
commit e9657c186e
5 changed files with 2593 additions and 2553 deletions

View File

@@ -594,6 +594,11 @@ extension Math {
} }
} }
static func remove(latexSymbol name: String) {
supportedLatexSymbols.withValue { $0[name] = nil }
textToLatexSymbolName.withValue { $0 = nil }
}
static func operatorWithName(_ name: String, limits: Bool) -> LargeOperator { static func operatorWithName(_ name: String, limits: Bool) -> LargeOperator {
let op = LargeOperator(limits: limits) let op = LargeOperator(limits: limits)
op.nucleus = name op.nucleus = name

View File

@@ -1136,7 +1136,12 @@ extension Math {
} }
} }
let table = self.buildTable(environment: env, alignment: alignment, firstList: nil, isRow: false) let table = self.buildTable(
environment: env,
alignment: alignment,
firstList: nil,
isRow: false
)
return table return table
} else { } else {
return nil return nil
@@ -1206,7 +1211,9 @@ extension Math {
alignment = .right alignment = .right
default: default:
self.setError( self.setError(
.invalidEnvironment, message: "Invalid alignment specifier: \(alignChar). Must be l, c, or r") .invalidEnvironment,
message: "Invalid alignment specifier: \(alignChar). Must be l, c, or r"
)
return nil return nil
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
import Foundation import Foundation
import Testing import Testing
@testable import SwiftUIMath @testable import SwiftUIMath
@Suite @Suite
@@ -260,7 +261,11 @@ struct AtomListTests {
let copy = Math.Radical(radical) let copy = Math.Radical(radical)
try assertAtomCopyMatches(copy, original: radical, context: "radical copy") try assertAtomCopyMatches(copy, original: radical, context: "radical copy")
try assertAtomListCopyMatches(copy.radicand, original: radical.radicand, context: "radicand copy") try assertAtomListCopyMatches(
copy.radicand,
original: radical.radicand,
context: "radicand copy"
)
try assertAtomListCopyMatches(copy.degree, original: radical.degree, context: "degree copy") try assertAtomListCopyMatches(copy.degree, original: radical.degree, context: "degree copy")
} }
@@ -294,9 +299,21 @@ struct AtomListTests {
let copy = Math.Inner(inner) let copy = Math.Inner(inner)
try assertAtomCopyMatches(copy, original: inner, context: "inner atom copy") try assertAtomCopyMatches(copy, original: inner, context: "inner atom copy")
try assertAtomListCopyMatches(copy.innerList, original: inner.innerList, context: "inner list copy") try assertAtomListCopyMatches(
try assertAtomCopyMatches(copy.leftBoundary!, original: inner.leftBoundary, context: "left boundary copy") copy.innerList,
try assertAtomCopyMatches(copy.rightBoundary!, original: inner.rightBoundary, context: "right boundary copy") original: inner.innerList,
context: "inner list copy"
)
try assertAtomCopyMatches(
copy.leftBoundary!,
original: inner.leftBoundary,
context: "left boundary copy"
)
try assertAtomCopyMatches(
copy.rightBoundary!,
original: inner.rightBoundary,
context: "right boundary copy"
)
} }
@Test @Test
@@ -330,7 +347,11 @@ struct AtomListTests {
let copy = Math.Overline(overline) let copy = Math.Overline(overline)
try assertAtomCopyMatches(copy, original: overline, context: "overline copy") try assertAtomCopyMatches(copy, original: overline, context: "overline copy")
try assertAtomListCopyMatches(copy.innerList, original: overline.innerList, context: "overline list copy") try assertAtomListCopyMatches(
copy.innerList,
original: overline.innerList,
context: "overline list copy"
)
} }
@Test @Test
@@ -349,7 +370,11 @@ struct AtomListTests {
let copy = Math.Underline(underline) let copy = Math.Underline(underline)
try assertAtomCopyMatches(copy, original: underline, context: "underline copy") try assertAtomCopyMatches(copy, original: underline, context: "underline copy")
try assertAtomListCopyMatches(copy.innerList, original: underline.innerList, context: "underline list copy") try assertAtomListCopyMatches(
copy.innerList,
original: underline.innerList,
context: "underline list copy"
)
} }
@Test @Test
@@ -368,7 +393,11 @@ struct AtomListTests {
let copy = Math.Accent(accent) let copy = Math.Accent(accent)
try assertAtomCopyMatches(copy, original: accent, context: "accent copy") try assertAtomCopyMatches(copy, original: accent, context: "accent copy")
try assertAtomListCopyMatches(copy.innerList, original: accent.innerList, context: "accent list copy") try assertAtomListCopyMatches(
copy.innerList,
original: accent.innerList,
context: "accent list copy"
)
} }
@Test @Test
@@ -498,7 +527,12 @@ struct AtomListTests {
try assertAtom(atom, type: .number, nucleus: "13", range: NSRange(location: 0, length: 2)) try assertAtom(atom, type: .number, nucleus: "13", range: NSRange(location: 0, length: 2))
atom = superscript.atoms[1] atom = superscript.atoms[1]
try assertAtom(atom, type: .binaryOperator, nucleus: "+", range: NSRange(location: 2, length: 1)) try assertAtom(
atom,
type: .binaryOperator,
nucleus: "+",
range: NSRange(location: 2, length: 1)
)
atom = superscript.atoms[2] atom = superscript.atoms[2]
try assertAtom(atom, type: .variable, nucleus: "y", range: NSRange(location: 3, length: 1)) try assertAtom(atom, type: .variable, nucleus: "y", range: NSRange(location: 3, length: 1))
@@ -514,7 +548,12 @@ struct AtomListTests {
try assertAtom(atom, type: .unaryOperator, nucleus: "", range: NSRange(location: 2, length: 1)) try assertAtom(atom, type: .unaryOperator, nucleus: "", range: NSRange(location: 2, length: 1))
atom = finalized.atoms[3] atom = finalized.atoms[3]
try assertAtom(atom, type: .binaryOperator, nucleus: "+", range: NSRange(location: 4, length: 1)) try assertAtom(
atom,
type: .binaryOperator,
nucleus: "+",
range: NSRange(location: 4, length: 1)
)
atom = finalized.atoms[4] atom = finalized.atoms[4]
try assertAtom(atom, type: .open, nucleus: "(", range: NSRange(location: 5, length: 1)) try assertAtom(atom, type: .open, nucleus: "(", range: NSRange(location: 5, length: 1))
@@ -526,7 +565,12 @@ struct AtomListTests {
try assertAtom(atom, type: .number, nucleus: "12.3", range: NSRange(location: 7, length: 4)) try assertAtom(atom, type: .number, nucleus: "12.3", range: NSRange(location: 7, length: 4))
atom = finalized.atoms[7] atom = finalized.atoms[7]
try assertAtom(atom, type: .unaryOperator, nucleus: "*", range: NSRange(location: 11, length: 1)) try assertAtom(
atom,
type: .unaryOperator,
nucleus: "*",
range: NSRange(location: 11, length: 1)
)
atom = finalized.atoms[8] atom = finalized.atoms[8]
try assertAtom(atom, type: .close, nucleus: ")", range: NSRange(location: 12, length: 1)) try assertAtom(atom, type: .close, nucleus: ")", range: NSRange(location: 12, length: 1))
@@ -586,7 +630,11 @@ struct AtomListTests {
for (index, copyAtom) in copy.atoms.enumerated() { for (index, copyAtom) in copy.atoms.enumerated() {
let originalAtom = original.atoms[index] let originalAtom = original.atoms[index]
try assertAtomCopyMatches(copyAtom, original: originalAtom, context: "\(context) atom \(index)") try assertAtomCopyMatches(
copyAtom,
original: originalAtom,
context: "\(context) atom \(index)"
)
} }
} }
} }

File diff suppressed because it is too large Load Diff