Merge pull request #16 from marcocapano/patch-1
Add support for new keywords
This commit is contained in:
commit
88961141d4
@ -47,7 +47,8 @@ private extension SwiftGrammar {
|
|||||||
"super", "self", "set", "true", "false", "nil",
|
"super", "self", "set", "true", "false", "nil",
|
||||||
"override", "where", "_", "default", "break",
|
"override", "where", "_", "default", "break",
|
||||||
"#selector", "required", "willSet", "didSet",
|
"#selector", "required", "willSet", "didSet",
|
||||||
"lazy", "subscript", "defer", "inout"
|
"lazy", "subscript", "defer", "inout", "while",
|
||||||
|
"continue", "fallthrough", "repeat"
|
||||||
]
|
]
|
||||||
|
|
||||||
struct PreprocessingRule: SyntaxRule {
|
struct PreprocessingRule: SyntaxRule {
|
||||||
|
@ -135,6 +135,40 @@ final class StatementTests: SyntaxHighlighterTestCase {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testSwitchStatementWithFallthrough() {
|
||||||
|
let components = highlighter.highlight("""
|
||||||
|
switch variable {
|
||||||
|
case .one: fallthrough
|
||||||
|
default:
|
||||||
|
callB()
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
|
||||||
|
XCTAssertEqual(components, [
|
||||||
|
.token("switch", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("variable"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("{"),
|
||||||
|
.whitespace("\n"),
|
||||||
|
.token("case", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("."),
|
||||||
|
.token("one", .dotAccess),
|
||||||
|
.plainText(":"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("fallthrough", .keyword),
|
||||||
|
.whitespace("\n"),
|
||||||
|
.token("default", .keyword),
|
||||||
|
.plainText(":"),
|
||||||
|
.whitespace("\n "),
|
||||||
|
.token("callB", .call),
|
||||||
|
.plainText("()"),
|
||||||
|
.whitespace("\n"),
|
||||||
|
.plainText("}")
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
func testForStatementWithStaticProperty() {
|
func testForStatementWithStaticProperty() {
|
||||||
let components = highlighter.highlight("for value in Enum.allCases { }")
|
let components = highlighter.highlight("for value in Enum.allCases { }")
|
||||||
|
|
||||||
@ -155,6 +189,76 @@ final class StatementTests: SyntaxHighlighterTestCase {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testForStatementWithContinue() {
|
||||||
|
let components = highlighter.highlight("for value in Enum.allCases { continue }")
|
||||||
|
|
||||||
|
XCTAssertEqual(components, [
|
||||||
|
.token("for", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("value"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("in", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("Enum", .type),
|
||||||
|
.plainText("."),
|
||||||
|
.token("allCases", .property),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("{"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("continue",.keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("}")
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
func testRepeatWhileStatement() {
|
||||||
|
let components = highlighter.highlight("""
|
||||||
|
var x = 5
|
||||||
|
repeat {
|
||||||
|
print(x)
|
||||||
|
x = x - 1
|
||||||
|
} while x > 1
|
||||||
|
""")
|
||||||
|
|
||||||
|
XCTAssertEqual(components, [
|
||||||
|
.token("var", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("x"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("="),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("5", .number),
|
||||||
|
.whitespace("\n"),
|
||||||
|
.token("repeat", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("{"),
|
||||||
|
.whitespace("\n "),
|
||||||
|
.token("print", .call),
|
||||||
|
.plainText("(x)"),
|
||||||
|
.whitespace("\n "),
|
||||||
|
.plainText("x"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("="),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("x"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("-"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("1", .number),
|
||||||
|
.whitespace("\n"),
|
||||||
|
.plainText("}"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("while", .keyword),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText("x"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.plainText(">"),
|
||||||
|
.whitespace(" "),
|
||||||
|
.token("1", .number)
|
||||||
|
])
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func testAllTestsRunOnLinux() {
|
func testAllTestsRunOnLinux() {
|
||||||
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
|
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
|
||||||
}
|
}
|
||||||
@ -168,7 +272,10 @@ extension StatementTests {
|
|||||||
("testChainedIfElseStatements", testChainedIfElseStatements),
|
("testChainedIfElseStatements", testChainedIfElseStatements),
|
||||||
("testSwitchStatement", testSwitchStatement),
|
("testSwitchStatement", testSwitchStatement),
|
||||||
("testSwitchStatementWithAssociatedValues", testSwitchStatementWithAssociatedValues),
|
("testSwitchStatementWithAssociatedValues", testSwitchStatementWithAssociatedValues),
|
||||||
("testForStatementWithStaticProperty", testForStatementWithStaticProperty)
|
("testSwitchStatementWithFallthrough", testSwitchStatementWithFallthrough),
|
||||||
|
("testForStatementWithStaticProperty", testForStatementWithStaticProperty),
|
||||||
|
("testForStatementWithContinue", testForStatementWithContinue),
|
||||||
|
("testRepeatWhileStatement", testRepeatWhileStatement)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user