From da3897f53b3d19cff083e4aa84648f95f297d581 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Thu, 30 Aug 2018 14:09:27 -0700 Subject: [PATCH] Add missing enum values for Swift 4.2 in SwiftDeclarationAttributeKind and SyntaxKind --- CHANGELOG.md | 4 ++ .../SwiftDeclarationAttributeKind.swift | 10 ++++ Source/SourceKittenFramework/SyntaxKind.swift | 2 + .../DocInfoTests.swift | 20 +++---- .../SourceKitTests.swift | 54 ++++++++++++++----- .../StructureTests.swift | 11 ++-- 6 files changed, 70 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eddabb96..f1c6e790b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/Source/SourceKittenFramework/SwiftDeclarationAttributeKind.swift b/Source/SourceKittenFramework/SwiftDeclarationAttributeKind.swift index 80581b7d0..289442b4d 100644 --- a/Source/SourceKittenFramework/SwiftDeclarationAttributeKind.swift +++ b/Source/SourceKittenFramework/SwiftDeclarationAttributeKind.swift @@ -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" diff --git a/Source/SourceKittenFramework/SyntaxKind.swift b/Source/SourceKittenFramework/SyntaxKind.swift index baafdc301..f1470b970 100644 --- a/Source/SourceKittenFramework/SyntaxKind.swift +++ b/Source/SourceKittenFramework/SyntaxKind.swift @@ -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] { diff --git a/Tests/SourceKittenFrameworkTests/DocInfoTests.swift b/Tests/SourceKittenFrameworkTests/DocInfoTests.swift index ad046be25..2f7ec8465 100644 --- a/Tests/SourceKittenFrameworkTests/DocInfoTests.swift +++ b/Tests/SourceKittenFrameworkTests/DocInfoTests.swift @@ -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 } } diff --git a/Tests/SourceKittenFrameworkTests/SourceKitTests.swift b/Tests/SourceKittenFrameworkTests/SourceKitTests.swift index e0705b184..7c2dcebf5 100644 --- a/Tests/SourceKittenFrameworkTests/SourceKitTests.swift +++ b/Tests/SourceKittenFrameworkTests/SourceKitTests.swift @@ -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, @@ -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( @@ -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 @@ -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, @@ -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( @@ -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 { diff --git a/Tests/SourceKittenFrameworkTests/StructureTests.swift b/Tests/SourceKittenFrameworkTests/StructureTests.swift index 0b76273a9..13ff49da7 100644 --- a/Tests/SourceKittenFrameworkTests/StructureTests.swift +++ b/Tests/SourceKittenFrameworkTests/StructureTests.swift @@ -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 { @@ -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"]