From 43f163bebc2255a9a2d183cd4184cfe00c1dd911 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Tue, 12 Mar 2019 00:52:18 +0100 Subject: [PATCH] Add test verifying that custom string interpolation works (#54) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Swift 5 enables us to define custom ways to interpolate expressions into strings, and Splash already successfully highlights that syntax, but let’s add a test to make sure that continues to be the case. --- Tests/SplashTests/Tests/LiteralTests.swift | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Tests/SplashTests/Tests/LiteralTests.swift b/Tests/SplashTests/Tests/LiteralTests.swift index 220bf94..052f117 100644 --- a/Tests/SplashTests/Tests/LiteralTests.swift +++ b/Tests/SplashTests/Tests/LiteralTests.swift @@ -76,6 +76,30 @@ final class LiteralTests: SyntaxHighlighterTestCase { ]) } + func testStringLiteralWithCustomIterpolation() { + let components = highlighter.highlight(""" + "Hello \\(label: a, b) world \\(label: call())" + """) + + XCTAssertEqual(components, [ + .token("\"Hello", .string), + .whitespace(" "), + .plainText("\\(label:"), + .whitespace(" "), + .plainText("a,"), + .whitespace(" "), + .plainText("b)"), + .whitespace(" "), + .token("world", .string), + .whitespace(" "), + .plainText("\\(label:"), + .whitespace(" "), + .token("call", .call), + .plainText("())"), + .token("\"", .string) + ]) + } + func testMultiLineStringLiteral() { let components = highlighter.highlight(""" let string = \"\"\" @@ -194,6 +218,7 @@ extension LiteralTests { ("testStringLiteralWithEscapedQuote", testStringLiteralWithEscapedQuote), ("testStringLiteralWithAttribute", testStringLiteralWithAttribute), ("testStringLiteralInterpolation", testStringLiteralInterpolation), + ("testStringLiteralWithCustomIterpolation", testStringLiteralWithCustomIterpolation), ("testMultiLineStringLiteral", testMultiLineStringLiteral), ("testSingleLineRawStringLiteral", testSingleLineRawStringLiteral), ("testMultiLineRawStringLiteral", testMultiLineRawStringLiteral),