Skip to content

Commit

Permalink
Updates to TypedSpec.stencil
Browse files Browse the repository at this point in the history
  • Loading branch information
art-divin committed Mar 19, 2024
1 parent b581ccd commit 1ba4f3e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions Sourcery/Templates/TypedSpec.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,40 @@ class TypedSpec: QuickSpec {

#if canImport(ObjectiveC)
it("can report optional via KVC") {
expect({{ type.name }}(typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect({{ type.name }}(typeName: typeName("Int!")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect({{ type.name }}(typeName: typeName("Int?")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(false))
expect({{ type.name }}(typeName: typeName("Int!")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(true))
expect({{ type.name }}(typeName: typeName("Int?")).value(forKeyPath: "unwrappedTypeName") as? String).to(equal("Int"))
expect({{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("Int?")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect({{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("Int!")).value(forKeyPath: "isOptional") as? Bool).to(equal(true))
expect({{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("Int?")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(false))
expect({{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("Int!")).value(forKeyPath: "isImplicitlyUnwrappedOptional") as? Bool).to(equal(true))
expect({{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("Int?")).value(forKeyPath: "unwrappedTypeName") as? String).to(equal("Int"))
}

it("can report tuple type via KVC") {
let sut = {{ type.name }}(typeName: typeName("(Int, Int)"))
let sut = {{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("(Int, Int)"))
expect(sut.value(forKeyPath: "isTuple") as? Bool).to(equal(true))
}

it("can report closure type via KVC") {
let sut = {{ type.name }}(typeName: typeName("(Int) -> (Int)"))
let sut = {{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("(Int) -> (Int)"))
expect(sut.value(forKeyPath: "isClosure") as? Bool).to(equal(true))
}

it("can report array type via KVC") {
let sut = {{ type.name }}(typeName: typeName("[Int]"))
let sut = {{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("[Int]"))
expect(sut.value(forKeyPath: "isArray") as? Bool).to(equal(true))
}

it("can report set type via KVC") {
let sut = {{ type.name }}(typeName: typeName("Set<Int>"))
let sut = {{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("Set<Int>"))
expect(sut.value(forKeyPath: "isSet") as? Bool).to(equal(true))
}

it("can report dictionary type via KVC") {
let sut = {{ type.name }}(typeName: typeName("[Int: Int]"))
let sut = {{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("[Int: Int]"))
expect(sut.value(forKeyPath: "isDictionary") as? Bool).to(equal(true))
}

it("can report actual type name via KVC") {
let sut = {{ type.name }}(typeName: typeName("Alias"))
let sut = {{ type.name }}({% if type.name == "MethodParameter" %}index: 0, {% endif %}typeName: typeName("Alias"))
expect(sut.value(forKeyPath: "actualTypeName") as? TypeName).to(equal(typeName("Alias")))

sut.typeName.actualTypeName = typeName("Int")
Expand Down
10 changes: 5 additions & 5 deletions SourceryRuntime/Sources/Linux/AST/MethodParameter_Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,42 +168,42 @@ public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffabl
/// :nodoc:
required public init?(coder aDecoder: NSCoder) {
self.argumentLabel = aDecoder.decode(forKey: "argumentLabel")
guard let name: String = aDecoder.decode(forKey: "name") else {
guard let name: String = aDecoder.decode(forKey: "name") else {
withVaList(["name"]) { arguments in
NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments)
}
fatalError()
}; self.name = name
guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else {
guard let typeName: TypeName = aDecoder.decode(forKey: "typeName") else {
withVaList(["typeName"]) { arguments in
NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments)
}
fatalError()
}; self.typeName = typeName
self.index = aDecoder.decode(forKey: "index")
self.`inout` = aDecoder.decode(forKey: "`inout`")
self.isVariadic = aDecoder.decode(forKey: "isVariadic")
self.type = aDecoder.decode(forKey: "type")
self.defaultValue = aDecoder.decode(forKey: "defaultValue")
guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else {
guard let annotations: Annotations = aDecoder.decode(forKey: "annotations") else {
withVaList(["annotations"]) { arguments in
NSException.raise(NSExceptionName.parseErrorException, format: "Key '%@' not found.", arguments: arguments)
}
fatalError()
}; self.annotations = annotations
self.index = aDecoder.decode(forKey: "index")
}

/// :nodoc:
public func encode(with aCoder: NSCoder) {
aCoder.encode(self.argumentLabel, forKey: "argumentLabel")
aCoder.encode(self.name, forKey: "name")
aCoder.encode(self.index, forKey: "index")
aCoder.encode(self.typeName, forKey: "typeName")
aCoder.encode(self.`inout`, forKey: "`inout`")
aCoder.encode(self.isVariadic, forKey: "isVariadic")
aCoder.encode(self.type, forKey: "type")
aCoder.encode(self.defaultValue, forKey: "defaultValue")
aCoder.encode(self.annotations, forKey: "annotations")
aCoder.encode(self.index, forKey: "index")
}
// sourcery:end
}
Expand Down
4 changes: 2 additions & 2 deletions SourceryRuntime/Sources/macOS/AST/MethodParameter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffabl
}
fatalError()
}; self.typeName = typeName
self.index = aDecoder.decode(forKey: "index")
self.`inout` = aDecoder.decode(forKey: "`inout`")
self.isVariadic = aDecoder.decode(forKey: "isVariadic")
self.type = aDecoder.decode(forKey: "type")
Expand All @@ -170,19 +169,20 @@ public class MethodParameter: NSObject, SourceryModel, Typed, Annotated, Diffabl
}
fatalError()
}; self.annotations = annotations
self.index = aDecoder.decode(forKey: "index")
}

/// :nodoc:
public func encode(with aCoder: NSCoder) {
aCoder.encode(self.argumentLabel, forKey: "argumentLabel")
aCoder.encode(self.name, forKey: "name")
aCoder.encode(self.index, forKey: "index")
aCoder.encode(self.typeName, forKey: "typeName")
aCoder.encode(self.`inout`, forKey: "`inout`")
aCoder.encode(self.isVariadic, forKey: "isVariadic")
aCoder.encode(self.type, forKey: "type")
aCoder.encode(self.defaultValue, forKey: "defaultValue")
aCoder.encode(self.annotations, forKey: "annotations")
aCoder.encode(self.index, forKey: "index")
}
// sourcery:end
}
Expand Down

0 comments on commit 1ba4f3e

Please sign in to comment.