0001
0009 import Foundation
0010 import SourceKittenFramework
0011 import XCTest
0012
0013 private func run| SourceKitTests.swift:30 | let sourceKitServicePath = (((run("/usr/bin/xcrun", arguments: ["-f", "swiftc"])! as NSString) |
| SourceKitTests.swift:34 | let strings = run("/usr/bin/strings", arguments: [sourceKitServicePath]) |
(executable: String, arguments: [String]) -> String? {
0014 let task = NSTask()
0015 task.launchPath = executable
0016 task.arguments = arguments
0017
0018 let pipe = NSPipe()
0019 task.standardOutput = pipe
0020
0021 task.launch()
0022
0023 let file = pipe.fileHandleForReading
0024 let output = NSString(data: file.readDataToEndOfFile(), encoding: NSUTF8StringEncoding)
0025 file.closeFile()
0026 return output as String?
0027 }
0028
0029 private func sourcekitStringsStartingWith| SourceKitTests.swift:62 | let actual = sourcekitStringsStartingWith("source.lang.swift.stmt.") |
| SourceKitTests.swift:96 | let actual = sourcekitStringsStartingWith("source.lang.swift.syntaxtype.") |
| SourceKitTests.swift:145 | let actual = sourcekitStringsStartingWith("source.lang.swift.decl.") |
(pattern: String) -> Set<String> {
0030 let sourceKitServicePath = (((run("/usr/bin/xcrun", arguments: ["-f", "swiftc"])! as NSString)
0031 .stringByDeletingLastPathComponent as NSString)
0032 .stringByDeletingLastPathComponent as NSString)
0033 .stringByAppendingPathComponent("lib/sourcekitd.framework/XPCServices/SourceKitService.xpc/Contents/MacOS/SourceKitService")
0034 let strings = run("/usr/bin/strings", arguments: [sourceKitServicePath])
0035 return Set(strings!.componentsSeparatedByString("\n").filter { string in
0036 return string.rangeOfString(pattern)?.startIndex == string.startIndex
0037 })
0038 }
0039
0040 class SourceKitTests| main_.swift:17 | SourceKitTests(), |
: XCTestCase {
0041
0042 lazy var allTests: [(String, () throws -> Void)] = [
0044 ("testStatementKinds", self.testStatementKinds),
0045 ("testSyntaxKinds", self.testSyntaxKinds),
0046 ("testSwiftDeclarationKind", self.testSwiftDeclarationKind),
0047 ]
0048
0049 func testStatementKinds| SourceKitTests.swift:44 | ("testStatementKinds", self.testStatementKinds), |
() {
0050 let expected: [StatementKind] = [
0051 .Brace,
0052 .Case,
0053 .For,
0054 .ForEach,
0055 .Guard,
0056 .If,
0057 .RepeatWhile,
0058 .Switch,
0059 .While,
0060 ]
0061
0062 let actual = sourcekitStringsStartingWith("source.lang.swift.stmt.")
0063 let expectedStrings = Set(expected.map { $0.rawValue })
0064 XCTAssertEqual(
0065 actual,
0066 expectedStrings
0067 )
0068 if actual != expectedStrings {
0069 print("the following strings were added: \(actual.subtract(expectedStrings))")
0070 print("the following strings were removed: \(expectedStrings.subtract(actual))")
0071 }
0072 }
0073
0074 func testSyntaxKinds| SourceKitTests.swift:45 | ("testSyntaxKinds", self.testSyntaxKinds), |
() {
0075 let expected: [SyntaxKind] = [
0076 .Argument,
0077 .AttributeBuiltin,
0078 .AttributeID,
0079 .BuildconfigID,
0080 .BuildconfigKeyword,
0081 .Comment,
0082 .CommentMark,
0083 .CommentURL,
0084 .DocComment,
0085 .DocCommentField,
0086 .Identifier,
0087 .Keyword,
0088 .Number,
0089 .ObjectLiteral,
0090 .Parameter,
0091 .Placeholder,
0092 .String,
0093 .StringInterpolationAnchor,
0094 .Typeidentifier
0095 ]
0096 let actual = sourcekitStringsStartingWith("source.lang.swift.syntaxtype.")
0097 let expectedStrings = Set(expected.map { $0.rawValue })
0098 XCTAssertEqual(
0099 actual,
0100 expectedStrings
0101 )
0102 if actual != expectedStrings {
0103 print("the following strings were added: \(actual.subtract(expectedStrings))")
0104 print("the following strings were removed: \(expectedStrings.subtract(actual))")
0105 }
0106 }
0107
0108 func testSwiftDeclarationKind| SourceKitTests.swift:46 | ("testSwiftDeclarationKind", self.testSwiftDeclarationKind), |
() {
0109 let expected: [SwiftDeclarationKind] = [
0110 .Class,
0111 .Enum,
0112 .Enumcase,
0113 .Enumelement,
0114 .Extension,
0115 .ExtensionClass,
0116 .ExtensionEnum,
0117 .ExtensionProtocol,
0118 .ExtensionStruct,
0119 .FunctionAccessorAddress,
0120 .FunctionAccessorDidset,
0121 .FunctionAccessorGetter,
0122 .FunctionAccessorMutableaddress,
0123 .FunctionAccessorSetter,
0124 .FunctionAccessorWillset,
0125 .FunctionConstructor,
0126 .FunctionDestructor,
0127 .FunctionFree,
0128 .FunctionMethodClass,
0129 .FunctionMethodInstance,
0130 .FunctionMethodStatic,
0131 .FunctionOperator,
0132 .FunctionSubscript,
0133 .GenericTypeParam,
0134 .Module,
0135 .Protocol,
0136 .Struct,
0137 .Typealias,
0138 .VarClass,
0139 .VarGlobal,
0140 .VarInstance,
0141 .VarLocal,
0142 .VarParameter,
0143 .VarStatic
0144 ]
0145 let actual = sourcekitStringsStartingWith("source.lang.swift.decl.")
0146 let expectedStrings = Set(expected.map { $0.rawValue })
0147 XCTAssertEqual(
0148 actual,
0149 expectedStrings
0150 )
0151 if actual != expectedStrings {
0152 print("the following strings were added: \(actual.subtract(expectedStrings))")
0153 print("the following strings were removed: \(expectedStrings.subtract(actual))")
0154 }
0155 }
0156 }
0157