From 1e08cab4a53c9f821fa72376e8a5f8f12af9ef5f Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 12 May 2023 18:04:41 -0700 Subject: [PATCH] Tests: escape the path separator for Windows `\` must be escaped for valid JSON. Ensure that we properly escape the character and form the reference string with the proper representation of the path. --- .../SourceKitObjectTests.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Tests/SourceKittenFrameworkTests/SourceKitObjectTests.swift b/Tests/SourceKittenFrameworkTests/SourceKitObjectTests.swift index 962edda3..3aa7fafd 100644 --- a/Tests/SourceKittenFrameworkTests/SourceKitObjectTests.swift +++ b/Tests/SourceKittenFrameworkTests/SourceKitObjectTests.swift @@ -1,10 +1,13 @@ +import Foundation import SourceKittenFramework import XCTest class SourceKitObjectTests: XCTestCase { func testExample() { - let path = #file + let path = + URL(fileURLWithPath: #file) + .withUnsafeFileSystemRepresentation { String(cString: $0!) } let object: SourceKitObject = [ "key.request": UID("source.request.editor.open"), "key.name": path, @@ -13,8 +16,8 @@ class SourceKitObjectTests: XCTestCase { let expected = """ { key.request: source.request.editor.open, - key.name: \"\(#file)\", - key.sourcefile: \"\(#file)\" + key.name: \"\((#file).replacingOccurrences(of: "\\", with: "\\\\"))\", + key.sourcefile: \"\((#file).replacingOccurrences(of: "\\", with: "\\\\"))\" } """ XCTAssertEqual(object.description, expected)