From 510ba24186b082d5d725b301d1eaf65d278f220d Mon Sep 17 00:00:00 2001 From: Ruslan Alikhamov Date: Sun, 24 Dec 2023 01:16:03 +0400 Subject: [PATCH] Introduce package access level (#1245) * added package modifier * added tests for Variable * added tests for package access level --- SourceryRuntime/Sources/AST/AccessLevel.swift | 1 + SourceryRuntime/Sources/AST/Attribute.swift | 1 + SourceryTests/Models/ClassSpec.swift | 4 ++++ SourceryTests/Models/MethodSpec.swift | 5 +++++ SourceryTests/Models/ProtocolSpec.swift | 4 ++++ SourceryTests/Models/VariableSpec.swift | 2 ++ 6 files changed, 17 insertions(+) diff --git a/SourceryRuntime/Sources/AST/AccessLevel.swift b/SourceryRuntime/Sources/AST/AccessLevel.swift index 91dd12255..c293f99dc 100644 --- a/SourceryRuntime/Sources/AST/AccessLevel.swift +++ b/SourceryRuntime/Sources/AST/AccessLevel.swift @@ -7,6 +7,7 @@ import Foundation /// :nodoc: public enum AccessLevel: String { + case `package` = "package" case `internal` = "internal" case `private` = "private" case `fileprivate` = "fileprivate" diff --git a/SourceryRuntime/Sources/AST/Attribute.swift b/SourceryRuntime/Sources/AST/Attribute.swift index 01fe475d4..4120f7974 100644 --- a/SourceryRuntime/Sources/AST/Attribute.swift +++ b/SourceryRuntime/Sources/AST/Attribute.swift @@ -62,6 +62,7 @@ public class Attribute: NSObject, AutoCoding, AutoEquatable, AutoDiffable, AutoJ case final case open case lazy + case `package` = "package" case `public` = "public" case `internal` = "internal" case `private` = "private" diff --git a/SourceryTests/Models/ClassSpec.swift b/SourceryTests/Models/ClassSpec.swift index 7291d3c86..a3bf3fb46 100644 --- a/SourceryTests/Models/ClassSpec.swift +++ b/SourceryTests/Models/ClassSpec.swift @@ -24,6 +24,10 @@ class ClassSpec: QuickSpec { expect(sut?.kind).to(equal("class")) } + it("supports package access level") { + expect(Class(name: "Foo", accessLevel: .package).accessLevel == AccessLevel.package.rawValue).to(beTrue()) + expect(Class(name: "Foo", accessLevel: .internal).accessLevel == AccessLevel.package.rawValue).to(beFalse()) + } } } } diff --git a/SourceryTests/Models/MethodSpec.swift b/SourceryTests/Models/MethodSpec.swift index 24d6c359c..fd70f6651 100644 --- a/SourceryTests/Models/MethodSpec.swift +++ b/SourceryTests/Models/MethodSpec.swift @@ -60,6 +60,11 @@ class MethodSpec: QuickSpec { expect(Method(name: "foo()").isGeneric).to(beFalse()) } + it("has correct access level") { + expect(Method(name: "foo()", accessLevel: .package).accessLevel == AccessLevel.package.rawValue).to(beTrue()) + expect(Method(name: "foo()", accessLevel: .open).accessLevel == AccessLevel.package.rawValue).to(beFalse()) + } + describe("When testing equality") { context("given same items") { diff --git a/SourceryTests/Models/ProtocolSpec.swift b/SourceryTests/Models/ProtocolSpec.swift index 5c516a035..4c30f532a 100644 --- a/SourceryTests/Models/ProtocolSpec.swift +++ b/SourceryTests/Models/ProtocolSpec.swift @@ -24,6 +24,10 @@ class ProtocolSpec: QuickSpec { expect(sut?.kind).to(equal("protocol")) } + it("supports package access level") { + expect(Protocol(name: "Foo", accessLevel: .package).accessLevel == AccessLevel.package.rawValue).to(beTrue()) + expect(Protocol(name: "Foo", accessLevel: .internal).accessLevel == AccessLevel.package.rawValue).to(beFalse()) + } } } } diff --git a/SourceryTests/Models/VariableSpec.swift b/SourceryTests/Models/VariableSpec.swift index 8f466e83e..af698412a 100644 --- a/SourceryTests/Models/VariableSpec.swift +++ b/SourceryTests/Models/VariableSpec.swift @@ -26,6 +26,7 @@ class VariableSpec: QuickSpec { it("has proper read access") { expect(sut?.readAccess == AccessLevel.public.rawValue).to(beTrue()) + expect(Variable(name: "variable", typeName: TypeName(name: "Int"), accessLevel: (read: .package, write: .public), isComputed: true).readAccess == AccessLevel.package.rawValue).to(beTrue()) } it("has proper dynamic state") { @@ -35,6 +36,7 @@ class VariableSpec: QuickSpec { it("has proper write access") { expect(sut?.writeAccess == AccessLevel.internal.rawValue).to(beTrue()) + expect(Variable(name: "variable", typeName: TypeName(name: "Int"), accessLevel: (read: .public, write: .package), isComputed: true).writeAccess == AccessLevel.package.rawValue).to(beTrue()) } describe("When testing equality") {