Adding support for rethrows keyword (#56)

This commit is contained in:
Marco Capano 2019-03-12 23:12:54 +01:00 committed by John Sundell
parent 9485a4e762
commit 60c06cc385
2 changed files with 37 additions and 2 deletions

View File

@ -41,7 +41,7 @@ private extension SwiftGrammar {
"final", "class", "struct", "enum", "protocol",
"extension", "let", "var", "func", "typealias",
"init", "guard", "if", "else", "return", "get",
"throw", "throws", "for", "in", "open", "weak",
"throw", "throws", "rethrows", "for", "in", "open", "weak",
"import", "mutating", "nonmutating", "associatedtype",
"case", "switch", "static", "do", "try", "catch", "as",
"super", "self", "set", "true", "false", "nil",

View File

@ -635,7 +635,7 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
.token("inout", .keyword),
.whitespace(" "),
.token("Int", .type),
.plainText(")"),
.plainText(")"),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
@ -750,6 +750,40 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}
func testRethrowingFunctionDeclaration() {
let components = highlighter.highlight("""
func map<T>(_ transform: (Element) throws -> T) rethrows -> [T]
""")
XCTAssertEqual(components, [
.token("func", .keyword),
.whitespace(" "),
.plainText("map<T>("),
.token("_", .keyword),
.whitespace(" "),
.plainText("transform:"),
.whitespace(" "),
.plainText("("),
.token("Element", .type),
.plainText(")"),
.whitespace(" "),
.token("throws", .keyword),
.whitespace(" "),
.plainText("->"),
.whitespace(" "),
.token("T", .type),
.plainText(")"),
.whitespace(" "),
.token("rethrows", .keyword),
.whitespace(" "),
.plainText("->"),
.whitespace(" "),
.plainText("["),
.token("T", .type),
.plainText("]")
])
}
func testIndirectEnumDeclaration() {
let components = highlighter.highlight("""
indirect enum Content {
@ -822,6 +856,7 @@ extension DeclarationTests {
("testFunctionDeclarationWithEscapedKeywordAsName", testFunctionDeclarationWithEscapedKeywordAsName),
("testFunctionDeclarationWithPreProcessors", testFunctionDeclarationWithPreProcessors),
("testNonMutatingFunction", testNonMutatingFunction),
("testRethrowingFunctionDeclaration", testRethrowingFunctionDeclaration),
("testIndirectEnumDeclaration", testIndirectEnumDeclaration)
]
}