a86694802e
This patch fixes highlighting when an enum is used as a dictionary key, like this: ``` let value = dictionary[.key] ```
76 lines
2.1 KiB
Swift
76 lines
2.1 KiB
Swift
/**
|
|
* Splash
|
|
* Copyright (c) John Sundell 2018
|
|
* MIT license - see LICENSE.md
|
|
*/
|
|
|
|
import Foundation
|
|
import XCTest
|
|
import Splash
|
|
|
|
final class EnumTests: SyntaxHighlighterTestCase {
|
|
func testEnumDotSyntaxInAssignment() {
|
|
let components = highlighter.highlight("let value: Enum = .aCase")
|
|
|
|
XCTAssertEqual(components, [
|
|
.token("let", .keyword),
|
|
.whitespace(" "),
|
|
.plainText("value:"),
|
|
.whitespace(" "),
|
|
.token("Enum", .type),
|
|
.whitespace(" "),
|
|
.plainText("="),
|
|
.whitespace(" "),
|
|
.plainText("."),
|
|
.token("aCase", .dotAccess)
|
|
])
|
|
}
|
|
|
|
func testEnumDotSyntaxAsArgument() {
|
|
let components = highlighter.highlight("call(.aCase)")
|
|
|
|
XCTAssertEqual(components, [
|
|
.token("call", .call),
|
|
.plainText("(."),
|
|
.token("aCase", .dotAccess),
|
|
.plainText(")")
|
|
])
|
|
}
|
|
|
|
func testEnumDotSyntaxWithAssociatedValue() {
|
|
let components = highlighter.highlight("call(.error(error))")
|
|
|
|
XCTAssertEqual(components, [
|
|
.token("call", .call),
|
|
.plainText("(."),
|
|
.token("error", .dotAccess),
|
|
.plainText("(error))")
|
|
])
|
|
}
|
|
|
|
func testUsingEnumInSubscript() {
|
|
let components = highlighter.highlight("dictionary[.key]")
|
|
|
|
XCTAssertEqual(components, [
|
|
.plainText("dictionary[."),
|
|
.token("key", .dotAccess),
|
|
.plainText("]")
|
|
])
|
|
}
|
|
|
|
func testAllTestsRunOnLinux() {
|
|
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
|
|
}
|
|
}
|
|
|
|
extension EnumTests {
|
|
static var allTests: [(String, TestClosure<EnumTests>)] {
|
|
return [
|
|
("testEnumDotSyntaxInAssignment", testEnumDotSyntaxInAssignment),
|
|
("testEnumDotSyntaxAsArgument", testEnumDotSyntaxAsArgument),
|
|
("testEnumDotSyntaxWithAssociatedValue", testEnumDotSyntaxWithAssociatedValue),
|
|
("testUsingEnumInSubscript", testUsingEnumInSubscript)
|
|
]
|
|
}
|
|
}
|