Skip to content

Lowercase all Assert methods #1438

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
Mar 24, 2023
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
8 changes: 4 additions & 4 deletions Sources/SwiftParser/SwiftParser.docc/FixingBugs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Once you’ve written a test case (see below), set a breakpoint in `Parser.parse

1. Add a new test case in `SwiftParserTest` that looks like the following
```swift
AssertParse(
assertParse(
"""
<#your code that does not round trip#>
"""
Expand All @@ -27,7 +27,7 @@ Diagnostics are produced when the parsed syntax tree contains missing or unexpec

1. Add a test case in `SwiftParserTest` that looks like the following
```swift
AssertParse(
assertParse(
"""
<#your code that produces an invalid syntax tree#>
""",
Expand All @@ -54,7 +54,7 @@ To add a new, more contextual diagnostic, perform the following steps.
1. Add a test case in `SwiftParserTest` that looks like the following

```swift
AssertParse(
assertParse(
"""
<#your code that produced the unhelpful diagnostic#>
""",
Expand All @@ -69,7 +69,7 @@ To add a new, more contextual diagnostic, perform the following steps.
5. If the function does not already exist, write a new visit method on <doc:SwiftParser/ParseDiagnosticsGenerator>.
6. In that visitation method, detect the pattern for which the improved diagnostic should be emitted and emit it using `diagnostics.append`.
7. Mark the missing or garbage nodes that are covered by the new diagnostic as handled by adding their `SyntaxIdentifier`s to `handledNodes`.
8. If the diagnostic produces Fix-Its assert that they are generated by adding the Fix-It's message to the `DiagnosticSpec` with the `fixIt` parameter and asserting that applying the Fix-Its produces the correct source code by adding the `fixedSource` parameter to `AssertParse`.
8. If the diagnostic produces Fix-Its assert that they are generated by adding the Fix-It's message to the `DiagnosticSpec` with the `fixIt` parameter and asserting that applying the Fix-Its produces the correct source code by adding the `fixedSource` parameter to `assertParse`.

> 💡 Tip: To make typing the marker emojis more convienient. you can set up code snippets in Xcode. To do this, perform the following steps:
> 1. Type the marker in any Xcode window or find it in some test case
Expand Down
10 changes: 5 additions & 5 deletions Sources/_SwiftSyntaxTestSupport/AssertEqualWithDiff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import XCTest
/// which this function was called.
/// - line: The line number on which failure occurred. Defaults to the line number on which this
/// function was called.
public func AssertStringsEqualWithDiff(
public func assertStringsEqualWithDiff(
_ actual: String,
_ expected: String,
_ message: String = "",
Expand All @@ -34,7 +34,7 @@ public func AssertStringsEqualWithDiff(
if actual == expected {
return
}
FailStringsEqualWithDiff(
failStringsEqualWithDiff(
actual,
expected,
message,
Expand All @@ -55,7 +55,7 @@ public func AssertStringsEqualWithDiff(
/// which this function was called.
/// - line: The line number on which failure occurred. Defaults to the line number on which this
/// function was called.
public func AssertDataEqualWithDiff(
public func assertDataEqualWithDiff(
_ actual: Data,
_ expected: Data,
_ message: String = "",
Expand All @@ -69,7 +69,7 @@ public func AssertDataEqualWithDiff(

// NOTE: Converting to `Stirng` here looses invalid UTF8 sequence difference,
// but at least we can see something is different.
FailStringsEqualWithDiff(
failStringsEqualWithDiff(
String(decoding: actual, as: UTF8.self),
String(decoding: expected, as: UTF8.self),
message,
Expand All @@ -80,7 +80,7 @@ public func AssertDataEqualWithDiff(
}

/// `XCTFail` with `diff`-style output.
public func FailStringsEqualWithDiff(
public func failStringsEqualWithDiff(
_ actual: String,
_ expected: String,
_ message: String = "",
Expand Down
14 changes: 7 additions & 7 deletions Tests/SwiftDiagnosticsTest/DiagnosticsFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class DiagnosticsFormatterTests: XCTestCase {
│ ╰─ error: expected expression after operator

"""
AssertStringsEqualWithDiff(annotate(source: source), expectedOutput)
assertStringsEqualWithDiff(annotate(source: source), expectedOutput)
}

func testMultipleDiagnosticsInOneLine() {
Expand All @@ -47,7 +47,7 @@ final class DiagnosticsFormatterTests: XCTestCase {
│ ╰─ error: expected name in member access

"""
AssertStringsEqualWithDiff(annotate(source: source), expectedOutput)
assertStringsEqualWithDiff(annotate(source: source), expectedOutput)
}

func testLineSkipping() {
Expand Down Expand Up @@ -78,7 +78,7 @@ final class DiagnosticsFormatterTests: XCTestCase {
│ ╰─ error: expected value and ')' to end function call

"""
AssertStringsEqualWithDiff(annotate(source: source), expectedOutput)
assertStringsEqualWithDiff(annotate(source: source), expectedOutput)
}

func testTwoDiagnosticsAtSameLocation() throws {
Expand All @@ -91,7 +91,7 @@ final class DiagnosticsFormatterTests: XCTestCase {

"""

AssertStringsEqualWithDiff(annotate(source: source), expectedOutput)
assertStringsEqualWithDiff(annotate(source: source), expectedOutput)
}

func testAddsColoringToSingleErrorDiagnostic() {
Expand All @@ -104,7 +104,7 @@ final class DiagnosticsFormatterTests: XCTestCase {
\u{001B}[0;36m│\u{001B}[0;0m ╰─ \u{001B}[1;31merror: expected expression after operator\u{001B}[0;0m

"""
AssertStringsEqualWithDiff(annotate(source: source, colorize: true), expectedOutput)
assertStringsEqualWithDiff(annotate(source: source, colorize: true), expectedOutput)
}

func testAddsColoringToMultipleDiagnosticsInOneLine() {
Expand All @@ -118,7 +118,7 @@ final class DiagnosticsFormatterTests: XCTestCase {
\u{001B}[0;36m│\u{001B}[0;0m ╰─ \u{001B}[1;31merror: expected name in member access\u{001B}[0;0m

"""
AssertStringsEqualWithDiff(annotate(source: source, colorize: true), expectedOutput)
assertStringsEqualWithDiff(annotate(source: source, colorize: true), expectedOutput)
}

func testColoringWithHighlights() {
Expand All @@ -133,6 +133,6 @@ final class DiagnosticsFormatterTests: XCTestCase {

"""

AssertStringsEqualWithDiff(annotate(source: source, colorize: true), expectedOutput)
assertStringsEqualWithDiff(annotate(source: source, colorize: true), expectedOutput)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
)

let annotated = DiagnosticsFormatter.annotateSources(in: group)
AssertStringsEqualWithDiff(
assertStringsEqualWithDiff(
annotated,
"""
=== main.swift:5 ===
Expand Down Expand Up @@ -178,7 +178,7 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
)

let annotated = DiagnosticsFormatter.annotateSources(in: group)
AssertStringsEqualWithDiff(
assertStringsEqualWithDiff(
annotated,
"""
=== main.swift:2 ===
Expand Down
52 changes: 26 additions & 26 deletions Tests/SwiftParserTest/Assertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct LexemeSpec {
/// which this function was called.
/// - line: The line number on which failure occurred. Defaults to the line number on which this
/// function was called.
private func AssertTokens(
private func assertTokens(
_ actual: [Lexer.Lexeme],
_ expected: [LexemeSpec],
markerLocations: [String: Int],
Expand Down Expand Up @@ -98,7 +98,7 @@ private func AssertTokens(
}

if actualLexeme.leadingTriviaText != expectedLexeme.leadingTrivia {
FailStringsEqualWithDiff(
failStringsEqualWithDiff(
String(syntaxText: actualLexeme.leadingTriviaText),
String(syntaxText: expectedLexeme.leadingTrivia),
"Leading trivia does not match",
Expand All @@ -108,7 +108,7 @@ private func AssertTokens(
}

if actualLexeme.tokenText.debugDescription != expectedLexeme.tokenText.debugDescription {
FailStringsEqualWithDiff(
failStringsEqualWithDiff(
actualLexeme.tokenText.debugDescription,
expectedLexeme.tokenText.debugDescription,
"Token text does not match",
Expand All @@ -118,7 +118,7 @@ private func AssertTokens(
}

if actualLexeme.trailingTriviaText != expectedLexeme.trailingTrivia {
FailStringsEqualWithDiff(
failStringsEqualWithDiff(
String(syntaxText: actualLexeme.trailingTriviaText),
String(syntaxText: expectedLexeme.trailingTrivia),
"Trailing trivia does not match",
Expand All @@ -142,7 +142,7 @@ private func AssertTokens(
line: expectedLexeme.line
)
case (let actualError?, let expectedError?):
AssertStringsEqualWithDiff(
assertStringsEqualWithDiff(
actualError.diagnosticMessage(wholeTextBytes: Array(actualLexeme.wholeText)).message,
expectedError,
file: expectedLexeme.file,
Expand Down Expand Up @@ -175,7 +175,7 @@ private func AssertTokens(
}
}

func AssertLexemes(
func assertLexemes(
_ markedSource: String,
lexemes expectedLexemes: [LexemeSpec],
file: StaticString = #file,
Expand All @@ -196,7 +196,7 @@ func AssertLexemes(
break
}
}
AssertTokens(lexemes, expectedLexemes, markerLocations: markerLocations, file: file, line: line)
assertTokens(lexemes, expectedLexemes, markerLocations: markerLocations, file: file, line: line)
}
}

Expand Down Expand Up @@ -324,7 +324,7 @@ class FixItApplier: SyntaxRewriter {
}

/// Assert that `location` is the same as that of `locationMarker` in `tree`.
func AssertLocation<T: SyntaxProtocol>(
func assertLocation<T: SyntaxProtocol>(
_ location: SourceLocation,
in tree: T,
markerLocations: [String: Int],
Expand Down Expand Up @@ -354,7 +354,7 @@ func AssertLocation<T: SyntaxProtocol>(

/// Assert that the diagnostic `note` produced in `tree` matches `spec`,
/// using `markerLocations` to translate markers to actual source locations.
func AssertNote<T: SyntaxProtocol>(
func assertNote<T: SyntaxProtocol>(
_ note: Note,
in tree: T,
markerLocations: [String: Int],
Expand All @@ -364,7 +364,7 @@ func AssertNote<T: SyntaxProtocol>(
) {
XCTAssertEqual(note.message, spec.message, file: file, line: line)
let locationConverter = SourceLocationConverter(file: "", source: tree.description)
AssertLocation(
assertLocation(
note.location(converter: locationConverter),
in: tree,
markerLocations: markerLocations,
Expand All @@ -376,7 +376,7 @@ func AssertNote<T: SyntaxProtocol>(

/// Assert that the diagnostic `diag` produced in `tree` matches `spec`,
/// using `markerLocations` to translate markers to actual source locations.
func AssertDiagnostic<T: SyntaxProtocol>(
func assertDiagnostic<T: SyntaxProtocol>(
_ diag: Diagnostic,
in tree: T,
markerLocations: [String: Int],
Expand All @@ -385,7 +385,7 @@ func AssertDiagnostic<T: SyntaxProtocol>(
line: UInt = #line
) {
let locationConverter = SourceLocationConverter(file: "", source: tree.description)
AssertLocation(
assertLocation(
diag.location(converter: locationConverter),
in: tree,
markerLocations: markerLocations,
Expand All @@ -397,7 +397,7 @@ func AssertDiagnostic<T: SyntaxProtocol>(
XCTAssertEqual(diag.diagnosticID, id, file: file, line: line)
}
if let message = spec.message {
AssertStringsEqualWithDiff(diag.message, message, file: file, line: line)
assertStringsEqualWithDiff(diag.message, message, file: file, line: line)
}
XCTAssertEqual(spec.severity, diag.diagMessage.severity, file: file, line: line)
if diag.message.contains("\n") {
Expand All @@ -411,7 +411,7 @@ func AssertDiagnostic<T: SyntaxProtocol>(
)
}
if let highlight = spec.highlight {
AssertStringsEqualWithDiff(
assertStringsEqualWithDiff(
diag.highlights.map(\.description).joined().trimmingTrailingWhitespace(),
highlight.trimmingTrailingWhitespace(),
file: file,
Expand All @@ -430,13 +430,13 @@ func AssertDiagnostic<T: SyntaxProtocol>(
)
} else {
for (note, expectedNote) in zip(diag.notes, notes) {
AssertNote(note, in: tree, markerLocations: markerLocations, expected: expectedNote, file: expectedNote.file, line: expectedNote.line)
assertNote(note, in: tree, markerLocations: markerLocations, expected: expectedNote, file: expectedNote.file, line: expectedNote.line)
}
}
}
if let fixIts = spec.fixIts {
if fixIts != diag.fixIts.map(\.message.message) {
FailStringsEqualWithDiff(
failStringsEqualWithDiff(
diag.fixIts.map(\.message.message).joined(separator: "\n"),
fixIts.joined(separator: "\n"),
file: file,
Expand All @@ -462,9 +462,9 @@ public struct AssertParseOptions: OptionSet {
public static let normalizeNewlinesInFixedSource = AssertParseOptions(rawValue: 1 << 1)
}

/// Same as `AssertParse` overload with a `(String) -> S` `parse`,
/// Same as `assertParse` overload with a `(String) -> S` `parse`,
/// parsing the resulting `String` as a `SourceFileSyntax`.
func AssertParse(
func assertParse(
_ markedSource: String,
substructure expectedSubstructure: Syntax? = nil,
substructureAfterMarker: String = "START",
Expand All @@ -475,7 +475,7 @@ func AssertParse(
file: StaticString = #file,
line: UInt = #line
) {
AssertParse(
assertParse(
markedSource,
{ SourceFileSyntax.parse(from: &$0) },
substructure: expectedSubstructure,
Expand All @@ -489,10 +489,10 @@ func AssertParse(
)
}

/// Same as `AssertParse` overload with a `(String) -> S` `parse`,
/// Same as `assertParse` overload with a `(String) -> S` `parse`,
/// constructing a `Parser` from the given `String` and passing that to
/// `parse` instead.
func AssertParse<S: SyntaxProtocol>(
func assertParse<S: SyntaxProtocol>(
_ markedSource: String,
_ parse: (inout Parser) -> S,
substructure expectedSubstructure: Syntax? = nil,
Expand All @@ -504,7 +504,7 @@ func AssertParse<S: SyntaxProtocol>(
file: StaticString = #file,
line: UInt = #line
) {
AssertParse(
assertParse(
markedSource,
{ (source: String) -> S in
var parser = Parser(source)
Expand Down Expand Up @@ -539,7 +539,7 @@ func AssertParse<S: SyntaxProtocol>(
/// - applyFixIts: Applies only the fix-its with these messages.
/// - fixedSource: Asserts that the source after applying fix-its matches
/// this string.
func AssertParse<S: SyntaxProtocol>(
func assertParse<S: SyntaxProtocol>(
_ markedSource: String,
_ parse: (String) -> S,
substructure expectedSubstructure: Syntax? = nil,
Expand All @@ -558,7 +558,7 @@ func AssertParse<S: SyntaxProtocol>(
let tree: S = parse(source)

// Round-trip
AssertStringsEqualWithDiff(
assertStringsEqualWithDiff(
"\(tree)",
source,
additionalInfo: """
Expand Down Expand Up @@ -594,7 +594,7 @@ func AssertParse<S: SyntaxProtocol>(
)
} else {
for (diag, expectedDiag) in zip(diags, expectedDiagnostics) {
AssertDiagnostic(diag, in: tree, markerLocations: markerLocations, expected: expectedDiag, file: expectedDiag.file, line: expectedDiag.line)
assertDiagnostic(diag, in: tree, markerLocations: markerLocations, expected: expectedDiag, file: expectedDiag.file, line: expectedDiag.line)
}
}

Expand All @@ -608,7 +608,7 @@ func AssertParse<S: SyntaxProtocol>(
.replacingOccurrences(of: "\r\n", with: "\n")
.replacingOccurrences(of: "\r", with: "\n")
}
AssertStringsEqualWithDiff(
assertStringsEqualWithDiff(
fixedTreeDescription.trimmingTrailingWhitespace(),
expectedFixedSource.trimmingTrailingWhitespace(),
file: file,
Expand Down
Loading