Skip to content

Commit 2ca2d58

Browse files
committed
indentation
1 parent a519f08 commit 2ca2d58

16 files changed

+1229
-1228
lines changed

DOM/Tests/DOM+Extensions.swift

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -33,59 +33,59 @@
3333
import Foundation
3434

3535
extension DOM {
36-
37-
static func createLine() -> DOM.Line {
38-
return DOM.Line(x1: 0, y1: 1, x2: 3, y2: 4)
39-
}
40-
41-
static func createCircle() -> DOM.Circle {
42-
return DOM.Circle(cx: 0, cy: 1, r: 2)
43-
}
44-
45-
static func createEllipse() -> DOM.Ellipse {
46-
return DOM.Ellipse(cx: 0, cy: 1, rx: 2, ry: 3)
47-
}
48-
49-
static func createRect() -> DOM.Rect {
50-
return DOM.Rect(x: 0, y: 1, width: 2, height: 3)
51-
}
52-
53-
static func createPolygon() -> DOM.Polygon {
54-
return DOM.Polygon(0, 1, 2, 3, 4, 5)
55-
}
56-
57-
static func createPolyline() -> DOM.Polyline {
58-
return DOM.Polyline(0, 1, 2, 3, 4, 5)
59-
}
60-
61-
static func createText() -> DOM.Text {
62-
return DOM.Text(y: 1, value: "The quick brown fox")
63-
}
64-
65-
static func createPath() -> DOM.Path {
66-
let path = DOM.Path(x: 0, y: 1)
67-
path.segments.append(.move(x: 10, y: 10, space: .absolute))
68-
path.segments.append(.horizontal(x: 10, space: .absolute))
69-
return path
70-
}
71-
72-
static func createGroup() -> DOM.Group {
73-
let group = DOM.Group()
74-
group.childElements.append(createLine())
75-
group.childElements.append(createPolygon())
76-
group.childElements.append(createCircle())
77-
group.childElements.append(createPath())
78-
group.childElements.append(createRect())
79-
group.childElements.append(createEllipse())
80-
return group
81-
}
36+
37+
static func createLine() -> DOM.Line {
38+
return DOM.Line(x1: 0, y1: 1, x2: 3, y2: 4)
39+
}
40+
41+
static func createCircle() -> DOM.Circle {
42+
return DOM.Circle(cx: 0, cy: 1, r: 2)
43+
}
44+
45+
static func createEllipse() -> DOM.Ellipse {
46+
return DOM.Ellipse(cx: 0, cy: 1, rx: 2, ry: 3)
47+
}
48+
49+
static func createRect() -> DOM.Rect {
50+
return DOM.Rect(x: 0, y: 1, width: 2, height: 3)
51+
}
52+
53+
static func createPolygon() -> DOM.Polygon {
54+
return DOM.Polygon(0, 1, 2, 3, 4, 5)
55+
}
56+
57+
static func createPolyline() -> DOM.Polyline {
58+
return DOM.Polyline(0, 1, 2, 3, 4, 5)
59+
}
60+
61+
static func createText() -> DOM.Text {
62+
return DOM.Text(y: 1, value: "The quick brown fox")
63+
}
64+
65+
static func createPath() -> DOM.Path {
66+
let path = DOM.Path(x: 0, y: 1)
67+
path.segments.append(.move(x: 10, y: 10, space: .absolute))
68+
path.segments.append(.horizontal(x: 10, space: .absolute))
69+
return path
70+
}
71+
72+
static func createGroup() -> DOM.Group {
73+
let group = DOM.Group()
74+
group.childElements.append(createLine())
75+
group.childElements.append(createPolygon())
76+
group.childElements.append(createCircle())
77+
group.childElements.append(createPath())
78+
group.childElements.append(createRect())
79+
group.childElements.append(createEllipse())
80+
return group
81+
}
8282
}
8383

8484
// Equatable just for tests
8585

8686
extension DOM.GraphicsElement: Swift.Equatable {
87-
static func ==(lhs: DOM.GraphicsElement, rhs: DOM.GraphicsElement) -> Bool {
88-
let toString: (Any) -> String = { var text = ""; dump($0, to: &text); return text }
89-
return toString(lhs) == toString(rhs)
90-
}
87+
static func ==(lhs: DOM.GraphicsElement, rhs: DOM.GraphicsElement) -> Bool {
88+
let toString: (Any) -> String = { var text = ""; dump($0, to: &text); return text }
89+
return toString(lhs) == toString(rhs)
90+
}
9191
}

