Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions Tests/FoundationMacrosTests/MacroTestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ struct DiagnosticTest : ExpressibleByStringLiteral, Hashable, CustomStringConver

var mappedToExpression: Self {
DiagnosticTest(
message._replacing("Predicate", with: "Expression")._replacing("predicate", with: "expression"),
message.replacing("Predicate", with: "Expression").replacing("predicate", with: "expression"),
fixIts: fixIts.map {
FixItTest($0.message, result: $0.result._replacing("#Predicate", with: "#Expression"))
FixItTest($0.message, result: $0.result.replacing("#Predicate", with: "#Expression"))
}
)
}
Expand Down Expand Up @@ -100,7 +100,7 @@ extension Diagnostic {
} else {
var result = "Message: \(debugDescription)\nFix-Its:\n"
for fixIt in fixIts {
result += "\t\(fixIt.message.message)\n\t\(fixIt.changes.first!._result._replacing("\n", with: "\n\t"))"
result += "\t\(fixIt.message.message)\n\t\(fixIt.changes.first!._result.replacing("\n", with: "\n\t"))"
}
return result
}
Expand All @@ -114,7 +114,7 @@ extension DiagnosticTest {
} else {
var result = "Message: \(message)\nFix-Its:\n"
for fixIt in fixIts {
result += "\t\(fixIt.message)\n\t\(fixIt.result._replacing("\n", with: "\n\t"))"
result += "\t\(fixIt.message)\n\t\(fixIt.result.replacing("\n", with: "\n\t"))"
}
return result
}
Expand Down Expand Up @@ -164,21 +164,9 @@ func AssertPredicateExpansion(_ source: String, _ result: String = "", diagnosti
)
AssertMacroExpansion(
macros: ["Expression" : FoundationMacros.ExpressionMacro.self],
source._replacing("#Predicate", with: "#Expression"),
result._replacing(".Predicate", with: ".Expression"),
source.replacing("#Predicate", with: "#Expression"),
result.replacing(".Predicate", with: ".Expression"),
diagnostics: Set(diagnostics.map(\.mappedToExpression)),
sourceLocation: sourceLocation
)
}

extension String {
func _replacing(_ text: String, with other: String) -> Self {
if #available(macOS 13.0, *) {
// Use the stdlib API if available
self.replacing(text, with: other)
} else {
// Use the Foundation API on older OSes
self.replacingOccurrences(of: text, with: other, options: [.literal])
}
}
}
2 changes: 0 additions & 2 deletions Tests/FoundationMacrosTests/PredicateMacroUsageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import Foundation
fileprivate func _blackHole<T>(_ t: T) {}

@inline(never)
@available(macOS 14, iOS 17, watchOS 10, tvOS 17, *)
fileprivate func _blackHoleExplicitInput(_ predicate: Predicate<Int>) {}

// MARK: - Tests

@Suite("#Predicate Macro Usage")
private struct PredicateMacroUsageTests {
@available(macOS 14, iOS 17, watchOS 10, tvOS 17, *)
@Test func usage() {
_blackHole(#Predicate<Bool> {
return $0
Expand Down