Skip to content

Commit

Permalink
Add missing enum values for Swift 4.2
Browse files Browse the repository at this point in the history
in SwiftDeclarationAttributeKind and SyntaxKind
  • Loading branch information
jpsim committed Aug 30, 2018
1 parent 4a5def2 commit da3897f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
* Improve support for building & running with Swift 4.2.
[Norio Nomura](https://github.com/norio-nomura)

* Add new values for `SwiftDeclarationAttributeKind` and `SyntaxKind` with
Swift 4.2.
[JP Simard](https://github.com/jpsim)

##### Bug Fixes

* None.
Expand Down
10 changes: 10 additions & 0 deletions Source/SourceKittenFramework/SwiftDeclarationAttributeKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public enum SwiftDeclarationAttributeKind: String {
case consuming = "source.decl.attribute.__consuming"
case implicitlyUnwrappedOptional = "source.decl.attribute._implicitly_unwrapped_optional"

// only available in Swift >= 4.1.50
case underscoredObjcNonLazyRealization = "source.decl.attribute._objc_non_lazy_realization"
case clangImporterSynthesizedType = "source.decl.attribute._clangImporterSynthesizedType"
case forbidSerializingReference = "source.decl.attribute._forbidSerializingReference"
case usableFromInline = "source.decl.attribute.usableFromInline"
case weakLinked = "source.decl.attribute._weakLinked"
case inlinable = "source.decl.attribute.inlinable"
case dynamicMemberLookup = "source.decl.attribute.dynamicMemberLookup"
case frozen = "source.decl.attribute._frozen"

// only available in Swift < 4.1
case autoclosure = "source.decl.attribute.autoclosure"
case noescape = "source.decl.attribute.noescape"
Expand Down
2 changes: 2 additions & 0 deletions Source/SourceKittenFramework/SyntaxKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public enum SyntaxKind: String {
case stringInterpolationAnchor = "source.lang.swift.syntaxtype.string_interpolation_anchor"
/// `typeidentifier`.
case typeidentifier = "source.lang.swift.syntaxtype.typeidentifier"
/// `pounddirective.keyword`.
case poundDirectiveKeyword = "source.lang.swift.syntaxtype.pounddirective.keyword"

/// Returns the valid documentation comment syntax kinds.
internal static func docComments() -> [SyntaxKind] {
Expand Down
20 changes: 11 additions & 9 deletions Tests/SourceKittenFrameworkTests/DocInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ class DocInfoTests: XCTestCase {
}

func testModuleInfoRequest() throws {
#if swift(>=4.1.50)
#if swift(>=4.1.50)
// FIXME
print("\(#function) is failing with Swift(>=4.1.50)")
#else
#else
let swiftFile = fixturesDirectory + "DocInfo.swift"
let info = toNSDictionary(
try Request.moduleInfo(module: "",
arguments: [
"-c", swiftFile,
"-module-name", "DocInfo",
"-sdk", sdkPath()
]).send()
try Request.moduleInfo(
module: "",
arguments: [
"-c", swiftFile,
"-module-name", "DocInfo",
"-sdk", sdkPath()
]
).send()
)
compareJSONString(withFixtureNamed: "ModuleInfo", jsonString: toJSON(info))
#endif
#endif
}
}

Expand Down
54 changes: 40 additions & 14 deletions Tests/SourceKittenFrameworkTests/SourceKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ class SourceKitTests: XCTestCase {
}

func testSyntaxKinds() {
#if swift(>=4.1.50)
// FIXME
print("\(#function) is failing with Swift(>=4.1.50)")
#elseif swift(>=4.1)
let expected: [SyntaxKind] = [
#if swift(>=4.1)
var expected: [SyntaxKind] = [
.argument,
.attributeBuiltin,
.attributeID,
Expand All @@ -121,6 +118,14 @@ class SourceKitTests: XCTestCase {
.stringInterpolationAnchor,
.typeidentifier
]

#if swift(>=4.1.50)
expected.append(.poundDirectiveKeyword)
#else
// silence `let` warning
expected.append(contentsOf: [])
#endif

let actual = sourcekitStrings(startingWith: "source.lang.swift.syntaxtype.")
let expectedStrings = Set(expected.map { $0.rawValue })
XCTAssertEqual(
Expand All @@ -131,7 +136,7 @@ class SourceKitTests: XCTestCase {
print("the following strings were added: \(actual.subtracting(expectedStrings))")
print("the following strings were removed: \(expectedStrings.subtracting(actual))")
}
#endif
#endif
}

// swiftlint:disable:next function_body_length
Expand Down Expand Up @@ -190,11 +195,8 @@ class SourceKitTests: XCTestCase {

// swiftlint:disable:next function_body_length
func testSwiftDeclarationAttributeKind() {
#if swift(>=4.1.50)
// FIXME
print("\(#function) is failing with Swift(>=4.1.50)")
#elseif swift(>=4.1)
let expected: [SwiftDeclarationAttributeKind] = [
#if swift(>=4.1)
var expected: [SwiftDeclarationAttributeKind] = [
.ibaction,
.iboutlet,
.ibdesignable,
Expand Down Expand Up @@ -262,11 +264,35 @@ class SourceKitTests: XCTestCase {
.setterInternal,
.setterPublic,
.setterOpen,
.implicitlyUnwrappedOptional,
.optimize,
.consuming
.consuming,
.implicitlyUnwrappedOptional
]

#if swift(>=4.1.50)
let removed: [SwiftDeclarationAttributeKind] = [
.objcNonLazyRealization,
.inlineable,
.versioned
]

expected.removeAll(where: removed.contains)

expected.append(contentsOf: [
.underscoredObjcNonLazyRealization,
.clangImporterSynthesizedType,
.forbidSerializingReference,
.usableFromInline,
.weakLinked,
.inlinable,
.dynamicMemberLookup,
.frozen
])
#else
// silence `let` warning
expected.append(contentsOf: [])
#endif

let actual = sourcekitStrings(startingWith: "source.decl.attribute.")
let expectedStrings = Set(expected.map { $0.rawValue })
XCTAssertEqual(
Expand All @@ -277,7 +303,7 @@ class SourceKitTests: XCTestCase {
print("the following strings were added: \(actual.subtracting(expectedStrings))")
print("the following strings were removed: \(expectedStrings.subtracting(actual))")
}
#endif
#endif
}

func testLibraryWrappersAreUpToDate() throws {
Expand Down
11 changes: 3 additions & 8 deletions Tests/SourceKittenFrameworkTests/StructureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@ class StructureTests: XCTestCase {
}

func testGenerateSameStructureFileAndContents() throws {
#if swift(>=4.1.50)
// FIXME
print("\(#function) is failing with Swift(>=4.1.50)")
#else
let fileContents = try String(contentsOfFile: #file, encoding: .utf8)
try XCTAssertEqual(Structure(file: File(path: #file)!),
Structure(file: File(contents: fileContents)),
"should generate the same structure for a file as raw text")
#endif
}

func testEnum() throws {
Expand Down Expand Up @@ -100,11 +95,11 @@ class StructureTests: XCTestCase {
]
],
"key.runtime_name": {
#if swift(>=4.1.50)
#if swift(>=4.1.50)
return "_TtC4main3Foo"
#else
#else
return "_TtC8__main__3Foo"
#endif
#endif
}(),
"key.inheritedtypes": [
["key.name": "Bar"]
Expand Down

0 comments on commit da3897f

Please sign in to comment.