Skip to content

Commit 38e294b

Browse files
stephencelisgithub-actions[bot]
authored andcommitted
Run swift-format
1 parent f7e7abd commit 38e294b

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

Sources/URLRouting/Fragment.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ import Parsing
22

33
/// Parses a request's fragment subcomponent with a substring parser.
44
public struct Fragment<ValueParser: Parser>: Parser where ValueParser.Input == Substring {
5-
5+
66
@usableFromInline
77
let valueParser: ValueParser
8-
8+
99
/// Initializes a fragment parser that parses the fragment as a string in its entirety.
1010
@inlinable
1111
public init()
12-
where ValueParser == Parsers.MapConversion<Parsers.ReplaceError<Rest<Substring>>, Conversions.SubstringToString> {
12+
where
13+
ValueParser == Parsers.MapConversion<
14+
Parsers.ReplaceError<Rest<Substring>>, Conversions.SubstringToString
15+
>
16+
{
1317
self.valueParser = Rest().replaceError(with: "").map(.string)
1418
}
15-
19+
1620
/// Initializes a fragment parser.
1721
///
1822
/// - Parameter value: A parser that parses the fragment's substring value into something
@@ -21,7 +25,7 @@ public struct Fragment<ValueParser: Parser>: Parser where ValueParser.Input == S
2125
public init(@ParserBuilder value: () -> ValueParser) {
2226
self.valueParser = value()
2327
}
24-
28+
2529
/// Initializes a fragment parser.
2630
///
2731
/// - Parameter value: A conversion that transforms the fragment's substring value into
@@ -31,7 +35,7 @@ public struct Fragment<ValueParser: Parser>: Parser where ValueParser.Input == S
3135
where ValueParser == Parsers.MapConversion<Parsers.ReplaceError<Rest<Substring>>, C> {
3236
self.valueParser = Rest().replaceError(with: "").map(value)
3337
}
34-
38+
3539
@inlinable
3640
public func parse(_ input: inout URLRequestData) throws -> ValueParser.Output {
3741
guard var fragment = input.fragment?[...] else { throw RoutingError() }

Sources/URLRouting/URLRequestData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Foundation
77
public struct URLRequestData: Equatable, _EmptyInitializable {
88
/// The request body.
99
public var body: Data?
10-
10+
1111
/// The fragment subcomponent of the request URL.
1212
public var fragment: String?
1313

Tests/URLRoutingTests/URLRoutingTests.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ class URLRoutingTests: XCTestCase {
9797
URLRequestData(query: [:])
9898
)
9999
}
100-
100+
101101
func testFragment() throws {
102102
// test default initializer
103103
let q1 = Fragment()
104-
104+
105105
var request = try XCTUnwrap(URLRequestData(string: "#fragment"))
106106
XCTAssertEqual(
107107
"fragment",
@@ -111,14 +111,15 @@ class URLRoutingTests: XCTestCase {
111111
URLRequestData(fragment: "fragment"),
112112
try q1.print("fragment")
113113
)
114-
114+
115115
struct Timestamp: Equatable, RawRepresentable {
116116
let rawValue: String
117117
}
118-
118+
119119
// test conversion initializer
120120
let q2 = Fragment(.string.representing(Timestamp.self))
121-
request = try XCTUnwrap(URLRequestData(string: "https://www.pointfree.co/episodes/ep182-invertible-parsing-map#t802"))
121+
request = try XCTUnwrap(
122+
URLRequestData(string: "https://www.pointfree.co/episodes/ep182-invertible-parsing-map#t802"))
122123
XCTAssertEqual(
123124
Timestamp(rawValue: "t802"),
124125
try q2.parse(&request)
@@ -127,12 +128,12 @@ class URLRoutingTests: XCTestCase {
127128
URLRequestData(fragment: "t802"),
128129
try q2.print(Timestamp(rawValue: "t802"))
129130
)
130-
131+
131132
// test parser builder initializer
132133
let p3 = Fragment {
133134
"section1"
134135
}
135-
136+
136137
request = try XCTUnwrap(URLRequestData(string: "#section1"))
137138
XCTAssertNoThrow(try p3.parse(&request))
138139
request = try XCTUnwrap(URLRequestData(string: "#section2"))
@@ -141,17 +142,20 @@ class URLRoutingTests: XCTestCase {
141142
.init(fragment: "section1"),
142143
try p3.print()
143144
)
144-
145+
145146
enum AppRoute: Equatable {
146147
case privacyPolicy(section: String)
147148
}
148-
149+
149150
// routing example
150151
let r = Route(.case(AppRoute.privacyPolicy(section:))) {
151-
Path { "legal"; "privacy" }
152+
Path {
153+
"legal"
154+
"privacy"
155+
}
152156
Fragment()
153157
}
154-
158+
155159
request = try XCTUnwrap(URLRequestData(string: "/legal/privacy#faq"))
156160
XCTAssertEqual(
157161
.privacyPolicy(section: "faq"),

0 commit comments

Comments
 (0)