DOM/Tests/DOM.PresentationAttributesTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,21 @@ final class PresentationAttributesTests: XCTestCase {
163163
XCTAssertEqual(
164164
DOM.presentationAttributes(for: .circle(id: "c1", class: "b c"),
165165
styles: [sheet])
166-
.opacity,
166+
.opacity,
167167
0.5
168168
)
169169

170170
XCTAssertEqual(
171171
DOM.presentationAttributes(for: .circle(id: "c2", class: "b c"),
172172
styles: [sheet])
173-
.opacity,
173+
.opacity,
174174
0.2
175175
)
176176

177177
XCTAssertEqual(
178178
DOM.presentationAttributes(for: .circle(id: "c2", class: "z"),
179179
styles: [sheet])
180-
.opacity,
180+
.opacity,
181181
1
182182
)
183183
}

DOM/Tests/Parser.AttributesTests.swift

Lines changed: 116 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -33,132 +33,132 @@ import XCTest
3333
@testable import SwiftDrawDOM
3434

3535
final class AttributeParserTests: XCTestCase {
36-
37-
// func testParser() {
38-
// let parser = XMLParser.Att
39-
// let att = ["x": "20"]
40-
// XCTAssertThrowsError(try att.parse("x", { _ in throw XMLParser.Error.invalid }))
41-
// }
42-
43-
func testParserOrder() {
44-
let parser = XMLParser.ValueParser()
4536

46-
let att = XMLParser.Attributes(parser: parser,
47-
element: ["x": "10", "y": "20.0", "fill": "red"],
48-
style: ["x": "d", "fill": "green"])
37+
// func testParser() {
38+
// let parser = XMLParser.Att
39+
// let att = ["x": "20"]
40+
// XCTAssertThrowsError(try att.parse("x", { _ in throw XMLParser.Error.invalid }))
41+
// }
4942

50-
//parse from style
51-
XCTAssertEqual(try att.parseColor("fill"), .keyword(.green))
52-
XCTAssertThrowsError(try att.parseFloat("x"))
43+
func testParserOrder() {
44+
let parser = XMLParser.ValueParser()
45+
46+
let att = XMLParser.Attributes(parser: parser,
47+
element: ["x": "10", "y": "20.0", "fill": "red"],
48+
style: ["x": "d", "fill": "green"])
49+
50+
//parse from style
51+
XCTAssertEqual(try att.parseColor("fill"), .keyword(.green))
52+
XCTAssertThrowsError(try att.parseFloat("x"))
53+
54+
//missing throws error
55+
XCTAssertThrowsError(try att.parseFloat("other"))
56+
//missing returns optional
57+
XCTAssertNil(try att.parseFloat("other") as DOM.Float?)
58+
59+
//fall through to element
60+
XCTAssertEqual(try att.parseFloat("y"), 20)
61+
62+
//SkipInvalidAttributes
63+
let another = XMLParser.Attributes(parser: parser,
64+
options: [.skipInvalidAttributes],
65+
element: att.element,
66+
style: att.style)
67+
68+
69+
XCTAssertEqual(try another.parseColor("fill"), .keyword(.green))
70+
XCTAssertEqual(try another.parseFloat("x"), 10)
71+
XCTAssertEqual(try another.parseFloat("y"), 20)
72+
73+
//missing throws error
74+
XCTAssertThrowsError(try another.parseFloat("other"))
75+
//missing returns optional
76+
XCTAssertNil(try another.parseFloat("other") as DOM.Float?)
77+
//invalid returns optional
78+
XCTAssertNil(try another.parseColor("x") as DOM.Color?)
79+
}
5380

54-
//missing throws error
55-
XCTAssertThrowsError(try att.parseFloat("other"))
56-
//missing returns optional
57-
XCTAssertNil(try att.parseFloat("other") as DOM.Float?)
81+
func testDictionary() {
82+
let att = ["x": "20", "y": "30", "fill": "#a0a0a0", "display": "none", "some": "random"]
83+
84+
XCTAssertEqual(try att.parseCoordinate("x"), 20.0)
85+
XCTAssertEqual(try att.parseCoordinate("y"), 30.0)
86+
XCTAssertEqual(try att.parseColor("fill"), .hex(160, 160, 160))
87+
XCTAssertEqual(try att.parseRaw("display"), DOM.DisplayMode.none)
88+
89+
XCTAssertThrowsError(try att.parseFloat("other"))
90+
XCTAssertThrowsError(try att.parseColor("some"))
91+
92+
//missing returns optional
93+
XCTAssertNil(try att.parseFloat("other") as DOM.Float?)
94+
}
5895

59-
//fall through to element
60-
XCTAssertEqual(try att.parseFloat("y"), 20)
96+
func testParseString() {
97+
let att = ["x": "20", "some": "random"]
98+
XCTAssertEqual(try att.parseString("x"), "20")
99+
XCTAssertThrowsError(try att.parseString("missing"))
100+
}
61101

62-
//SkipInvalidAttributes
63-
let another = XMLParser.Attributes(parser: parser,
64-
options: [.skipInvalidAttributes],
65-
element: att.element,
66-
style: att.style)
102+
func testParseFloat() {
103+
let att = ["x": "20", "some": "random"]
104+
XCTAssertEqual(try att.parseFloat("x"), 20.0)
105+
XCTAssertNil(try att.parseFloat("missing"))
106+
XCTAssertThrowsError(try att.parseFloat("some"))
107+
}
67108

109+
func testParseFloats() {
110+
let att = ["x": "20 30 40", "some": "random"]
111+
XCTAssertEqual(try att.parseFloats("x"), [20.0, 30.0, 40.0])
112+
XCTAssertThrowsError(try att.parseFloats("some"))
113+
}
68114

69-
XCTAssertEqual(try another.parseColor("fill"), .keyword(.green))
70-
XCTAssertEqual(try another.parseFloat("x"), 10)
71-
XCTAssertEqual(try another.parseFloat("y"), 20)
115+
func testParsePoints() {
116+
let att = ["x": "20 30 40 50", "some": "random"]
117+
XCTAssertEqual(try att.parsePoints("x"), [DOM.Point(20, 30), DOM.Point(40, 50)])
118+
XCTAssertNil(try att.parsePoints("missing"))
119+
XCTAssertThrowsError(try att.parsePoints("some"))
120+
XCTAssertThrowsError(try att.parsePoints("some") as [DOM.Point]?)
121+
}
72122

73-
//missing throws error
74-
XCTAssertThrowsError(try another.parseFloat("other"))
75-
//missing returns optional
76-
XCTAssertNil(try another.parseFloat("other") as DOM.Float?)
77-
//invalid returns optional
78-
XCTAssertNil(try another.parseColor("x") as DOM.Color?)
79-
}
80-
81-
func testDictionary() {
82-
let att = ["x": "20", "y": "30", "fill": "#a0a0a0", "display": "none", "some": "random"]
123+
func testParseLength() {
124+
let att = ["x": "20", "y": "aa"]
125+
XCTAssertEqual(try att.parseLength("x"), 20)
126+
XCTAssertNil(try att.parseLength("missing"))
127+
XCTAssertThrowsError(try att.parseLength("y"))
128+
XCTAssertThrowsError(try att.parseLength("y") as DOM.Length?)
129+
}
83130

84-
XCTAssertEqual(try att.parseCoordinate("x"), 20.0)
85-
XCTAssertEqual(try att.parseCoordinate("y"), 30.0)
86-
XCTAssertEqual(try att.parseColor("fill"), .hex(160, 160, 160))
87-
XCTAssertEqual(try att.parseRaw("display"), DOM.DisplayMode.none)
131+
func testParseBool() {
132+
let att = ["x": "true", "y": "5"]
133+
XCTAssertEqual(try att.parseBool("x"), true)
134+
XCTAssertNil(try att.parseBool("missing"))
135+
XCTAssertThrowsError(try att.parseBool("y"))
136+
XCTAssertThrowsError(try att.parseBool("y") as Bool?)
137+
}
88138

89-
XCTAssertThrowsError(try att.parseFloat("other"))
90-
XCTAssertThrowsError(try att.parseColor("some"))
139+
func testParseURL() {
140+
let att = ["clip": "http://www.test.com", "mask": "20 twenty"]
141+
XCTAssertEqual(try att.parseUrl("clip"), URL(string: "http://www.test.com"))
142+
XCTAssertNil(try att.parseUrl("missing"))
143+
XCTAssertThrowsError(try att.parseUrl(" "))
144+
}
145+
146+
func testParseURLSelector() {
147+
let att = ["clip": "url(#shape)", "mask": "aa"]
148+
XCTAssertEqual(try att.parseUrlSelector("clip"), URL(string: "#shape"))
149+
XCTAssertNil(try att.parseUrlSelector("missing"))
150+
XCTAssertThrowsError(try att.parseUrlSelector("mask"))
151+
}
152+
//
153+
// func parseString(_ key: String) throws -> String {
154+
// return try parse(key) { $0 }
155+
// }
156+
//
157+
// func parseFloat(_ key: String) throws -> DOM.Float {
158+
// return try parse(key) { return try parser.parseFloat($0) }
159+
// }
160+
//
161+
// func parseFloats(_ key: String) throws -> [DOM.Float] {
91162

92-
//missing returns optional
93-
XCTAssertNil(try att.parseFloat("other") as DOM.Float?)
94-
}
95-
96-
func testParseString() {
97-
let att = ["x": "20", "some": "random"]
98-
XCTAssertEqual(try att.parseString("x"), "20")
99-
XCTAssertThrowsError(try att.parseString("missing"))
100-
}
101-
102-
func testParseFloat() {
103-
let att = ["x": "20", "some": "random"]
104-
XCTAssertEqual(try att.parseFloat("x"), 20.0)
105-
XCTAssertNil(try att.parseFloat("missing"))
106-
XCTAssertThrowsError(try att.parseFloat("some"))
107-
}
108-
109-
func testParseFloats() {
110-
let att = ["x": "20 30 40", "some": "random"]
111-
XCTAssertEqual(try att.parseFloats("x"), [20.0, 30.0, 40.0])
112-
XCTAssertThrowsError(try att.parseFloats("some"))
113-
}
114-
115-
func testParsePoints() {
116-
let att = ["x": "20 30 40 50", "some": "random"]
117-
XCTAssertEqual(try att.parsePoints("x"), [DOM.Point(20, 30), DOM.Point(40, 50)])
118-
XCTAssertNil(try att.parsePoints("missing"))
119-
XCTAssertThrowsError(try att.parsePoints("some"))
120-
XCTAssertThrowsError(try att.parsePoints("some") as [DOM.Point]?)
121-
}
122-
123-
func testParseLength() {
124-
let att = ["x": "20", "y": "aa"]
125-
XCTAssertEqual(try att.parseLength("x"), 20)
126-
XCTAssertNil(try att.parseLength("missing"))
127-
XCTAssertThrowsError(try att.parseLength("y"))
128-
XCTAssertThrowsError(try att.parseLength("y") as DOM.Length?)
129-
}
130-
131-
func testParseBool() {
132-
let att = ["x": "true", "y": "5"]
133-
XCTAssertEqual(try att.parseBool("x"), true)
134-
XCTAssertNil(try att.parseBool("missing"))
135-
XCTAssertThrowsError(try att.parseBool("y"))
136-
XCTAssertThrowsError(try att.parseBool("y") as Bool?)
137-
}
138-
139-
func testParseURL() {
140-
let att = ["clip": "http://www.test.com", "mask": "20 twenty"]
141-
XCTAssertEqual(try att.parseUrl("clip"), URL(string: "http://www.test.com"))
142-
XCTAssertNil(try att.parseUrl("missing"))
143-
XCTAssertThrowsError(try att.parseUrl(" "))
144-
}
145-
146-
func testParseURLSelector() {
147-
let att = ["clip": "url(#shape)", "mask": "aa"]
148-
XCTAssertEqual(try att.parseUrlSelector("clip"), URL(string: "#shape"))
149-
XCTAssertNil(try att.parseUrlSelector("missing"))
150-
XCTAssertThrowsError(try att.parseUrlSelector("mask"))
151-
}
152-
//
153-
// func parseString(_ key: String) throws -> String {
154-
// return try parse(key) { $0 }
155-
// }
156-
//
157-
// func parseFloat(_ key: String) throws -> DOM.Float {
158-
// return try parse(key) { return try parser.parseFloat($0) }
159-
// }
160-
//
161-
// func parseFloats(_ key: String) throws -> [DOM.Float] {
162-
163163
}
164164

0 commit comments

Comments
 (0)