Add support for Swift 5.1’s opaque return types (#71)

This change adds support for the Swift 5.1 `some` keyword, which is used
to declare opaque return types.
This commit is contained in:
John Sundell 2019-06-09 12:33:00 +02:00 committed by GitHub
parent 6fcb458c63
commit d978081933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -52,7 +52,7 @@ private extension SwiftGrammar {
"lazy", "subscript", "defer", "inout", "while",
"continue", "fallthrough", "repeat", "indirect",
"deinit", "is", "#file", "#line", "#function",
"dynamic"
"dynamic", "some"
] as Set<String>).union(accessControlKeywords)
static let accessControlKeywords: Set<String> = [

View File

@ -858,6 +858,31 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}
func testFunctionDeclarationWithOpaqueReturnType() {
let components = highlighter.highlight(#"func make() -> some View { Text("!") }"#)
XCTAssertEqual(components, [
.token("func", .keyword),
.whitespace(" "),
.plainText("make()"),
.whitespace(" "),
.plainText("->"),
.whitespace(" "),
.token("some", .keyword),
.whitespace(" "),
.token("View", .type),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.token("Text", .type),
.plainText("("),
.token(#""!""#, .string),
.plainText(")"),
.whitespace(" "),
.plainText("}")
])
}
func testIndirectEnumDeclaration() {
let components = highlighter.highlight("""
indirect enum Content {
@ -934,6 +959,7 @@ extension DeclarationTests {
("testFunctionDeclarationWithPreProcessors", testFunctionDeclarationWithPreProcessors),
("testNonMutatingFunction", testNonMutatingFunction),
("testRethrowingFunctionDeclaration", testRethrowingFunctionDeclaration),
("testFunctionDeclarationWithOpaqueReturnType", testFunctionDeclarationWithOpaqueReturnType),
("testIndirectEnumDeclaration", testIndirectEnumDeclaration)
]
}