Skip to content

Audit GenericDisambiguationTests.swift and ForeachTests.swift #965

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 2 commits into from
Oct 17, 2022
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
6 changes: 0 additions & 6 deletions Tests/SwiftParserTest/translated/ForeachAsyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ final class ForeachAsyncTests: XCTestCase {
}
""",
diagnostics: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW you can remove the FIXME above as well

// TODO: Old parser expected error on line 21: found an unexpected second identifier in constant declaration
// TODO: Old parser expected note on line 21: join the identifiers together
// TODO: Old parser expected note on line 21: join the identifiers together with camel-case
// TODO: Old parser expected error on line 21: expected 'in' after for-each pattern
// TODO: Old parser expected error on line 21: expected Sequence expression for for-each loop
DiagnosticSpec(locationMarker: "1️⃣", message: "expected 'in' in 'for' statement"),
// TODO: Old parser expected error on line 23: expected '{' to start the body of for-each loop
DiagnosticSpec(locationMarker: "2️⃣", message: "expected '{' in 'for' statement"),
DiagnosticSpec(locationMarker: "3️⃣", message: "expected '}' to end 'for' statement"),
]
Expand Down
6 changes: 0 additions & 6 deletions Tests/SwiftParserTest/translated/ForeachTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ final class ForeachTests: XCTestCase {
}
""",
diagnostics: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

// TODO: Old parser expected error on line 21: found an unexpected second identifier in constant declaration
// TODO: Old parser expected note on line 21: join the identifiers together
// TODO: Old parser expected note on line 21: join the identifiers together with camel-case
// TODO: Old parser expected error on line 21: expected 'in' after for-each pattern
// TODO: Old parser expected error on line 21: expected Sequence expression for for-each loop
DiagnosticSpec(locationMarker: "1️⃣", message: "expected 'in' in 'for' statement"),
// TODO: Old parser expected error on line 23: expected '{' to start the body of for-each loop
DiagnosticSpec(locationMarker: "2️⃣", message: "expected '{' in 'for' statement"),
DiagnosticSpec(locationMarker: "3️⃣", message: "expected '}' to end 'for' statement"),
]
Expand Down
93 changes: 76 additions & 17 deletions Tests/SwiftParserTest/translated/GenericDisambiguationTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// This test file has been translated from swift/test/Parse/generic_disambiguation.swift

import SwiftSyntax

import XCTest

final class GenericDisambiguationTests: XCTestCase {
Expand Down Expand Up @@ -54,36 +56,93 @@ final class GenericDisambiguationTests: XCTestCase {
)
}

func testGenericDisambiguation6() {
func testGenericDisambiguation6a() {
AssertParse(
"""
_ = a < b
"""
)
}

func testGenericDisambiguation6b() {
AssertParse(
"""
_ = (a < b, c > d)
// Parses as generic because of lparen after '>'
(a < b, c > (d))
// Parses as generic because of lparen after '>'
(a<b, c>(d))
"""
)
}

func testGenericDisambiguation6c() {
// Parses as generic because of lparen after '>'
AssertParse(
"""
(a < b, c > (d))
""",
substructure: Syntax(GenericArgumentListSyntax([
GenericArgumentSyntax(
argumentType: TypeSyntax(SimpleTypeIdentifierSyntax(
name: .identifier("b"),
genericArgumentClause: nil
)),
trailingComma: .commaToken()
),
GenericArgumentSyntax(
argumentType: TypeSyntax(SimpleTypeIdentifierSyntax(
name: .identifier("c"),
genericArgumentClause: nil
)),
trailingComma: nil
)
]))
)
}

func testGenericDisambiguation6d() {
// Parses as generic because of lparen after '>'
AssertParse(
"""
(a<b, c>(d))
""",
substructure: Syntax(GenericArgumentListSyntax([
GenericArgumentSyntax(
argumentType: TypeSyntax(SimpleTypeIdentifierSyntax(
name: .identifier("b"),
genericArgumentClause: nil
)),
trailingComma: .commaToken()
),
GenericArgumentSyntax(
argumentType: TypeSyntax(SimpleTypeIdentifierSyntax(
name: .identifier("c"),
genericArgumentClause: nil
)),
trailingComma: nil
)
]))
)
}

func testGenericDisambiguation6e() {
AssertParse(
"""
_ = a>(b)
"""
)
}

func testGenericDisambiguation6f() {
AssertParse(
"""
_ = a > (b)
""",
diagnostics: [
// TODO: Old parser expected error on line 4: cannot specialize a non-generic definition
// TODO: Old parser expected note on line 4: while parsing this '<' as a type parameter bracket
// TODO: Old parser expected error on line 6: cannot specialize a non-generic definition
// TODO: Old parser expected note on line 6: while parsing this '<' as a type parameter bracket
]
"""
)
}

func testGenericDisambiguation7() {
AssertParse(
"""
generic<Int>(0)
""",
diagnostics: [
// TODO: Old parser expected error on line 1: cannot explicitly specialize a generic function
// TODO: Old parser expected note on line 1: while parsing this '<' as a type parameter bracket
]
"""
)
}

Expand Down