Skip to content

Commit 2890a2e

Browse files
committed
fix: automockable tuple properties
1 parent 2011813 commit 2890a2e

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
# [0.2.5] - 2024-11-15
9+
10+
### Fixed
11+
12+
- Automackable support to handle tupples
13+
814
# [0.2.4] - 2024-11-14
915

1016
### Fixed

Sources/SageSwiftKitClient/main.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ struct PlayingObject {
3939

4040
@AutoMockable()
4141
public protocol DateSelectorViewModel {
42-
func make() throws -> String
42+
var onTap: (String, Int?) -> Void { get set }
43+
var onString: String { get set }
44+
var onDouble: Double? { get set }
4345
}

Sources/SageSwiftKitMacros/MockableMacros/Auxiliars/Builders/ProtocolVarsConformanceBuilder.swift

+20-4
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,33 @@ struct ProtocolVarsConformanceBuilder {
2020
}
2121

2222
var typeReturnVar: TypeAnnotationSyntax? {
23-
guard let myType = variable.bindings.first?.typeAnnotation else {
23+
guard let typeAnnotation = variable.bindings.first?.typeAnnotation else {
2424
return nil
2525
}
2626

27-
if let optional = myType.type.as(OptionalTypeSyntax.self) {
28-
return TypeAnnotationSyntax(type: optional)
27+
let type = typeAnnotation.type
28+
29+
if type.as(OptionalTypeSyntax.self) != nil || type.as(ImplicitlyUnwrappedOptionalTypeSyntax.self) != nil {
30+
return typeAnnotation
31+
}
32+
33+
if let funcType = type.as(FunctionTypeSyntax.self) {
34+
return TypeAnnotationSyntax(
35+
type: ImplicitlyUnwrappedOptionalTypeSyntax(
36+
wrappedType: TupleTypeSyntax(
37+
elements: .init(itemsBuilder: {
38+
TupleTypeElementSyntax(
39+
type: funcType.trimmed
40+
)
41+
})
42+
)
43+
)
44+
)
2945
}
3046

3147
return TypeAnnotationSyntax(
3248
type: ImplicitlyUnwrappedOptionalTypeSyntax(
33-
wrappedType: myType.type.trimmed,
49+
wrappedType: type.trimmed,
3450
exclamationMark: .exclamationMarkToken()
3551
)
3652
)

0 commit comments

Comments
 (0)