Skip to content

Commit 22edb9c

Browse files
authored
Lowered SDK requirements to macOS 14 (#10)
1 parent 6381001 commit 22edb9c

File tree

4 files changed

+164
-8
lines changed

4 files changed

+164
-8
lines changed

Package.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
// swift-tools-version: 6.1
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "PrincipleMacros",
88
platforms: [
9-
.macOS(.v15),
10-
.macCatalyst(.v18),
11-
.iOS(.v18),
12-
.tvOS(.v18),
13-
.watchOS(.v11),
14-
.visionOS(.v2)
9+
.macOS(.v14),
10+
.macCatalyst(.v17),
11+
.iOS(.v17),
12+
.tvOS(.v17),
13+
.watchOS(.v10),
14+
.visionOS(.v1)
1515
],
1616
products: [
1717
.library(

Sources/PrincipleMacros/Parsers/Properties/PropertiesList.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ extension PropertiesList {
4646

4747
extension PropertiesList {
4848

49+
public var uniqueInferredTypes: [TypeSyntax] {
50+
let allInferredTypes = all.lazy.map { property in
51+
(property.inferredType.description, property.inferredType)
52+
}
53+
let dictionary = Dictionary(
54+
allInferredTypes,
55+
uniquingKeysWith: { first, _ in first }
56+
)
57+
return dictionary.values.sorted { lhs, rhs in
58+
lhs.description < rhs.description
59+
}
60+
}
61+
4962
public func withInferredType(like someType: TypeSyntax) -> Self {
5063
.init(filter { $0.inferredType.isLike(someType) })
5164
}

Sources/PrincipleMacros/Syntax/Extensions/TypeSyntax.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SwiftSyntax
1111
extension TypeSyntax {
1212

1313
public func isLike(_ other: TypeSyntax) -> Bool {
14-
trimmedDescription == other.trimmedDescription
14+
standardized.trimmedDescription == other.standardized.trimmedDescription
1515
}
1616
}
1717

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
//
2+
// PropertiesListTests.swift
3+
// PrincipleMacros
4+
//
5+
// Created by Kamil Strzelecki on 15/05/2025.
6+
// Copyright © 2025 Kamil Strzelecki. All rights reserved.
7+
//
8+
9+
@testable import PrincipleMacros
10+
import SwiftSyntaxMacroExpansion
11+
import Testing
12+
13+
internal struct PropertiesListTests {
14+
15+
private let list: PropertiesList
16+
17+
init() throws {
18+
let decl: DeclSyntax = """
19+
class Test {
20+
21+
let letProp: Int? = 0
22+
var varProp = ""
23+
lazy var lazyVarProp = Optional<Int>.none
24+
25+
static let staticLetProp = String(data: Data(), encoding: .utf8)
26+
static var staticVarProp = Int?.some(0)
27+
class var classVarProp: String { "" }
28+
29+
var computedProp: Int? { 0 }
30+
var computedSettableProp: Optional<Int> {
31+
get { 0 }
32+
set {}
33+
}
34+
}
35+
"""
36+
37+
let classDecl = try #require(ClassDeclSyntax(decl))
38+
let context = BasicMacroExpansionContext()
39+
self.list = PropertiesParser.parse(memberBlock: classDecl.memberBlock, in: context)
40+
}
41+
42+
@Test
43+
func testImmutable() throws {
44+
#expect(
45+
list.immutable.map(\.trimmedName.description) == [
46+
"letProp",
47+
"staticLetProp",
48+
"classVarProp",
49+
"computedProp"
50+
]
51+
)
52+
}
53+
54+
@Test
55+
func testMutable() throws {
56+
#expect(
57+
list.mutable.map(\.trimmedName.description) == [
58+
"varProp",
59+
"lazyVarProp",
60+
"staticVarProp",
61+
"computedSettableProp"
62+
]
63+
)
64+
}
65+
66+
@Test
67+
func testInstance() throws {
68+
#expect(
69+
list.instance.map(\.trimmedName.description) == [
70+
"letProp",
71+
"varProp",
72+
"lazyVarProp",
73+
"computedProp",
74+
"computedSettableProp"
75+
]
76+
)
77+
}
78+
79+
@Test
80+
func testType() throws {
81+
#expect(
82+
list.type.map(\.trimmedName.description) == [
83+
"staticLetProp",
84+
"staticVarProp",
85+
"classVarProp"
86+
]
87+
)
88+
}
89+
90+
@Test
91+
func testStored() throws {
92+
#expect(
93+
list.stored.map(\.trimmedName.description) == [
94+
"letProp",
95+
"varProp",
96+
"lazyVarProp",
97+
"staticLetProp",
98+
"staticVarProp"
99+
]
100+
)
101+
}
102+
103+
@Test
104+
func testComputed() throws {
105+
#expect(
106+
list.computed.map(\.trimmedName.description) == [
107+
"classVarProp",
108+
"computedProp",
109+
"computedSettableProp"
110+
]
111+
)
112+
}
113+
114+
@Test
115+
func testUniqueInferredTypes() throws {
116+
#expect(
117+
list.uniqueInferredTypes.map(\.description) == [
118+
"Optional<Int>",
119+
"String"
120+
]
121+
)
122+
}
123+
124+
@Test
125+
func testWithInferredType() throws {
126+
#expect(
127+
list.withInferredType(like: "Int?").map(\.trimmedName.description) == [
128+
"letProp",
129+
"lazyVarProp",
130+
"staticVarProp",
131+
"computedProp",
132+
"computedSettableProp"
133+
]
134+
)
135+
#expect(
136+
list.withInferredType(like: "String").map(\.trimmedName.description) == [
137+
"varProp",
138+
"staticLetProp",
139+
"classVarProp"
140+
]
141+
)
142+
}
143+
}

0 commit comments

Comments
 (0)