Skip to content

Commit 233fb0d

Browse files
committed
test: cover SVG string utility edge cases
1 parent fb0da21 commit 233fb0d

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

‎Tests/SVGViewTests/SVGParsingUtilitiesTests.swift‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,54 @@ final class SVGParsingUtilitiesTests: XCTestCase {
3636
}
3737
}
3838

39+
func testCollapsingWhitespaceTrimsEdgesAndCollapsesRuns() {
40+
let values = [
41+
("", ""),
42+
(" ", ""),
43+
(" hello ", "hello"),
44+
("hello world", "hello world"),
45+
("\thello\n\rworld ", "hello world"),
46+
]
47+
48+
for (value, expected) in values {
49+
XCTAssertEqual(
50+
SVGStringUtilities.collapsingWhitespace(in: value),
51+
expected,
52+
value
53+
)
54+
}
55+
}
56+
57+
func testRemovingCharactersMatchingPredicate() {
58+
XCTAssertEqual(
59+
SVGStringUtilities.removing(from: "##shape#", where: { $0 == "#" }),
60+
"shape"
61+
)
62+
XCTAssertEqual(
63+
SVGStringUtilities.removing(from: "100%%", where: { $0 == "%" }),
64+
"100"
65+
)
66+
}
67+
68+
func testSplitOmitsEmptySubsequences() {
69+
XCTAssertEqual(
70+
SVGStringUtilities.split(",10,, 20\t30,") {
71+
$0 == "," || $0.isWhitespace
72+
},
73+
["10", "20", "30"]
74+
)
75+
}
76+
77+
func testStripURLIdentifierRequiresCompleteWrapper() {
78+
XCTAssertEqual(
79+
SVGStringUtilities.stripURLIdentifier("url(#gradient)"),
80+
"gradient"
81+
)
82+
XCTAssertNil(SVGStringUtilities.stripURLIdentifier("#gradient"))
83+
XCTAssertNil(SVGStringUtilities.stripURLIdentifier("url(#gradient"))
84+
XCTAssertNil(SVGStringUtilities.stripURLIdentifier("gradient)"))
85+
}
86+
3987
func testHexUtilitiesMatchFoundationFormatting() {
4088
for value in [0, 1, 15, 16, 127, 255, 256, -1] {
4189
XCTAssertEqual(
@@ -53,6 +101,12 @@ final class SVGParsingUtilitiesTests: XCTestCase {
53101
}
54102
}
55103

104+
func testParseHexRejectsInvalidInput() {
105+
for value in ["", "xyz", "FFgarbage", " FF"] {
106+
XCTAssertNil(SVGStringUtilities.parseHex(value), value)
107+
}
108+
}
109+
56110
func testNumberAndUnitParserMatchesFoundationScanner() {
57111
let values = [
58112
"0",

0 commit comments

Comments
 (0)