Sfoglia il codice sorgente

add PluginExample for UseAccessLevelOnImports option

Jakub Skotnicki 1 anno fa
parent
commit
3f34c41ab9

+ 32 - 7
PluginExamples/Package.swift

@@ -7,14 +7,22 @@ let package = Package(
     dependencies: [
         .package(path: "../")
     ],
-    targets: [
+    targets: targets()
+)
+
+private func targets() -> [Target] {
+    var testDependencies: [Target.Dependency] = [
+        .target(name: "Simple"),
+        .target(name: "Nested"),
+        .target(name: "Import"),
+    ]
+#if compiler(>=5.9)
+    testDependencies.append(.target(name: "AccessLevelOnImport"))
+#endif
+    var targets: [Target] = [
         .testTarget(
             name: "ExampleTests",
-            dependencies: [
-                .target(name: "Simple"),
-                .target(name: "Nested"),
-                .target(name: "Import"),
-            ]
+            dependencies: testDependencies
         ),
         .target(
             name: "Simple",
@@ -44,4 +52,21 @@ let package = Package(
             ]
         ),
     ]
-)
+#if compiler(>=5.9)
+    targets.append(
+        .target(
+            name: "AccessLevelOnImport",
+            dependencies: [
+                .product(name: "SwiftProtobuf", package: "swift-protobuf"),
+            ],
+            swiftSettings: [
+                .enableExperimentalFeature("AccessLevelOnImport"),
+            ],
+            plugins: [
+                .plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf")
+            ]
+        )
+    )
+#endif
+    return targets
+}

+ 7 - 0
PluginExamples/Sources/AccessLevelOnImport/AccessLevelOnImport/AccessLevelOnImport.proto

@@ -0,0 +1,7 @@
+syntax = "proto3";
+
+import "Dependency/Dependency.proto";
+
+message AccessLevelOnImport {
+  Dependency dependency = 1;
+}

+ 5 - 0
PluginExamples/Sources/AccessLevelOnImport/Dependency/Dependency.proto

@@ -0,0 +1,5 @@
+syntax = "proto3";
+
+message Dependency {
+  string name = 1;
+}

+ 3 - 0
PluginExamples/Sources/AccessLevelOnImport/empty.swift

@@ -0,0 +1,3 @@
+/// DO NOT DELETE.
+///
+/// We need to keep this file otherwise the plugin is not running.

+ 12 - 0
PluginExamples/Sources/AccessLevelOnImport/swift-protobuf-config.json

@@ -0,0 +1,12 @@
+{
+    "invocations": [
+        {
+            "protoFiles": [
+                "AccessLevelOnImport/AccessLevelOnImport.proto",
+                "Dependency/Dependency.proto",
+            ],
+            "visibility": "public",
+            "useAccessLevelOnImports": true
+        }
+    ]
+}

+ 13 - 0
PluginExamples/Sources/ExampleTests/AccessLevelOnImportTests.swift

@@ -0,0 +1,13 @@
+#if compiler(>=5.9)
+
+import AccessLevelOnImport
+import XCTest
+
+final class AccessLevelOnImportTests: XCTestCase {
+    func testAccessLevelOnImport() {
+        let access = AccessLevelOnImport.with { $0.dependency = .with { $0.name = "Dependency" } }
+        XCTAssertEqual(access.dependency.name, "Dependency")
+    }
+}
+
+#endif