|
29 | 29 | // 3. This notice may not be removed or altered from any source distribution. |
30 | 30 | // |
31 | 31 |
|
32 | | - |
33 | | -import XCTest |
| 32 | +import Foundation |
| 33 | +import Testing |
34 | 34 | @testable import SwiftDrawDOM |
35 | 35 |
|
36 | | -final class ValueParserTests: XCTestCase { |
| 36 | +@Suite("Value Parser Tests") |
| 37 | +struct ValueParserTests { |
37 | 38 |
|
38 | 39 | var parser = XMLParser.ValueParser() |
39 | 40 |
|
40 | | - func testFloat() { |
41 | | - XCTAssertEqual(try parser.parseFloat("10"), 10) |
42 | | - XCTAssertEqual(try parser.parseFloat("10.0"), 10.0) |
| 41 | + @Test |
| 42 | + func float() throws { |
| 43 | + #expect(try parser.parseFloat("10") == 10) |
| 44 | + #expect(try parser.parseFloat("10.0") == 10.0) |
43 | 45 |
|
44 | | - XCTAssertThrowsError(try parser.parseFloat("")) |
45 | | - //XCTAssertThrowsError(try parser.parseFloat("10a")) |
| 46 | + #expect(throws: (any Error).self) { _ = try parser.parseFloat("") } |
| 47 | + // #expect(throws: (any Error).self) { _ = try parser.parseFloat("10a") } |
46 | 48 | } |
47 | 49 |
|
48 | | - func testFloats() { |
49 | | - XCTAssertEqual(try parser.parseFloats("10 20 30.5"), [10, 20, 30.5]) |
50 | | - XCTAssertEqual(try parser.parseFloats("10.0"), [10.0]) |
51 | | - XCTAssertEqual(try parser.parseFloats("5 10 1 5"), [5, 10, 1, 5]) |
52 | | - XCTAssertEqual(try parser.parseFloats(" 1, 2.5, 3.5 "), [1, 2.5, 3.5]) |
53 | | - XCTAssertEqual(try parser.parseFloats(" "), []) |
54 | | - XCTAssertEqual(try parser.parseFloats(""), []) |
55 | | - |
56 | | - //XCTAssertThrowsError(try parser.parseFloats("")) |
57 | | - //XCTAssertThrowsError(try parser.parseFloat("10a")) |
| 50 | + @Test |
| 51 | + func floats() throws { |
| 52 | + #expect(try parser.parseFloats("10 20 30.5") == [10, 20, 30.5]) |
| 53 | + #expect(try parser.parseFloats("10.0") == [10.0]) |
| 54 | + #expect(try parser.parseFloats("5 10 1 5") == [5, 10, 1, 5]) |
| 55 | + #expect(try parser.parseFloats(" 1, 2.5, 3.5 ") == [1, 2.5, 3.5]) |
| 56 | + #expect(try parser.parseFloats(" ") == []) |
| 57 | + #expect(try parser.parseFloats("") == []) |
| 58 | + |
| 59 | + // #expect(throws: (any Error).self) { _ = try parser.parseFloats("") } |
| 60 | + // #expect(throws: (any Error).self) { _ = try parser.parseFloat("10a") } |
58 | 61 | } |
59 | 62 |
|
60 | | - func testPercentage() { |
61 | | - XCTAssertEqual(try parser.parsePercentage("0"), 0) |
62 | | - XCTAssertEqual(try parser.parsePercentage("1"), 1) |
63 | | - XCTAssertEqual(try parser.parsePercentage("0.45"), 0.45) |
64 | | - XCTAssertEqual(try parser.parsePercentage("0.0%"), 0) |
65 | | - XCTAssertEqual(try parser.parsePercentage("100%"), 1) |
66 | | - XCTAssertEqual(try parser.parsePercentage("55%"), 0.55) |
67 | | - XCTAssertEqual(try parser.parsePercentage("10.25%"), 0.1025) |
68 | | - |
69 | | - XCTAssertThrowsError(try parser.parsePercentage("100")) |
70 | | - XCTAssertThrowsError(try parser.parsePercentage("asd")) |
71 | | - XCTAssertThrowsError(try parser.parsePercentage(" ")) |
72 | | - //XCTAssertThrowsError(try parser.parseFloat("10a")) |
| 63 | + @Test |
| 64 | + func percentage() throws { |
| 65 | + #expect(try parser.parsePercentage("0") == 0) |
| 66 | + #expect(try parser.parsePercentage("1") == 1) |
| 67 | + #expect(try parser.parsePercentage("0.45") == 0.45) |
| 68 | + #expect(try parser.parsePercentage("0.0%") == 0) |
| 69 | + #expect(try parser.parsePercentage("100%") == 1) |
| 70 | + #expect(try parser.parsePercentage("55%") == 0.55) |
| 71 | + #expect(try parser.parsePercentage("10.25%") == 0.1025) |
| 72 | + |
| 73 | + #expect(throws: (any Error).self) { _ = try parser.parsePercentage("100") } |
| 74 | + #expect(throws: (any Error).self) { _ = try parser.parsePercentage("asd") } |
| 75 | + #expect(throws: (any Error).self) { _ = try parser.parsePercentage(" ") } |
| 76 | + // #expect(throws: (any Error).self) { _ = try parser.parseFloat("10a") } |
73 | 77 | } |
74 | 78 |
|
75 | | - func testCoordinate() { |
76 | | - XCTAssertEqual(try parser.parseCoordinate("0"), 0) |
77 | | - XCTAssertEqual(try parser.parseCoordinate("0.0"), 0) |
78 | | - XCTAssertEqual(try parser.parseCoordinate("100"), 100) |
79 | | - XCTAssertEqual(try parser.parseCoordinate("25.0"), 25.0) |
80 | | - XCTAssertEqual(try parser.parseCoordinate("-25.0"), -25.0) |
| 79 | + @Test |
| 80 | + func coordinate() throws { |
| 81 | + #expect(try parser.parseCoordinate("0") == 0) |
| 82 | + #expect(try parser.parseCoordinate("0.0") == 0) |
| 83 | + #expect(try parser.parseCoordinate("100") == 100) |
| 84 | + #expect(try parser.parseCoordinate("25.0") == 25.0) |
| 85 | + #expect(try parser.parseCoordinate("-25.0") == -25.0) |
81 | 86 |
|
82 | | - XCTAssertThrowsError(try parser.parseCoordinate("asd")) |
83 | | - XCTAssertThrowsError(try parser.parseCoordinate(" ")) |
| 87 | + #expect(throws: (any Error).self) { _ = try parser.parseCoordinate("asd") } |
| 88 | + #expect(throws: (any Error).self) { _ = try parser.parseCoordinate(" ") } |
84 | 89 | } |
85 | 90 |
|
86 | | - func testLength() { |
87 | | - XCTAssertEqual(try parser.parseLength("0"), 0) |
88 | | - XCTAssertEqual(try parser.parseLength("100"), 100) |
89 | | - XCTAssertEqual(try parser.parseLength("25"), 25) |
90 | | - XCTAssertEqual(try parser.parseLength("1.3"), 1) //should error? |
| 91 | + @Test |
| 92 | + func length() throws { |
| 93 | + #expect(try parser.parseLength("0") == 0) |
| 94 | + #expect(try parser.parseLength("100") == 100) |
| 95 | + #expect(try parser.parseLength("25") == 25) |
| 96 | + #expect(try parser.parseLength("1.3") == 1) // should error? |
91 | 97 |
|
92 | | - XCTAssertThrowsError(try parser.parseLength("asd")) |
93 | | - XCTAssertThrowsError(try parser.parseLength(" ")) |
94 | | - XCTAssertThrowsError(try parser.parseLength("-25")) |
| 98 | + #expect(throws: (any Error).self) { _ = try parser.parseLength("asd") } |
| 99 | + #expect(throws: (any Error).self) { _ = try parser.parseLength(" ") } |
| 100 | + #expect(throws: (any Error).self) { _ = try parser.parseLength("-25") } |
95 | 101 | } |
96 | 102 |
|
97 | | - func testBool() { |
98 | | - XCTAssertEqual(try parser.parseBool("false"), false) |
99 | | - XCTAssertEqual(try parser.parseBool("FALSE"), false) |
100 | | - XCTAssertEqual(try parser.parseBool("true"), true) |
101 | | - XCTAssertEqual(try parser.parseBool("TRUE"), true) |
102 | | - XCTAssertEqual(try parser.parseBool("1"), true) |
103 | | - XCTAssertEqual(try parser.parseBool("0"), false) |
104 | | - |
105 | | - XCTAssertThrowsError(try parser.parseBool("asd")) |
106 | | - XCTAssertThrowsError(try parser.parseBool("yes")) |
| 103 | + @Test |
| 104 | + func bools() throws { |
| 105 | + #expect(try parser.parseBool("false") == false) |
| 106 | + #expect(try parser.parseBool("FALSE") == false) |
| 107 | + #expect(try parser.parseBool("true") == true) |
| 108 | + #expect(try parser.parseBool("TRUE") == true) |
| 109 | + #expect(try parser.parseBool("1") == true) |
| 110 | + #expect(try parser.parseBool("0") == false) |
| 111 | + |
| 112 | + #expect(throws: (any Error).self) { _ = try parser.parseBool("asd") } |
| 113 | + #expect(throws: (any Error).self) { _ = try parser.parseBool("yes") } |
107 | 114 | } |
108 | 115 |
|
109 | | - func testFill() { |
110 | | - XCTAssertEqual(try parser.parseFill("none"), .color(.none)) |
111 | | - XCTAssertEqual(try parser.parseFill("black"), .color(.keyword(.black))) |
112 | | - XCTAssertEqual(try parser.parseFill("red"), .color(.keyword(.red))) |
| 116 | + @Test |
| 117 | + func fill() throws { |
| 118 | + #expect(try parser.parseFill("none") == .color(.none)) |
| 119 | + #expect(try parser.parseFill("black") == .color(.keyword(.black))) |
| 120 | + #expect(try parser.parseFill("red") == .color(.keyword(.red))) |
113 | 121 |
|
114 | | - XCTAssertEqual(try parser.parseFill("rgb(10,20,30)"), .color(.rgbi(10, 20, 30, 1.0))) |
115 | | - XCTAssertEqual(try parser.parseFill("rgb(10%,20%,100%)"), .color(.rgbf(0.1, 0.2, 1.0, 1.0))) |
116 | | - XCTAssertEqual(try parser.parseFill("rgba(10, 20, 30, 0.5)"), .color(.rgbi(10, 20, 30, 0.5))) |
117 | | - XCTAssertEqual(try parser.parseFill("rgba(10%,20%,100%,0.6)"), .color(.rgbf(0.1, 0.2, 1.0, 0.6))) |
118 | | - XCTAssertEqual(try parser.parseFill("#AAFF00"), .color(.hex(170, 255, 0))) |
| 122 | + #expect(try parser.parseFill("rgb(10,20,30)") == .color(.rgbi(10, 20, 30, 1.0))) |
| 123 | + #expect(try parser.parseFill("rgb(10%,20%,100%)") == .color(.rgbf(0.1, 0.2, 1.0, 1.0))) |
| 124 | + #expect(try parser.parseFill("rgba(10, 20, 30, 0.5)") == .color(.rgbi(10, 20, 30, 0.5))) |
| 125 | + #expect(try parser.parseFill("rgba(10%,20%,100%,0.6)") == .color(.rgbf(0.1, 0.2, 1.0, 0.6))) |
| 126 | + #expect(try parser.parseFill("#AAFF00") == .color(.hex(170, 255, 0))) |
119 | 127 |
|
120 | | - XCTAssertEqual(try parser.parseFill("url(#test)"), .url(URL(string: "#test")!)) |
| 128 | + #expect(try parser.parseFill("url(#test)") == .url(URL(string: "#test")!)) |
121 | 129 |
|
122 | | - XCTAssertThrowsError(try parser.parseFill("Ns ")) |
123 | | - XCTAssertThrowsError(try parser.parseFill("d")) |
124 | | - XCTAssertThrowsError(try parser.parseFill("url()")) |
125 | | - //XCTAssertThrowsError(try parser.parseFill("url(asdf")) |
| 130 | + #expect(throws: (any Error).self) { _ = try parser.parseFill("Ns ") } |
| 131 | + #expect(throws: (any Error).self) { _ = try parser.parseFill("d") } |
| 132 | + #expect(throws: (any Error).self) { _ = try parser.parseFill("url()") } |
| 133 | + // #expect(throws: (any Error).self) { _ = try parser.parseFill("url(asdf") } |
126 | 134 | } |
127 | 135 |
|
128 | | - func testUrl() { |
129 | | -#if canImport(Darwin) |
130 | | - XCTAssertEqual(try parser.parseUrl("#testing🐟").fragmentID, "testing🐟") |
131 | | -#else |
132 | | - XCTAssertEqual(try parser.parseUrl("#testing").fragmentID, "testing") |
133 | | -#endif |
134 | | - XCTAssertEqual(try parser.parseUrl("http://www.google.com").host, "www.google.com") |
| 136 | + @Test |
| 137 | + func url() throws { |
| 138 | + #if canImport(Darwin) |
| 139 | + #expect(try parser.parseUrl("#testing🐟").fragmentID == "testing🐟") |
| 140 | + #else |
| 141 | + #expect(try parser.parseUrl("#testing").fragmentID == "testing") |
| 142 | + #endif |
| 143 | + #expect(try parser.parseUrl("http://www.google.com").host == "www.google.com") |
135 | 144 | } |
136 | 145 |
|
137 | | - func testUrlSelector() { |
138 | | - XCTAssertEqual(try parser.parseUrlSelector("url(#testingId)").fragmentID, "testingId") |
139 | | - XCTAssertEqual(try parser.parseUrlSelector("url(http://www.google.com)").host, "www.google.com") |
| 146 | + @Test |
| 147 | + func urlSelector() throws { |
| 148 | + #expect(try parser.parseUrlSelector("url(#testingId)").fragmentID == "testingId") |
| 149 | + #expect(try parser.parseUrlSelector("url(http://www.google.com)").host == "www.google.com") |
140 | 150 |
|
141 | | - XCTAssertThrowsError(try parser.parseUrlSelector("url(#testingId) other")) |
| 151 | + #expect(throws: (any Error).self) { _ = try parser.parseUrlSelector("url(#testingId) other") } |
142 | 152 | } |
143 | 153 |
|
144 | | - func testPoints() { |
145 | | - XCTAssertEqual(try parser.parsePoints("0 1 2 3"), [DOM.Point(0, 1), DOM.Point(2, 3)]) |
146 | | - XCTAssertEqual(try parser.parsePoints("0,1 2,3"), [DOM.Point(0, 1), DOM.Point(2, 3)]) |
147 | | - XCTAssertEqual(try parser.parsePoints("0 1.5 1e4 2.4"), [DOM.Point(0, 1.5), DOM.Point(1e4, 2.4)]) |
148 | | - // XCTAssertEqual(try parser.parsePoints("0 1 2 3 5.0 6.5"), [0, 1 ,2]) |
| 154 | + @Test |
| 155 | + func points() throws { |
| 156 | + #expect(try parser.parsePoints("0 1 2 3") == [DOM.Point(0, 1), DOM.Point(2, 3)]) |
| 157 | + #expect(try parser.parsePoints("0,1 2,3") == [DOM.Point(0, 1), DOM.Point(2, 3)]) |
| 158 | + #expect(try parser.parsePoints("0 1.5 1e4 2.4") == [DOM.Point(0, 1.5), DOM.Point(1e4, 2.4)]) |
| 159 | + // #expect(try parser.parsePoints("0 1 2 3 5.0 6.5") == [0, 1 ,2]) |
149 | 160 | } |
150 | 161 |
|
151 | | - func testRaw() { |
152 | | - XCTAssertEqual(try parser.parseRaw("evenodd"), DOM.FillRule.evenodd) |
153 | | - XCTAssertEqual(try parser.parseRaw("round"), DOM.LineCap.round) |
154 | | - XCTAssertEqual(try parser.parseRaw("miter"), DOM.LineJoin.miter) |
| 162 | + @Test |
| 163 | + func raw() throws { |
| 164 | + #expect(try parser.parseRaw("evenodd") as DOM.FillRule == .evenodd) |
| 165 | + #expect(try parser.parseRaw("round") as DOM.LineCap == .round) |
| 166 | + #expect(try parser.parseRaw("miter") as DOM.LineJoin == .miter) |
155 | 167 |
|
156 | | - XCTAssertThrowsError((try parser.parseRaw("sd")) as DOM.LineJoin) |
| 168 | + #expect(throws: (any Error).self) { |
| 169 | + let _: DOM.LineJoin = try parser.parseRaw("sd") |
| 170 | + } |
157 | 171 | } |
158 | 172 | } |
159 | | - |
160 | | - |
161 | | - |
|
0 commit comments