0001
0009 import Foundation
0010 import SourceKittenFramework
0011 import XCTest
0012
0013 func compareSyntax| SyntaxTests.swift:48 | compareSyntax(File(contents: "struct A { subscript(index: Int) -> () { return () } }"), |
| SyntaxTests.swift:61 | compareSyntax(File(contents: "import Foundation // Hello World!"), |
(file: File, _ expectedTokens: [(SyntaxKind, Int, Int)]) {
0014 let expectedSyntaxMap = SyntaxMap(tokens: expectedTokens.map { tokenTuple in
0015 return SyntaxToken(type: tokenTuple.0.rawValue, offset: tokenTuple.1, length: tokenTuple.2)
0016 })
0017 let syntaxMap = SyntaxMap(file: file)
0018 XCTAssertEqual(syntaxMap, expectedSyntaxMap, "should generate expected syntax map")
0019
0020 let syntaxJSON = syntaxMap.description
0021 let jsonArray = try! NSJSONSerialization.JSONObjectWithData(syntaxJSON.dataUsingEncoding(NSUTF8StringEncoding)!, options: []) as? NSArray
0022 XCTAssertNotNil(jsonArray, "JSON should be propery parsed")
0023 XCTAssertEqual(jsonArray!, expectedSyntaxMap.tokens.map { $0.dictionaryValue }, "JSON should match expected syntax")
0024 }
0025
0026 class SyntaxTests| main_.swift:21 | SyntaxTests(), |
: XCTestCase {
0027
0028 lazy var allTests: [(String, () throws -> Void)] = [
0030 ("testPrintEmptySyntax", self.testPrintEmptySyntax),
0031 ("testGenerateSameSyntaxMapFileAndContents", self.testGenerateSameSyntaxMapFileAndContents),
0032 ("testSubscript", self.testSubscript),
0033 ("testSyntaxMapPrintValidJSON", self.testSyntaxMapPrintValidJSON),
0034 ]
0035
0036 func testPrintEmptySyntax| SyntaxTests.swift:30 | ("testPrintEmptySyntax", self.testPrintEmptySyntax), |
() {
0037 XCTAssertEqual(SyntaxMap(file: File(contents: "")).description, "[\n\n]", "should print empty syntax")
0038 }
0039
0040 func testGenerateSameSyntaxMapFileAndContents| SyntaxTests.swift:31 | ("testGenerateSameSyntaxMapFileAndContents", self.testGenerateSameSyntaxMapFileAndContents), |
() {
0041 let fileContents = try! NSString(contentsOfFile: __FILE__, encoding: NSUTF8StringEncoding) as String!
0042 XCTAssertEqual(SyntaxMap(file: File(path: __FILE__)!),
0043 SyntaxMap(file: File(contents: fileContents)),
0044 "should generate the same syntax map for a file as raw text")
0045 }
0046
0047 func testSubscript| SyntaxTests.swift:32 | ("testSubscript", self.testSubscript), |
() {
0048 compareSyntax(File(contents: "struct A { subscript(index: Int) -> () { return () } }"),
0049 [
0050 (.Keyword, 0, 6),
0051 (.Identifier, 7, 1),
0052 (.Keyword, 11, 9),
0053 (.Identifier, 21, 5),
0054 (.Typeidentifier, 28, 3),
0055 (.Keyword, 41, 6)
0056 ]
0057 )
0058 }
0059
0060 func testSyntaxMapPrintValidJSON| SyntaxTests.swift:33 | ("testSyntaxMapPrintValidJSON", self.testSyntaxMapPrintValidJSON), |
() {
0061 compareSyntax(File(contents: "import Foundation // Hello World!"),
0062 [
0063 (.Keyword, 0, 6),
0064 (.Identifier, 7, 10),
0065 (.Comment, 18, 15)
0066 ]
0067 )
0068 }
0069 }
0070