Skip to content

Commit 1ac498f

Browse files
committed
[MacroExamples] Update invalid URL example
Workaround for a Foundation bug that can return non-nil URL for "https://not a url.com".
1 parent 248dcef commit 1ac498f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Examples/Sources/MacroExamples/Playground/ExpressionMacrosPlayground.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func runExpressionMacrosPlayground() {
4747

4848
// let domain = "domain.com"
4949
//print(#URL("https://\(domain)/api/path")) // error: #URL requires a static string literal
50-
//print(#URL("https://not a url.com")) // error: Malformed url
50+
//print(#URL("https://not a url.com:invalid-port/")) // error: Malformed url
5151

5252
// MARK: - Warning
5353

Examples/Tests/MacroExamples/Implementation/Expression/URLMacroTests.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ final class URLMacroTests: XCTestCase {
2121
func testExpansionWithMalformedURLEmitsError() {
2222
assertMacroExpansion(
2323
"""
24-
let invalid = #URL("https://not a url.com")
24+
let invalid = #URL("https://not a url.com:invalid-port/")
2525
""",
2626
expandedSource: """
27-
let invalid = #URL("https://not a url.com")
27+
let invalid = #URL("https://not a url.com:invalid-port/")
2828
""",
2929
diagnostics: [
30-
DiagnosticSpec(message: #"malformed url: "https://not a url.com""#, line: 1, column: 15, severity: .error)
30+
DiagnosticSpec(
31+
message: #"malformed url: "https://not a url.com:invalid-port/""#,
32+
line: 1,
33+
column: 15,
34+
severity: .error
35+
)
3136
],
3237
macros: macros,
3338
indentationWidth: .spaces(2)

0 commit comments

Comments
 (0)