Skip to content

Commit f9b8d79

Browse files
ikesyojpsim
authored andcommitted
Test SwiftDocKey.elements
1 parent b51d27a commit f9b8d79

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

Tests/LinuxMain.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ XCTMain([
1111
testCase(SourceKitTests.allTests),
1212
testCase(StringTests.allTests),
1313
testCase(StructureTests.allTests),
14+
testCase(SwiftDocKeyTests.allTests),
1415
testCase(SwiftDocsTests.allTests),
1516
testCase(SyntaxTests.allTests)
1617
])

Tests/SourceKittenFrameworkTests/StructureTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,40 @@ class StructureTests: XCTestCase {
7373
XCTAssertEqual(toNSDictionary(structure.dictionary), expectedStructure, "should generate expected structure")
7474
}
7575

76+
func testInheritedType() {
77+
let structure = try! Structure(file: File(contents: "class Foo: Bar {}"))
78+
let expected: NSDictionary = [
79+
"key.substructure": [
80+
[
81+
"key.kind": "source.lang.swift.decl.class",
82+
"key.accessibility": "source.lang.swift.accessibility.internal",
83+
"key.offset": 0,
84+
"key.nameoffset": 6,
85+
"key.namelength": 3,
86+
"key.bodyoffset": 16,
87+
"key.bodylength": 0,
88+
"key.length": 17,
89+
"key.name": "Foo",
90+
"key.elements": [
91+
[
92+
"key.kind": "source.lang.swift.structure.elem.typeref",
93+
"key.offset": 11,
94+
"key.length": 3
95+
]
96+
],
97+
"key.runtime_name": "_TtC8__main__3Foo",
98+
"key.inheritedtypes": [
99+
["key.name": "Bar"]
100+
]
101+
]
102+
],
103+
"key.offset": 0,
104+
"key.diagnostic_stage": "source.diagnostic.stage.swift.parse",
105+
"key.length": 17
106+
]
107+
XCTAssertEqual(toNSDictionary(structure.dictionary), expected, "should generate expected structure")
108+
}
109+
76110
func testStructurePrintValidJSON() {
77111
let structure = try! Structure(file: File(contents: "struct A { func b() {} }"))
78112
let expectedStructure: NSDictionary = [
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// SwiftDocKeyTests.swift
3+
// SourceKittenFrameworkTests
4+
//
5+
// Created by Sho Ikeda on 2/22/18.
6+
// Copyright © 2018 SourceKitten. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import SourceKittenFramework
11+
import XCTest
12+
13+
class SwiftDocKeyTests: XCTestCase {
14+
15+
func testElements() {
16+
let structure = try! Structure(file: File(contents: "class Foo: Bar {}"))
17+
let substructures = structure.dictionary[SwiftDocKey.substructure.rawValue] as! [[String: SourceKitRepresentable]]
18+
let elements = (substructures[0][SwiftDocKey.elements.rawValue] as! [[String: SourceKitRepresentable]]).map(toNSDictionary)
19+
let expected: [NSDictionary] = [
20+
[
21+
"key.kind": "source.lang.swift.structure.elem.typeref",
22+
"key.offset": 11,
23+
"key.length": 3
24+
]
25+
]
26+
XCTAssertEqual(elements, expected)
27+
}
28+
29+
}
30+
31+
extension SwiftDocKeyTests {
32+
static var allTests: [(String, (SwiftDocKeyTests) -> () throws -> Void)] {
33+
return [
34+
("testElements", testElements)
35+
]
36+
}
37+
}

sourcekitten.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
6CCFCE901CFED005003239EB /* Result.framework in Embed Frameworks into SourceKittenFramework.framework */ = {isa = PBXBuildFile; fileRef = E834D61D1B2D054B002AA1FE /* Result.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2626
B2FA87E26BC9C5F774FD694C /* SwiftLangSyntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2FA804AA9D4427FF571EFB2 /* SwiftLangSyntax.swift */; };
2727
C236E84B1DFF5120003807D2 /* YamlRequestCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C236E84A1DFF5120003807D2 /* YamlRequestCommand.swift */; };
28+
CDB51F33203E2899007563AE /* SwiftDocKeyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB51F32203E2899007563AE /* SwiftDocKeyTests.swift */; };
2829
D0AAAB5019FB0960007B24B3 /* SourceKittenFramework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D0D1216D19E87B05005E4BAA /* SourceKittenFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2930
D0D1217219E87B05005E4BAA /* SourceKittenFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = D0D1217119E87B05005E4BAA /* SourceKittenFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
3031
D0D1217819E87B05005E4BAA /* SourceKittenFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0D1216D19E87B05005E4BAA /* SourceKittenFramework.framework */; };
@@ -147,6 +148,7 @@
147148
6CFC18F01C7F2FB900CD70E1 /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
148149
B2FA804AA9D4427FF571EFB2 /* SwiftLangSyntax.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftLangSyntax.swift; sourceTree = "<group>"; };
149150
C236E84A1DFF5120003807D2 /* YamlRequestCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YamlRequestCommand.swift; sourceTree = "<group>"; };
151+
CDB51F32203E2899007563AE /* SwiftDocKeyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDocKeyTests.swift; sourceTree = "<group>"; };
150152
D0D1211B19E87861005E4BAA /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; usesTabs = 0; };
151153
D0D1212419E878CC005E4BAA /* Common.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Common.xcconfig; sourceTree = "<group>"; };
152154
D0D1212619E878CC005E4BAA /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
@@ -454,6 +456,7 @@
454456
E805A0471B55CBAF00EA654A /* SourceKitTests.swift */,
455457
E8C9EA071A5C99C400A6D4D1 /* StringTests.swift */,
456458
E8C9EA031A5C986A00A6D4D1 /* StructureTests.swift */,
459+
CDB51F32203E2899007563AE /* SwiftDocKeyTests.swift */,
457460
E80F23661A5CADD900FD2352 /* SwiftDocsTests.swift */,
458461
D0DB09A319EA354200234B16 /* SyntaxTests.swift */,
459462
);
@@ -708,6 +711,7 @@
708711
E8C9EA0A1A5C9A2900A6D4D1 /* OffsetMapTests.swift in Sources */,
709712
E805A0481B55CBAF00EA654A /* SourceKitTests.swift in Sources */,
710713
E8C9EA081A5C99C400A6D4D1 /* StringTests.swift in Sources */,
714+
CDB51F33203E2899007563AE /* SwiftDocKeyTests.swift in Sources */,
711715
E8C9EA041A5C986A00A6D4D1 /* StructureTests.swift in Sources */,
712716
E80F23671A5CADD900FD2352 /* SwiftDocsTests.swift in Sources */,
713717
D0DB09A419EA354200234B16 /* SyntaxTests.swift in Sources */,

0 commit comments

Comments
 (0)