Fix highlighting for inout closure arguments (#68)
This patch makes Splash correctly highlight the `inout` keyword when it appears as part of a closure argument definition.
This commit is contained in:
parent
30d6cacb7c
commit
4675ffe963
@ -272,7 +272,7 @@ private extension SwiftGrammar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't highlight most keywords when used as a parameter label
|
// Don't highlight most keywords when used as a parameter label
|
||||||
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false") {
|
if !segment.tokens.current.isAny(of: "_", "self", "let", "var", "true", "false", "inout") {
|
||||||
guard !previousToken.isAny(of: "(", ",", ">(") else {
|
guard !previousToken.isAny(of: "(", ",", ">(") else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,27 @@ final class ClosureTests: SyntaxHighlighterTestCase {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testClosureWithInoutArgument() {
|
||||||
|
let components = highlighter.highlight("func add(closure: (inout Value) -> Void)")
|
||||||
|
|
||||||
|
XCTAssertEqual(components, [
|
||||||
|
.token("func", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("add(closure:"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("("),
|
||||||
|
.token("inout", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("Value", .type),
|
||||||
|
.plainText(")"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("->"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("Void", .type),
|
||||||
|
.plainText(")")
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
func testPassingClosureAsArgument() {
|
func testPassingClosureAsArgument() {
|
||||||
let components = highlighter.highlight("object.call({ $0 })")
|
let components = highlighter.highlight("object.call({ $0 })")
|
||||||
|
|
||||||
@ -194,6 +215,7 @@ extension ClosureTests {
|
|||||||
("testClosureArgumentWithSingleArgument", testClosureArgumentWithSingleArgument),
|
("testClosureArgumentWithSingleArgument", testClosureArgumentWithSingleArgument),
|
||||||
("testClosureArgumentWithMultipleArguments", testClosureArgumentWithMultipleArguments),
|
("testClosureArgumentWithMultipleArguments", testClosureArgumentWithMultipleArguments),
|
||||||
("testEscapingClosureArgument", testEscapingClosureArgument),
|
("testEscapingClosureArgument", testEscapingClosureArgument),
|
||||||
|
("testClosureWithInoutArgument", testClosureWithInoutArgument),
|
||||||
("testPassingClosureAsArgument", testPassingClosureAsArgument),
|
("testPassingClosureAsArgument", testPassingClosureAsArgument),
|
||||||
("testNestedEscapingClosure", testNestedEscapingClosure),
|
("testNestedEscapingClosure", testNestedEscapingClosure),
|
||||||
("testClosureArgumentShorthands", testClosureArgumentShorthands)
|
("testClosureArgumentShorthands", testClosureArgumentShorthands)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user