diff --git a/AGENTS.md b/AGENTS.md
index 57fcdb88..b6e738a7 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -67,7 +67,9 @@ import Synchronization
### Writing tests
-Write all new tests with Swift Testing (`import Testing`, `@Test`, `#expect`, `#require`), including tests brought in from other branches or pull requests. Follow the existing suites: a `struct`, `@Test` functions named for the behaviour without a `test` prefix, and `@Test(arguments:)` instead of looping over inputs. Some older suites still use XCTest; when adding to one, a new Swift Testing suite is preferred over more XCTest cases.
+All tests use Swift Testing (`import Testing`, `@Test`, `#expect`, `#require`); there is no XCTest, so convert tests brought in from other branches or pull requests. Each suite is an implicit one: a plain `struct` (a `class` only when a test needs `deinit`) holding `@Test` functions named for the behaviour without a `test` prefix, with no free-standing `@Test` functions. Use `@Suite` only to set a trait such as `.serialized` or `.timeLimit`, never just for a display name. Use `@Test(arguments:)` instead of looping over inputs or writing near-duplicate tests. Compare floating-point values with `#expect(a.isApproximately(b, tolerance: 0.001))` (`SwiftDraw/Tests/Utilities/FloatingPoint+Approximately.swift`).
+
+Swift Testing runs tests in parallel. Give each test its own state (caches, temporary file names, renderers) rather than sharing globals, or mark the suite `@Suite(.serialized)` when it must touch global state such as the log sink. Tests that draw with AppKit or UIKit (`NSImage`, `UIImage`, views) need `@MainActor`.
## Checking rendering changes
diff --git a/DOM/Tests/Parser.XML.PathTests.swift b/DOM/Tests/Parser.XML.PathTests.swift
index d0d870bd..c5a3347b 100644
--- a/DOM/Tests/Parser.XML.PathTests.swift
+++ b/DOM/Tests/Parser.XML.PathTests.swift
@@ -39,7 +39,6 @@ private typealias Coordinate = DOM.Coordinate
private typealias Segment = DOM.Path.Segment
private typealias CoordinateSpace = DOM.Path.Segment.CoordinateSpace
-@Suite("Parser XML Path Tests")
struct ParserXMLPathTests {
@Test
diff --git a/DOM/Tests/Parser.XML.PatternTests.swift b/DOM/Tests/Parser.XML.PatternTests.swift
index de130174..abf113e8 100644
--- a/DOM/Tests/Parser.XML.PatternTests.swift
+++ b/DOM/Tests/Parser.XML.PatternTests.swift
@@ -34,7 +34,6 @@ import Testing
private typealias Coordinate = DOM.Coordinate
-@Suite("Parser XML Pattern Tests")
struct ParserXMLPatternTests {
@Test
diff --git a/DOM/Tests/Parser.XML.RadialGradientTests.swift b/DOM/Tests/Parser.XML.RadialGradientTests.swift
index 6d27e4e3..96859734 100644
--- a/DOM/Tests/Parser.XML.RadialGradientTests.swift
+++ b/DOM/Tests/Parser.XML.RadialGradientTests.swift
@@ -34,7 +34,6 @@ import Foundation
import Testing
@testable import SwiftDrawDOM
-@Suite("Parser XML Radial Gradient Tests")
struct ParserXMLRadialGradientTests {
@Test
diff --git a/DOM/Tests/Parser.XML.StyleSheetCascadeTests.swift b/DOM/Tests/Parser.XML.StyleSheetCascadeTests.swift
index 46c79886..993a9e75 100644
--- a/DOM/Tests/Parser.XML.StyleSheetCascadeTests.swift
+++ b/DOM/Tests/Parser.XML.StyleSheetCascadeTests.swift
@@ -33,7 +33,6 @@ import Testing
import Foundation
@testable import SwiftDrawDOM
-@Suite("Parser XML StyleSheet Cascade Tests")
struct ParserXMLStyleSheetCascadeTests {
typealias Selector = DOM.StyleSheet.ComplexSelector
diff --git a/DOM/Tests/Parser.XML.StyleSheetTests.swift b/DOM/Tests/Parser.XML.StyleSheetTests.swift
index a332eb5b..d3cc45f0 100644
--- a/DOM/Tests/Parser.XML.StyleSheetTests.swift
+++ b/DOM/Tests/Parser.XML.StyleSheetTests.swift
@@ -32,7 +32,6 @@
import Testing
@testable import SwiftDrawDOM
-@Suite("Parser XML StyleSheet Tests")
struct ParserXMLStyleSheetTests {
@Test
diff --git a/DOM/Tests/Parser.XML.TextTests.swift b/DOM/Tests/Parser.XML.TextTests.swift
index d6c8102b..9ed9b95f 100644
--- a/DOM/Tests/Parser.XML.TextTests.swift
+++ b/DOM/Tests/Parser.XML.TextTests.swift
@@ -32,7 +32,6 @@
import Testing
@testable import SwiftDrawDOM
-@Suite("Parser XML Text Tests")
struct ParserXMLTextTests {
@Test
diff --git a/DOM/Tests/Parser.XML.TransformTests.swift b/DOM/Tests/Parser.XML.TransformTests.swift
index ef8e3457..4d2a1841 100644
--- a/DOM/Tests/Parser.XML.TransformTests.swift
+++ b/DOM/Tests/Parser.XML.TransformTests.swift
@@ -32,7 +32,6 @@
import Testing
@testable import SwiftDrawDOM
-@Suite("Parser Transform Tests")
struct ParserTransformTests {
@Test
diff --git a/DOM/Tests/ParserSVGImageTests.swift b/DOM/Tests/ParserSVGImageTests.swift
index 643f75e6..ea42499b 100644
--- a/DOM/Tests/ParserSVGImageTests.swift
+++ b/DOM/Tests/ParserSVGImageTests.swift
@@ -33,7 +33,6 @@ import Testing
@testable import SwiftDrawDOM
import Foundation
-@Suite("Parser SVG Image Tests")
struct ParserSVGImageTests {
@Test
diff --git a/DOM/Tests/StyleTests.swift b/DOM/Tests/StyleTests.swift
index d9a07818..4117eefa 100644
--- a/DOM/Tests/StyleTests.swift
+++ b/DOM/Tests/StyleTests.swift
@@ -32,7 +32,6 @@
import Testing
@testable import SwiftDrawDOM
-@Suite("Style Tests")
struct StyleTests {
@Test
diff --git a/DOM/Tests/UseTests.swift b/DOM/Tests/UseTests.swift
index 48a9d336..974511ed 100644
--- a/DOM/Tests/UseTests.swift
+++ b/DOM/Tests/UseTests.swift
@@ -32,7 +32,6 @@
import Testing
@testable import SwiftDrawDOM
-@Suite("Use Tests")
struct UseTests {
@Test
diff --git a/DOM/Tests/ValueParserTests.swift b/DOM/Tests/ValueParserTests.swift
index ff9d0410..d28ef906 100644
--- a/DOM/Tests/ValueParserTests.swift
+++ b/DOM/Tests/ValueParserTests.swift
@@ -33,7 +33,6 @@ import Foundation
import Testing
@testable import SwiftDrawDOM
-@Suite("Value Parser Tests")
struct ValueParserTests {
var parser = XMLParser.ValueParser()
diff --git a/DOM/Tests/XML.Parser.ScannerTests.swift b/DOM/Tests/XML.Parser.ScannerTests.swift
index 4eaaf791..894a9e0f 100644
--- a/DOM/Tests/XML.Parser.ScannerTests.swift
+++ b/DOM/Tests/XML.Parser.ScannerTests.swift
@@ -33,7 +33,6 @@ public import Foundation
import Testing
@testable import SwiftDrawDOM
-@Suite("Scanner Tests")
struct ScannerTests {
@Test
diff --git a/DOM/Tests/XML.SAXParserTests.swift b/DOM/Tests/XML.SAXParserTests.swift
index 39f4a15d..6ab8e382 100644
--- a/DOM/Tests/XML.SAXParserTests.swift
+++ b/DOM/Tests/XML.SAXParserTests.swift
@@ -33,7 +33,6 @@ import Foundation
import Testing
@testable import SwiftDrawDOM
-@Suite("SAX Parser Tests")
struct SAXParserTests {
@Test
diff --git a/SwiftDraw/Tests/CommandLine/CommandLine.ArgumentsTests.swift b/SwiftDraw/Tests/CommandLine/CommandLine.ArgumentsTests.swift
index 8d68360b..554aa566 100644
--- a/SwiftDraw/Tests/CommandLine/CommandLine.ArgumentsTests.swift
+++ b/SwiftDraw/Tests/CommandLine/CommandLine.ArgumentsTests.swift
@@ -29,57 +29,54 @@
// 3. This notice may not be removed or altered from any source distribution.
//
-import XCTest
+import Testing
@testable import SwiftDraw
-final class CommandLineArgumentsTests: XCTestCase {
+struct CommandLineArgumentsTests {
- func testParseModifiers() throws {
- var modifiers = try CommandLine.parseModifiers(from: [
- "--format", "some", "--output", "more", "--scale", "magnify", "--size", "huge",
- ])
- XCTAssertEqual(modifiers, [.format: "some", .output: "more", .scale: "magnify", .size: "huge"])
-
- modifiers = try CommandLine.parseModifiers(from: [
- "--ultralightInsets", "a", "--blackInsets", "b", "--hideUnsupportedFilters", "--legacy",
- ])
- XCTAssertEqual(
- modifiers,
- [.ultralightInsets: "a", .blackInsets: "b", .hideUnsupportedFilters: nil, .legacy: nil]
- )
-
- modifiers = try CommandLine.parseModifiers(from: [
- "--ultralight-insets", "a", "--black-insets", "b", "--hide-unsupported-filters", "--legacy",
- ])
- XCTAssertEqual(
- modifiers,
- [.ultralightInsets: "a", .blackInsets: "b", .hideUnsupportedFilters: nil, .legacy: nil]
- )
-
- modifiers = try CommandLine.parseModifiers(from: ["--format", "png", "--quiet"])
- XCTAssertEqual(modifiers, [.format: "png", .quiet: nil])
- }
-
- func testParseModifiersThrowsForOddPairs() {
- XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format"]))
- XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--output"]))
+ @Test(
+ arguments: [
+ (
+ ["--format", "some", "--output", "more", "--scale", "magnify", "--size", "huge"],
+ [.format: "some", .output: "more", .scale: "magnify", .size: "huge"]
+ ),
+ (
+ ["--ultralightInsets", "a", "--blackInsets", "b", "--hideUnsupportedFilters", "--legacy"],
+ [.ultralightInsets: "a", .blackInsets: "b", .hideUnsupportedFilters: nil, .legacy: nil]
+ ),
+ (
+ ["--ultralight-insets", "a", "--black-insets", "b", "--hide-unsupported-filters", "--legacy"],
+ [.ultralightInsets: "a", .blackInsets: "b", .hideUnsupportedFilters: nil, .legacy: nil]
+ ),
+ (
+ ["--format", "png", "--quiet"],
+ [.format: "png", .quiet: nil]
+ ),
+ ] as [([String], [CommandLine.Modifier: String?])]
+ )
+ func parsesModifiers(args: [String], expected: [CommandLine.Modifier: String?]) throws {
+ #expect(try CommandLine.parseModifiers(from: args) == expected)
}
- func testParseModifiersThrowsForDuplicateModifiers() {
- XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--format", "jpg"]))
- XCTAssertThrowsError(
- try CommandLine.parseModifiers(from: ["--format", "png", "--output", "more", "--output", "evenmore"])
- )
+ @Test(
+ arguments: [
+ // odd pairs
+ ["--format"],
+ ["--format", "png", "--output"],
+ // duplicate modifiers
+ ["--format", "png", "--format", "jpg"],
+ ["--format", "png", "--output", "more", "--output", "evenmore"],
+ // unknown modifiers
+ ["--unknown", "png"],
+ ["--format", "png", "--unknown", "more"],
+ // missing prefix
+ ["format", "png"],
+ ["--format", "png", "output", "more"],
+ ]
+ )
+ func invalidModifiersThrow(args: [String]) {
+ #expect(throws: CommandLine.Error.invalid) {
+ try CommandLine.parseModifiers(from: args)
+ }
}
-
- func testParseModifiersThrowsForUnknownModifiers() {
- XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--unknown", "png"]))
- XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--unknown", "more"]))
- }
-
- func testParseModifiersThrowsForMissingPrefix() {
- XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["format", "png"]))
- XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "output", "more"]))
- }
-
}
diff --git a/SwiftDraw/Tests/CommandLine/CommandLine.ConfigurationTests.swift b/SwiftDraw/Tests/CommandLine/CommandLine.ConfigurationTests.swift
index 92bb6e53..cd401710 100644
--- a/SwiftDraw/Tests/CommandLine/CommandLine.ConfigurationTests.swift
+++ b/SwiftDraw/Tests/CommandLine/CommandLine.ConfigurationTests.swift
@@ -29,239 +29,214 @@
// 3. This notice may not be removed or altered from any source distribution.
//
-import XCTest
+import Foundation
+import Testing
@testable import SwiftDraw
-final class CommandLineConfigurationTests: XCTestCase {
+struct CommandLineConfigurationTests {
- func testParseFileURL() throws {
- let url = try CommandLine.parseFileURL(file: "file", within: URL(directory: "/test"))
- XCTAssertEqual(url, URL(fileURLWithPath: "/test/file"))
-
- let url1 = try CommandLine.parseFileURL(file: "file", within: URL(directory: "/test/subfolder"))
- XCTAssertEqual(url1, URL(fileURLWithPath: "/test/subfolder/file"))
-
- let url2 = try CommandLine.parseFileURL(file: "../file", within: URL(directory: "/test/subfolder"))
- XCTAssertEqual(url2, URL(fileURLWithPath: "/test/file"))
+ @Test(
+ arguments: [
+ ("file", "/test", "/test/file"),
+ ("file", "/test/subfolder", "/test/subfolder/file"),
+ ("../file", "/test/subfolder", "/test/file"),
+ ] as [(String, String, String)]
+ )
+ func parseFileURLResolvesAgainstDirectory(file: String, directory: String, expected: String) throws {
+ let url = try CommandLine.parseFileURL(file: file, within: URL(directory: directory))
+ #expect(url == URL(fileURLWithPath: expected))
}
- func testNewURLForFormat() throws {
+ @Test
+ func newURLForFormat() {
let svg = URL(fileURLWithPath: "/test/file.svg")
- XCTAssertEqual(svg.newURL(for: .jpeg, scale: .default), URL(fileURLWithPath: "/test/file.jpg"))
- XCTAssertEqual(svg.newURL(for: .png, scale: .default), URL(fileURLWithPath: "/test/file.png"))
- XCTAssertEqual(svg.newURL(for: .pdf, scale: .default), URL(fileURLWithPath: "/test/file.pdf"))
+ #expect(svg.newURL(for: .jpeg, scale: .default) == URL(fileURLWithPath: "/test/file.jpg"))
+ #expect(svg.newURL(for: .png, scale: .default) == URL(fileURLWithPath: "/test/file.png"))
+ #expect(svg.newURL(for: .pdf, scale: .default) == URL(fileURLWithPath: "/test/file.pdf"))
+ #expect(svg.newURL(for: .jpeg, scale: .retina) == URL(fileURLWithPath: "/test/file.jpg"))
+ #expect(svg.newURL(for: .sfsymbol, scale: .default) == URL(fileURLWithPath: "/test/file-symbol.svg"))
+ #expect(svg.newURL(for: .swift, scale: .default) == URL(fileURLWithPath: "/test/file.swift"))
- let svgExtension = URL(fileURLWithPath: "/test/file")
- XCTAssertEqual(svgExtension.newURL(for: .jpeg, scale: .default), URL(fileURLWithPath: "/test/file.jpg"))
+ let noExtension = URL(fileURLWithPath: "/test/file")
+ #expect(noExtension.newURL(for: .jpeg, scale: .default) == URL(fileURLWithPath: "/test/file.jpg"))
}
- func testParseConfiguration() throws {
+ @Test
+ func parseConfigurationDefaults() throws {
let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "pdf")
- XCTAssertEqual(config.input, URL(fileURLWithPath: "/file.svg"))
- XCTAssertEqual(config.output, URL(fileURLWithPath: "/file.pdf"))
- XCTAssertEqual(config.scale, .default)
- XCTAssertEqual(config.format, .pdf)
- XCTAssertEqual(config.size, .default)
+ #expect(config.input == URL(fileURLWithPath: "/file.svg"))
+ #expect(config.output == URL(fileURLWithPath: "/file.pdf"))
+ #expect(config.scale == .default)
+ #expect(config.format == .pdf)
+ #expect(config.size == .default)
}
- func testParseConfigurationSize() throws {
+ @Test
+ func parseConfigurationSize() throws {
let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "png", "--size", "400x300")
- XCTAssertEqual(config.input, URL(fileURLWithPath: "/file.svg"))
- XCTAssertEqual(config.output, URL(fileURLWithPath: "/file.png"))
- XCTAssertEqual(config.format, .png)
- XCTAssertEqual(config.size, .custom(width: 400, height: 300))
+ #expect(config.input == URL(fileURLWithPath: "/file.svg"))
+ #expect(config.output == URL(fileURLWithPath: "/file.png"))
+ #expect(config.format == .png)
+ #expect(config.size == .custom(width: 400, height: 300))
}
- func testParseConfigurationScale2x() throws {
+ @Test
+ func parseConfigurationScale2x() throws {
let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "png", "--scale", "2x")
- XCTAssertEqual(config.input, URL(fileURLWithPath: "/file.svg"))
- XCTAssertEqual(config.output, URL(fileURLWithPath: "/file@2x.png"))
- XCTAssertEqual(config.scale, .retina)
- XCTAssertEqual(config.format, .png)
+ #expect(config.input == URL(fileURLWithPath: "/file.svg"))
+ #expect(config.output == URL(fileURLWithPath: "/file@2x.png"))
+ #expect(config.scale == .retina)
+ #expect(config.format == .png)
}
- func testParseConfigurationLogLevel() throws {
- let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "pdf")
- XCTAssertEqual(config.logLevel, .info)
+ @Test
+ func parseConfigurationScale3x() throws {
+ let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "png", "--scale", "3x")
- let quiet = try parseConfiguration("swiftdraw", "file.svg", "--format", "pdf", "--quiet")
- XCTAssertEqual(quiet.logLevel, .error)
+ #expect(config.output == URL(fileURLWithPath: "/file@3x.png"))
+ #expect(config.scale == .superRetina)
}
- func testParseConfigurationThrows() {
- XCTAssertThrowsError(try parseConfiguration())
- XCTAssertThrowsError(try parseConfiguration("swiftdraw", "file.svg"))
- XCTAssertThrowsError(try parseConfiguration("swiftdraw", "file.svg", "--format", "unknown"))
- }
+ @Test
+ func parseConfigurationLogLevel() throws {
+ let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "pdf")
+ #expect(config.logLevel == .info)
- func testParseInsets() throws {
- XCTAssertNil(
- try CommandLine.parseInsets(from: nil)
- )
- XCTAssertEqual(
- try CommandLine.parseInsets(from: "auto"),
- .init()
- )
- XCTAssertEqual(
- try CommandLine.parseInsets(from: "1,2,3,4"),
- .init(top: 1, left: 2, bottom: 3, right: 4)
- )
- XCTAssertEqual(
- try CommandLine.parseInsets(from: "0.995,auto,2.5,auto"),
- .init(top: 0.995, left: nil, bottom: 2.5, right: nil)
- )
- XCTAssertThrowsError(
- try CommandLine.parseInsets(from: "cab,1,2,2")
- )
- XCTAssertThrowsError(
- try CommandLine.parseInsets(from: "1,2")
- )
- XCTAssertThrowsError(
- try CommandLine.parseInsets(from: "")
+ let quiet = try parseConfiguration("swiftdraw", "file.svg", "--format", "pdf", "--quiet")
+ #expect(quiet.logLevel == .error)
+ }
+
+ @Test(
+ arguments: [
+ [],
+ ["swiftdraw", "file.svg"],
+ ["swiftdraw", "file.svg", "--format", "unknown"],
+ ["swiftdraw", "file.svg", "--format", "swift", "--precision", "abc"],
+ ["swiftdraw", "file.svg", "--format", "png", "--size", "abc"],
+ ["swiftdraw", "file.svg", "--format", "png", "--size", "0x0"],
+ ["swiftdraw", "file.svg", "--format", "png", "--size", "-10x20"],
+ ["swiftdraw", "file.svg", "--format", "png", "--scale", "5x"],
+ ["swiftdraw", "file.svg", "--format", "swift", "--api", "flutter"],
+ ["swiftdraw", "file.svg", "--format", "sfsymbol", "--size", "tiny"],
+ ["swiftdraw", "file.svg", "--format", "sfsymbol", "--ultralight-stroke-width", "abc"],
+ ["swiftdraw", "file.svg", "--format", "sfsymbol", "--black-stroke-width", "0"],
+ ]
+ )
+ func invalidConfigurationThrows(args: [String]) {
+ #expect(throws: CommandLine.Error.invalid) {
+ try parseConfiguration(args)
+ }
+ }
+
+ @Test(
+ arguments: [
+ ("auto", .init()),
+ ("1,2,3,4", .init(top: 1, left: 2, bottom: 3, right: 4)),
+ ("0.995,auto,2.5,auto", .init(top: 0.995, left: nil, bottom: 2.5, right: nil)),
+ ] as [(String, CommandLine.Insets)]
+ )
+ func parseInsets(string: String, expected: CommandLine.Insets) throws {
+ #expect(try CommandLine.parseInsets(from: string) == expected)
+ }
+
+ @Test
+ func parseInsetsFromNilIsNil() throws {
+ #expect(try CommandLine.parseInsets(from: nil) == nil)
+ }
+
+ @Test(arguments: ["cab,1,2,2", "1,2", ""])
+ func parseInvalidInsetsThrows(string: String) {
+ #expect(throws: (any Error).self) {
+ try CommandLine.parseInsets(from: string)
+ }
+ }
+
+ @Test
+ func parseConfigurationInsets() throws {
+ let config = try parseConfiguration(
+ "swiftdraw",
+ "file.svg",
+ "--format",
+ "sfsymbol",
+ "--insets",
+ "1,2,3.5,auto"
)
- }
-
- func testParseConfigurationInsets() throws {
- let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "sfsymbol", "--insets", "1,2,3.5,auto")
- XCTAssertEqual(config.insets.top, 1)
- XCTAssertEqual(config.insets.left, 2)
- XCTAssertEqual(config.insets.bottom, 3.5)
- XCTAssertEqual(config.insets.right, nil)
+ #expect(config.insets.top == 1)
+ #expect(config.insets.left == 2)
+ #expect(config.insets.bottom == 3.5)
+ #expect(config.insets.right == nil)
}
- func testParseConfigurationAppKit() throws {
- let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "swift", "--api", "appkit")
-
- XCTAssertEqual(config.format, .swift)
- XCTAssertEqual(config.api, .appkit)
- }
-
- func testParseConfigurationUIKit() throws {
- let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "swift", "--api", "uikit")
-
- XCTAssertEqual(config.format, .swift)
- XCTAssertEqual(config.api, .uikit)
- }
+ @Test(arguments: ["appkit", "uikit", "swiftui"])
+ func parseConfigurationAPI(api: String) throws {
+ let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "swift", "--api", api)
- func testAPIConversion() {
- XCTAssertEqual(CommandLine.makeTextAPI(for: nil), .swiftUI)
- XCTAssertEqual(CommandLine.makeTextAPI(for: .appkit), .appKit)
- XCTAssertEqual(CommandLine.makeTextAPI(for: .uikit), .uiKit)
+ #expect(config.format == .swift)
+ #expect(config.api?.rawValue == api)
}
- func testParseConfigurationScale3x() throws {
- let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "png", "--scale", "3x")
-
- XCTAssertEqual(config.output, URL(fileURLWithPath: "/file@3x.png"))
- XCTAssertEqual(config.scale, .superRetina)
+ @Test
+ func textAPIConversion() {
+ #expect(CommandLine.makeTextAPI(for: nil) == .swiftUI)
+ #expect(CommandLine.makeTextAPI(for: .appkit) == .appKit)
+ #expect(CommandLine.makeTextAPI(for: .uikit) == .uiKit)
}
- func testParseConfigurationPrecision() throws {
+ @Test
+ func parseConfigurationPrecision() throws {
let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "swift", "--precision", "3")
- XCTAssertEqual(config.precision, 3)
- }
-
- func testParseConfigurationPrecisionInvalid() {
- XCTAssertThrowsError(
- try parseConfiguration("swiftdraw", "file.svg", "--format", "swift", "--precision", "abc")
- )
+ #expect(config.precision == 3)
}
- func testParseConfigurationSizeInvalid() {
- XCTAssertThrowsError(
- try parseConfiguration("swiftdraw", "file.svg", "--format", "png", "--size", "abc")
- )
- XCTAssertThrowsError(
- try parseConfiguration("swiftdraw", "file.svg", "--format", "png", "--size", "0x0")
- )
- XCTAssertThrowsError(
- try parseConfiguration("swiftdraw", "file.svg", "--format", "png", "--size", "-10x20")
- )
- }
-
- func testParseConfigurationScaleInvalid() {
- XCTAssertThrowsError(
- try parseConfiguration("swiftdraw", "file.svg", "--format", "png", "--scale", "5x")
- )
- }
-
- func testParseConfigurationSwiftUIAPI() throws {
- let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "swift", "--api", "swiftui")
-
- XCTAssertEqual(config.format, .swift)
- XCTAssertEqual(config.api, .swiftui)
- }
-
- func testParseConfigurationInvalidAPI() {
- XCTAssertThrowsError(
- try parseConfiguration("swiftdraw", "file.svg", "--format", "swift", "--api", "flutter")
+ @Test
+ func parseConfigurationHideUnsupportedFilters() throws {
+ let config = try parseConfiguration(
+ "swiftdraw",
+ "file.svg",
+ "--format",
+ "png",
+ "--hide-unsupported-filters"
)
- }
- func testParseConfigurationHideUnsupportedFilters() throws {
- let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "png", "--hide-unsupported-filters")
-
- XCTAssertTrue(config.options.contains(.hideUnsupportedFilters))
+ #expect(config.options.contains(.hideUnsupportedFilters))
}
- func testParseConfigurationLegacyInsets() throws {
+ @Test
+ func parseConfigurationLegacyInsets() throws {
let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "sfsymbol", "--legacy")
- XCTAssertTrue(config.isLegacyInsetsEnabled)
- }
-
- func testParseConfigurationSymbolSize() throws {
- let configSmall = try parseConfiguration("swiftdraw", "file.svg", "--format", "sfsymbol", "--size", "small")
- XCTAssertEqual(configSmall.symbolSize, .small)
-
- let configMedium = try parseConfiguration("swiftdraw", "file.svg", "--format", "sfsymbol", "--size", "medium")
- XCTAssertEqual(configMedium.symbolSize, .medium)
-
- let configLarge = try parseConfiguration("swiftdraw", "file.svg", "--format", "sfsymbol", "--size", "large")
- XCTAssertEqual(configLarge.symbolSize, .large)
+ #expect(config.isLegacyInsetsEnabled)
}
- func testParseConfigurationSymbolSizeInvalid() {
- XCTAssertThrowsError(
- try parseConfiguration("swiftdraw", "file.svg", "--format", "sfsymbol", "--size", "tiny")
- )
+ @Test(arguments: ["small", "medium", "large"])
+ func parseConfigurationSymbolSize(size: String) throws {
+ let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "sfsymbol", "--size", size)
+ #expect(config.symbolSize.map { "\($0)" } == size)
}
- func testParseConfigurationCustomOutput() throws {
+ @Test
+ func parseConfigurationCustomOutput() throws {
let config = try parseConfiguration("swiftdraw", "file.svg", "--format", "png", "--output", "custom.png")
- XCTAssertEqual(config.output, URL(fileURLWithPath: "/custom.png"))
- }
-
- func testNewURLForSFSymbol() {
- let svg = URL(fileURLWithPath: "/test/icon.svg")
- XCTAssertEqual(svg.newURL(for: .sfsymbol, scale: .default), URL(fileURLWithPath: "/test/icon-symbol.svg"))
- }
-
- func testNewURLForJPEG() {
- let svg = URL(fileURLWithPath: "/test/photo.svg")
- XCTAssertEqual(svg.newURL(for: .jpeg, scale: .retina), URL(fileURLWithPath: "/test/photo.jpg"))
+ #expect(config.output == URL(fileURLWithPath: "/custom.png"))
}
- func testNewURLForSwift() {
- let svg = URL(fileURLWithPath: "/test/icon.svg")
- XCTAssertEqual(svg.newURL(for: .swift, scale: .default), URL(fileURLWithPath: "/test/icon.swift"))
+ @Test
+ func emptyInsets() {
+ #expect(CommandLine.Insets().isEmpty)
+ #expect(!CommandLine.Insets(top: 1).isEmpty)
+ #expect(!CommandLine.Insets(left: 1).isEmpty)
+ #expect(!CommandLine.Insets(bottom: 1).isEmpty)
+ #expect(!CommandLine.Insets(right: 1).isEmpty)
}
- func testInsetsIsEmpty() {
- XCTAssertTrue(CommandLine.Insets().isEmpty)
- XCTAssertFalse(CommandLine.Insets(top: 1).isEmpty)
- XCTAssertFalse(CommandLine.Insets(left: 1).isEmpty)
- XCTAssertFalse(CommandLine.Insets(bottom: 1).isEmpty)
- XCTAssertFalse(CommandLine.Insets(right: 1).isEmpty)
- }
-
- func testParseConfigurationUltralightStrokeWidth() throws {
+ @Test
+ func parseConfigurationUltralightStrokeWidth() throws {
let config = try parseConfiguration(
"swiftdraw",
"file.svg",
@@ -270,11 +245,12 @@ final class CommandLineConfigurationTests: XCTestCase {
"--ultralight-stroke-width",
"50%"
)
- XCTAssertEqual(config.ultralightStrokeScale?.multiplier, 0.5)
- XCTAssertNil(config.blackStrokeScale)
+ #expect(config.ultralightStrokeScale?.multiplier == 0.5)
+ #expect(config.blackStrokeScale == nil)
}
- func testParseConfigurationBlackStrokeWidth() throws {
+ @Test
+ func parseConfigurationBlackStrokeWidth() throws {
let config = try parseConfiguration(
"swiftdraw",
"file.svg",
@@ -283,35 +259,16 @@ final class CommandLineConfigurationTests: XCTestCase {
"--black-stroke-width",
"2"
)
- XCTAssertEqual(config.blackStrokeScale?.multiplier, 2.0)
- XCTAssertNil(config.ultralightStrokeScale)
- }
-
- func testParseConfigurationStrokeWidthInvalid() {
- XCTAssertThrowsError(
- try parseConfiguration(
- "swiftdraw",
- "file.svg",
- "--format",
- "sfsymbol",
- "--ultralight-stroke-width",
- "abc"
- )
- )
- XCTAssertThrowsError(
- try parseConfiguration(
- "swiftdraw",
- "file.svg",
- "--format",
- "sfsymbol",
- "--black-stroke-width",
- "0"
- )
- )
+ #expect(config.blackStrokeScale?.multiplier == 2.0)
+ #expect(config.ultralightStrokeScale == nil)
}
}
private func parseConfiguration(_ args: String...) throws -> CommandLine.Configuration {
+ try parseConfiguration(args)
+}
+
+private func parseConfiguration(_ args: [String]) throws -> CommandLine.Configuration {
try CommandLine.parseConfiguration(from: args, baseDirectory: URL(directory: "/"))
}
diff --git a/SwiftDraw/Tests/Formatter/CoordinateTests.swift b/SwiftDraw/Tests/Formatter/CoordinateTests.swift
index 1a11bf83..4c2d3db0 100644
--- a/SwiftDraw/Tests/Formatter/CoordinateTests.swift
+++ b/SwiftDraw/Tests/Formatter/CoordinateTests.swift
@@ -29,84 +29,86 @@
// 3. This notice may not be removed or altered from any source distribution.
//
-import XCTest
+import Testing
@testable import SwiftDraw
-final class CoordinateTests: XCTestCase {
+struct CoordinateTests {
- func testPrecisionMax() {
+ @Test(
+ arguments: [
+ (1.0, "1.0"),
+ (1.01, "1.01"),
+ (1.001, "1.001"),
+ (1.0001, "1.0001"),
+ (1.00001, "1.00001"),
+ (1.000001, "1.000001"),
+ (1.0000001, "1.0000001"),
+ (1e-20, "1e-20"),
+ (12e-20, "1.2e-19"),
+ ] as [(Double, String)]
+ )
+ func maximumPrecision(value: Double, expected: String) {
let f = CoordinateFormatter(precision: .maximum)
-
- XCTAssertEqual(f.format(1.0), "1.0")
- XCTAssertEqual(f.format(1.01), "1.01")
- XCTAssertEqual(f.format(1.001), "1.001")
- XCTAssertEqual(f.format(1.0001), "1.0001")
- XCTAssertEqual(f.format(1.00001), "1.00001")
- XCTAssertEqual(f.format(1.000001), "1.000001")
- XCTAssertEqual(f.format(1.0000001), "1.0000001")
- XCTAssertEqual(f.format(1e-20), "1e-20")
- XCTAssertEqual(f.format(12e-20), "1.2e-19")
+ #expect(f.format(value) == expected)
}
- func testPrecisionCapped() {
+ @Test(
+ arguments: [
+ (1.0, "1"),
+ (1.01, "1.01"),
+ (1.001, "1.001"),
+ (1.0001, "1.0001"),
+ (1.00001, "1"),
+ (1.000001, "1"),
+ (1.0000001, "1"),
+ (1e-20, "0"),
+ (12e-20, "0"),
+ ] as [(Double, String)]
+ )
+ func precisionCappedAtFourPlaces(value: Double, expected: String) {
let f = CoordinateFormatter(precision: .capped(max: 4))
-
- XCTAssertEqual(f.format(1.0), "1")
- XCTAssertEqual(f.format(1.01), "1.01")
- XCTAssertEqual(f.format(1.001), "1.001")
- XCTAssertEqual(f.format(1.0001), "1.0001")
- XCTAssertEqual(f.format(1.00001), "1")
- XCTAssertEqual(f.format(1.000001), "1")
- XCTAssertEqual(f.format(1.0000001), "1")
- XCTAssertEqual(f.format(1e-20), "0")
- XCTAssertEqual(f.format(12e-20), "0")
+ #expect(f.format(value) == expected)
}
- func testPrecisionCapped2() {
+ @Test(
+ arguments: [
+ (1.0, "1"),
+ (1.01, "1.01"),
+ (114.052001953125, "114.05"),
+ (1.001, "1"),
+ (1.0001, "1"),
+ (1.00001, "1"),
+ (1.000001, "1"),
+ (1.0000001, "1"),
+ (1e-20, "0"),
+ (12e-20, "0"),
+ ] as [(Double, String)]
+ )
+ func precisionCappedAtTwoPlaces(value: Double, expected: String) {
let f = CoordinateFormatter(precision: .capped(max: 2))
-
- XCTAssertEqual(f.format(1.0), "1")
- XCTAssertEqual(f.format(1.01), "1.01")
- XCTAssertEqual(f.format(114.052001953125), "114.05")
- XCTAssertEqual(f.format(1.001), "1")
- XCTAssertEqual(f.format(1.0001), "1")
- XCTAssertEqual(f.format(1.00001), "1")
- XCTAssertEqual(f.format(1.000001), "1")
- XCTAssertEqual(f.format(1.0000001), "1")
- XCTAssertEqual(f.format(1e-20), "0")
- XCTAssertEqual(f.format(12e-20), "0")
-
- XCTAssertEqual(
- f.format(114.052001953125, precision: .capped(max: 4)),
- "114.052"
- )
- XCTAssertEqual(
- f.format(1.0001, precision: .capped(max: 4)),
- "1.0001"
- )
+ #expect(f.format(value) == expected)
}
- func testDelimeterSpace() {
- let f = CoordinateFormatter(delimeter: .space)
-
- XCTAssertEqual(f.format(2.05), "2.05")
- XCTAssertEqual(f.format(2.05, 4.5), "2.05 4.5")
- XCTAssertEqual(f.format(2.05, 4.5, 10, 20), "2.05 4.5 10 20")
- }
-
- func testDelimeterComma() {
- let f = CoordinateFormatter(delimeter: .comma)
+ @Test
+ func precisionCanBeOverriddenPerCall() {
+ let f = CoordinateFormatter(precision: .capped(max: 2))
- XCTAssertEqual(f.format(2.05), "2.05")
- XCTAssertEqual(f.format(2.05, 4.5), "2.05,4.5")
- XCTAssertEqual(f.format(2.05, 4.5, 10, 20), "2.05,4.5,10,20")
+ #expect(f.format(114.052001953125, precision: .capped(max: 4)) == "114.052")
+ #expect(f.format(1.0001, precision: .capped(max: 4)) == "1.0001")
}
- func testDelimeterCommaSpace() {
- let f = CoordinateFormatter(delimeter: .commaSpace)
+ @Test(
+ arguments: [
+ (.space, "2.05 4.5", "2.05 4.5 10 20"),
+ (.comma, "2.05,4.5", "2.05,4.5,10,20"),
+ (.commaSpace, "2.05, 4.5", "2.05, 4.5, 10, 20"),
+ ] as [(CoordinateFormatter.Delimeter, String, String)]
+ )
+ func delimeterSeparatesCoordinates(delimeter: CoordinateFormatter.Delimeter, two: String, four: String) {
+ let f = CoordinateFormatter(delimeter: delimeter)
- XCTAssertEqual(f.format(2.05), "2.05")
- XCTAssertEqual(f.format(2.05, 4.5), "2.05, 4.5")
- XCTAssertEqual(f.format(2.05, 4.5, 10, 20), "2.05, 4.5, 10, 20")
+ #expect(f.format(2.05) == "2.05")
+ #expect(f.format(2.05, 4.5) == two)
+ #expect(f.format(2.05, 4.5, 10, 20) == four)
}
}
diff --git a/SwiftDraw/Tests/Formatter/XML.FormatterTests.swift b/SwiftDraw/Tests/Formatter/XML.FormatterTests.swift
index cb175e8d..e65aeebf 100644
--- a/SwiftDraw/Tests/Formatter/XML.FormatterTests.swift
+++ b/SwiftDraw/Tests/Formatter/XML.FormatterTests.swift
@@ -29,13 +29,15 @@
// 3. This notice may not be removed or altered from any source distribution.
//
+import Foundation
import SwiftDrawDOM
+import Testing
@testable import SwiftDraw
-import XCTest
-final class XMLFormatterTests: XCTestCase {
+struct XMLFormatterTests {
- func testAA() {
+ @Test
+ func encodesElementWithEscapedAttributes() {
let formatter = XML.Formatter(spaces: 2)
let element = XML.Element(
@@ -45,26 +47,23 @@ final class XMLFormatterTests: XCTestCase {
element.children.append(.init(name: "circle"))
- XCTAssertEqual(
- formatter.encodeElement(element),
- """
+ let expected = """
"""
- )
+ #expect(formatter.encodeElement(element) == expected)
}
- func testBB() throws {
+ @Test
+ func encodesGradientDocument() throws {
let url = try Bundle.test.url(forResource: "gradient-gratification.svg")
let svg = try DOM.SVG.parse(fileURL: url)
let element = try XML.Formatter.SVG().makeElement(from: svg)
let formatter = XML.Formatter(spaces: 2)
- XCTAssertEqual(
- formatter.encodeRootElement(element),
- """
+ let expected = """
"""
- )
+ #expect(formatter.encodeRootElement(element) == expected)
}
- func testFractionalRootSizeRoundTrips() throws {
+ @Test
+ func fractionalRootSizeRoundTrips() throws {
let svg = DOM.SVG(width: 5.8, height: 80.5)
svg.viewBox = .init(x: 0, y: 0, width: 10, height: 10)
let element = try XML.Formatter.SVG().makeElement(from: svg)
- XCTAssertEqual(element.attributes["width"], "5.8")
- XCTAssertEqual(element.attributes["height"], "80.5")
+ #expect(element.attributes["width"] == "5.8")
+ #expect(element.attributes["height"] == "80.5")
let data = XML.Formatter(spaces: 2).encodeRootElement(element)
let parsed = try DOM.SVG.parse(data: Data(data.utf8))
- XCTAssertEqual(parsed.width, 5.8)
- XCTAssertEqual(parsed.height, 80.5)
+ #expect(parsed.width == 5.8)
+ #expect(parsed.height == 80.5)
}
- func testSymbol() throws {
+ @Test
+ func encodesSymbolDocument() throws {
let url = try Bundle.test.url(forResource: "symbol-test.svg")
let svg = try DOM.SVG.parse(fileURL: url)
let element = try XML.Formatter.SVG().makeElement(from: svg)
let formatter = XML.Formatter(spaces: 2)
- XCTAssertEqual(
- formatter.encodeRootElement(element),
- """
+ let expected = """
"""
- )
+ #expect(formatter.encodeRootElement(element) == expected)
}
}
diff --git a/SwiftDraw/Tests/LayerTree/LayerTree.Builder.GradientTests.swift b/SwiftDraw/Tests/LayerTree/LayerTree.Builder.GradientTests.swift
index da4ca5ad..64235b78 100644
--- a/SwiftDraw/Tests/LayerTree/LayerTree.Builder.GradientTests.swift
+++ b/SwiftDraw/Tests/LayerTree/LayerTree.Builder.GradientTests.swift
@@ -30,12 +30,13 @@
//
@testable import SwiftDrawDOM
-import XCTest
@testable import SwiftDraw
+import Testing
-final class LayerTreeBuilderGradientTests: XCTestCase {
+struct LayerTreeBuilderGradientTests {
- func testRadialGradient_InheritsStops_FromLinearGradient() throws {
+ @Test
+ func radialGradientInheritsStopsFromLinearGradient() throws {
let svg = try DOM.SVG.parse(
xml: #"""