Adding nonmutating support (#50)

This commit is contained in:
Marco Capano 2019-03-11 21:31:32 +01:00 committed by John Sundell
parent 1a77051c67
commit 9a7fdefab4
2 changed files with 31 additions and 2 deletions

View File

@ -41,8 +41,8 @@ private extension SwiftGrammar {
"extension", "let", "var", "func", "typealias",
"init", "guard", "if", "else", "return", "get",
"throw", "throws", "for", "in", "open", "weak",
"import", "mutating", "associatedtype", "case",
"switch", "static", "do", "try", "catch", "as",
"import", "mutating", "nonmutating", "associatedtype",
"case", "switch", "static", "do", "try", "catch", "as",
"super", "self", "set", "true", "false", "nil",
"override", "where", "_", "default", "break",
"#selector", "required", "willSet", "didSet",

View File

@ -722,6 +722,34 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
])
}
func testNonMutatingFunction() {
let components = highlighter.highlight("""
struct MyStruct {
nonmutating func doNotChangeState() { }
}
""")
XCTAssertEqual(components, [
.token("struct", .keyword),
.whitespace(" "),
.plainText("MyStruct"),
.whitespace(" "),
.plainText("{"),
.whitespace("\n "),
.token("nonmutating", .keyword),
.whitespace(" "),
.token("func", .keyword),
.whitespace(" "),
.plainText("doNotChangeState()"),
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.plainText("}"),
.whitespace("\n"),
.plainText("}")
])
}
func testIndirectEnumDeclaration() {
let components = highlighter.highlight("""
indirect enum Content {
@ -793,6 +821,7 @@ extension DeclarationTests {
("testFunctionDeclarationWithNonEscapedKeywordAsName", testFunctionDeclarationWithNonEscapedKeywordAsName),
("testFunctionDeclarationWithEscapedKeywordAsName", testFunctionDeclarationWithEscapedKeywordAsName),
("testFunctionDeclarationWithPreProcessors", testFunctionDeclarationWithPreProcessors),
("testNonMutatingFunction", testNonMutatingFunction),
("testIndirectEnumDeclaration", testIndirectEnumDeclaration)
]
}