From 6305b70502e3dc2759332da4b183f6f75002030e Mon Sep 17 00:00:00 2001 From: Radu Ursache Date: Tue, 24 Mar 2026 10:58:42 +0200 Subject: [PATCH] Add test verifying SVG length unit conversion (cm, in) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unit conversion for SVG root width/height attributes already works correctly (10cm → 377px, 2in → 192px). Adding regression test. Relates to #42 --- DOM/Tests/Parser.SVGTests.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/DOM/Tests/Parser.SVGTests.swift b/DOM/Tests/Parser.SVGTests.swift index 4abb011..b1fc05e 100644 --- a/DOM/Tests/Parser.SVGTests.swift +++ b/DOM/Tests/Parser.SVGTests.swift @@ -56,6 +56,18 @@ struct ParserSVGTests { #expect(parsed != expected2) } + @Test + func svgWithUnits() throws { + let node = XML.Element(name: "svg", attributes: ["width": "10cm", "height": "2in"]) + let parser = DOMXMLParser() + + let parsed = try parser.parseSVG(node) + // 10cm = 10 * 37.795 = 377.95 → truncated to 377 + #expect(parsed.width == 377) + // 2in = 2 * 96 = 192 + #expect(parsed.height == 192) + } + @Test func parseSVGInvalidNode() { let node = XML.Element(name: "svg2", attributes: ["width": "100", "height": "200"])