Skip to content

A couple of minor improvements to SwiftSyntaxTestSupport #1578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2023
Merged
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
17 changes: 5 additions & 12 deletions Sources/SwiftSyntaxMacrosTestSupport/Assertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import SwiftSyntax
import SwiftSyntaxMacros
import XCTest

private extension String {
// This implementation is really slow; to use it outside a test it should be optimized.
func trimmingTrailingWhitespace() -> String {
return self.replacingOccurrences(of: "[ ]+\\n", with: "\n", options: .regularExpression)
}
}

// MARK: - Note

/// Describes a diagnostic note that tests expect to be created by a macro expansion.
Expand Down Expand Up @@ -210,8 +203,8 @@ func assertDiagnostic<T: SyntaxProtocol>(
}

assertStringsEqualWithDiff(
highlightedCode.trimmingTrailingWhitespace(),
highlight.trimmingTrailingWhitespace(),
highlightedCode,
highlight,
"highlight does not match",
file: spec.originatorFile,
line: spec.originatorLine
Expand Down Expand Up @@ -255,7 +248,7 @@ func assertDiagnostic<T: SyntaxProtocol>(
/// macros in various places (e.g., `#stringify(x + y)`).
/// - expandedSource: The source code that we expect to see after performing
/// macro expansion on the original source.
/// - diagnostics:
/// - diagnostics: The diagnostics when expanding any macro
/// - macros: The macros that should be expanded, provided as a dictionary
/// mapping macro names (e.g., `"stringify"`) to implementation types
/// (e.g., `StringifyMacro.self`).
Expand All @@ -282,8 +275,8 @@ public func assertMacroExpansion(
let expandedSourceFile = origSourceFile.expand(macros: macros, in: context).formatted(using: BasicFormat(indentationWidth: indentationWidth))

assertStringsEqualWithDiff(
expandedSourceFile.description.trimmingTrailingWhitespace(),
expandedSource.trimmingTrailingWhitespace(),
expandedSourceFile.description,
expandedSource,
file: file,
line: line
)
Expand Down