diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..aafdc82 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,42 @@ +{ + "originHash" : "f1d7267746a12d71d624c75daa345adf396e99a25ae07ee92716ae508085d85e", + "pins" : [ + { + "identity" : "swift-custom-dump", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-custom-dump", + "state" : { + "revision" : "82645ec760917961cfa08c9c0c7104a57a0fa4b1", + "version" : "1.3.3" + } + }, + { + "identity" : "swift-snapshot-testing", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-snapshot-testing", + "state" : { + "revision" : "a8b7c5e0ed33d8ab8887d1654d9b59f2cbad529b", + "version" : "1.18.7" + } + }, + { + "identity" : "swift-syntax", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swiftlang/swift-syntax", + "state" : { + "revision" : "4799286537280063c85a32f09884cfbca301b1a1", + "version" : "602.0.0" + } + }, + { + "identity" : "xctest-dynamic-overlay", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", + "state" : { + "revision" : "34e463e98ab8541c604af706c99bed7160f5ec70", + "version" : "1.8.1" + } + } + ], + "version" : 3 +} diff --git a/Package.swift b/Package.swift index ea00947..9c11b10 100755 --- a/Package.swift +++ b/Package.swift @@ -14,7 +14,9 @@ let package = Package( products: [ .library(name: "SwiftUIMath", targets: ["SwiftUIMath"]) ], - dependencies: [], + dependencies: [ + .package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.7") + ], targets: [ .target( name: "SwiftUIMath", @@ -23,7 +25,11 @@ let package = Package( ), .testTarget( name: "SwiftUIMathTests", - dependencies: ["SwiftUIMath"] + dependencies: [ + "SwiftUIMath", + .product(name: "SnapshotTesting", package: "swift-snapshot-testing"), + ], + exclude: ["__Snapshots__"] ), ] ) diff --git a/Tests/SwiftUIMathTests/MathTests.swift b/Tests/SwiftUIMathTests/MathTests.swift new file mode 100644 index 0000000..fa30c7d --- /dev/null +++ b/Tests/SwiftUIMathTests/MathTests.swift @@ -0,0 +1,96 @@ +#if os(iOS) + import SnapshotTesting + import SwiftUI + import Testing + + @testable import SwiftUIMath + + @MainActor + struct MathTests { + private let layout = SwiftUISnapshotLayout.device(config: .iPhone8) + + @Test + func displayAndInlineStyles() { + let view = VStack(alignment: .leading, spacing: 16) { + Math("\\frac{1}{2}+\\sqrt{2}+\\sum_{i=1}^{n}x_i") + .mathTypesettingStyle(.display) + .mathFont(Math.Font(name: .latinModern, size: 24)) + + Math("\\int_0^1 x^2\\,dx = \\frac{1}{3}") + .mathTypesettingStyle(.text) + .mathFont(Math.Font(name: .libertinus, size: 20)) + } + .background(Color.guide) + .padding(.horizontal) + + assertSnapshot(of: view, as: .image(layout: layout)) + } + + @Test + func multicolorExpressions() { + let view = VStack(alignment: .leading, spacing: 16) { + Math("\\color{#cc0000}{a}+\\color{#00aa00}{b}+\\color{#0000cc}{c}") + .mathTypesettingStyle(.text) + .mathRenderingMode(.multicolor) + .mathFont(Math.Font(name: .latinModern, size: 22)) + + Math("\\textcolor{#ff8800}{\\int_0^1 x^2\\,dx}=\\textcolor{#0088ff}{\\frac{1}{3}}") + .mathRenderingMode(.multicolor) + .mathFont(Math.Font(name: .libertinus, size: 20)) + } + .background(Color.guide) + .padding(.horizontal) + + assertSnapshot(of: view, as: .image(layout: layout)) + } + + @Test + func matricesAndCases() { + let view = VStack(alignment: .leading, spacing: 16) { + Math("A=\\begin{pmatrix}1&2\\\\3&4\\end{pmatrix}") + .mathTypesettingStyle(.display) + .mathFont(Math.Font(name: .asana, size: 22)) + + Math("\\begin{cases} x + y = 5 \\\\ 2x - y = 1 \\end{cases}") + .mathTypesettingStyle(.display) + .mathFont(Math.Font(name: .termes, size: 22)) + } + .background(Color.guide) + .padding(.horizontal) + + assertSnapshot(of: view, as: .image(layout: layout)) + } + + @Test + func largeOperatorsAndLimits() { + let view = VStack(alignment: .leading, spacing: 16) { + Math("\\lim_{n\\to\\infty}\\sum_{k=1}^{n}\\frac{1}{k^2}=\\frac{\\pi^2}{6}") + .mathTypesettingStyle(.display) + .mathFont(Math.Font(name: .xits, size: 22)) + } + .background(Color.guide) + .padding(.horizontal) + + assertSnapshot(of: view, as: .image(layout: layout)) + } + + @Test + func inlineTextWrapping() { + let view = VStack(alignment: .leading, spacing: 16) { + Math("\\text{Rappelons la conversion : 1 km équivaut à 1000 m.}") + .mathTypesettingStyle(.text) + .mathFont(Math.Font(name: .latinModern, size: 18)) + } + .background(Color.guide) + .padding(.horizontal) + + assertSnapshot(of: view, as: .image(layout: layout)) + } + } + + extension Color { + fileprivate static var guide: Color { + .accentColor.opacity(0.06) + } + } +#endif diff --git a/Tests/SwiftUIMathTests/__Snapshots__/MathTests/displayAndInlineStyles.1.png b/Tests/SwiftUIMathTests/__Snapshots__/MathTests/displayAndInlineStyles.1.png new file mode 100644 index 0000000..05580c7 Binary files /dev/null and b/Tests/SwiftUIMathTests/__Snapshots__/MathTests/displayAndInlineStyles.1.png differ diff --git a/Tests/SwiftUIMathTests/__Snapshots__/MathTests/inlineTextWrapping.1.png b/Tests/SwiftUIMathTests/__Snapshots__/MathTests/inlineTextWrapping.1.png new file mode 100644 index 0000000..b53df61 Binary files /dev/null and b/Tests/SwiftUIMathTests/__Snapshots__/MathTests/inlineTextWrapping.1.png differ diff --git a/Tests/SwiftUIMathTests/__Snapshots__/MathTests/largeOperatorsAndLimits.1.png b/Tests/SwiftUIMathTests/__Snapshots__/MathTests/largeOperatorsAndLimits.1.png new file mode 100644 index 0000000..e6f1990 Binary files /dev/null and b/Tests/SwiftUIMathTests/__Snapshots__/MathTests/largeOperatorsAndLimits.1.png differ diff --git a/Tests/SwiftUIMathTests/__Snapshots__/MathTests/matricesAndCases.1.png b/Tests/SwiftUIMathTests/__Snapshots__/MathTests/matricesAndCases.1.png new file mode 100644 index 0000000..37105ef Binary files /dev/null and b/Tests/SwiftUIMathTests/__Snapshots__/MathTests/matricesAndCases.1.png differ diff --git a/Tests/SwiftUIMathTests/__Snapshots__/MathTests/multicolorExpressions.1.png b/Tests/SwiftUIMathTests/__Snapshots__/MathTests/multicolorExpressions.1.png new file mode 100644 index 0000000..655bbe7 Binary files /dev/null and b/Tests/SwiftUIMathTests/__Snapshots__/MathTests/multicolorExpressions.1.png differ