Skip to content

Commit

Permalink
[core] MutatedCopy macro & function naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
VAndrJ committed Jul 3, 2024
1 parent f5062c8 commit 4c6de25
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Example:


```swift
@MutableCopy
@MutatedCopy
struct SomeStruct: Equatable {
let id = "const uuidstring ;)"
var intValue: Int
Expand All @@ -176,7 +176,7 @@ struct SomeStruct: Equatable {
}

extension SomeStruct {
func mutableCopy(configuring: (inout SomeStruct) throws -> Void) rethrows -> SomeStruct {
func mutatedCopy(configuring: (_ it: inout SomeStruct) throws -> Void) rethrows -> SomeStruct {
var mutableCopy = self
try configuring(&mutableCopy)

Expand All @@ -187,7 +187,7 @@ extension SomeStruct {
// usage

let exampleStruct = SomeStruct(parameter1: 0, parameter2: false)
let exampleStructModified = exampleStruct.mutableCopy {
let exampleStructModified = exampleStruct.mutatedCopy {
$0.intValue = 42
$0.boolValue = true
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/VACopyWith/VACopyWith.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@attached(extension, names: arbitrary)
public macro CopyWith() = #externalMacro(module: "VACopyWithMacros", type: "VACopyWithMacro")
@attached(extension, names: arbitrary)
public macro MutableCopy() = #externalMacro(module: "VACopyWithMacros", type: "VAMutableCopyMacro")
public macro MutatedCopy() = #externalMacro(module: "VACopyWithMacros", type: "VAMutatedCopyMacro")
4 changes: 2 additions & 2 deletions Sources/VACopyWithClient/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ assert(value2.copyWith(parameter1: [2, 3, 4]) == SomeStruct2(parameter1: [2, 3,
assert(value2.copyWith(parameter2: .value("new string")) == SomeStruct2(parameter2: "new string"))
assert(value2.copyWith(parameter2: .nil) == SomeStruct2(parameter2: nil))

@MutableCopy
@MutatedCopy
struct SomeStruct3: Equatable {
let id = "const uuidstring ;)"
var parameter1: Int
var parameter2: Bool
}

let value3 = SomeStruct3(parameter1: 0, parameter2: false)
assert(value3.mutableCopy {
assert(value3.mutatedCopy {
$0.parameter1 = 42
$0.parameter2 = true
} == SomeStruct3(parameter1: 42, parameter2: true))
6 changes: 3 additions & 3 deletions Sources/VACopyWithMacros/VACopyWithMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public struct VACopyWithMacro: ExtensionMacro {
}
}

public struct VAMutableCopyMacro: ExtensionMacro {
public struct VAMutatedCopyMacro: ExtensionMacro {

public static func expansion(
of node: AttributeSyntax,
Expand All @@ -117,7 +117,7 @@ public struct VAMutableCopyMacro: ExtensionMacro {
return [
ExtensionDeclSyntax(modifiers: decl.modifiers.accessModifier, extendedType: type) {
"""
func mutableCopy(configuring: (inout \(type)) throws -> Void) rethrows -> \(type) {
func mutatedCopy(configuring: (_ it: inout \(type)) throws -> Void) rethrows -> \(type) {
var mutableCopy = self
try configuring(&mutableCopy)
Expand All @@ -133,6 +133,6 @@ public struct VAMutableCopyMacro: ExtensionMacro {
struct VACopyWithPlugin: CompilerPlugin {
let providingMacros: [Macro.Type] = [
VACopyWithMacro.self,
VAMutableCopyMacro.self,
VAMutatedCopyMacro.self,
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import VACopyWithMacros

extension VACopyWithTests {

func test_mutableCopy_struct_extension() throws {
func test_mutated_struct_extension() throws {
assertMacroExpansion(
"""
@MutableCopy
@MutatedCopy
struct SomeStruct {
}
""",
Expand All @@ -30,10 +30,10 @@ extension VACopyWithTests {
)
}

func test_mutableCopy_struct_failure() throws {
func test_mutated_struct_failure() throws {
assertMacroExpansion(
"""
@MutableCopy
@MutatedCopy
class SomeStruct {
let (a, b): (Int, Int)
}
Expand All @@ -48,10 +48,10 @@ extension VACopyWithTests {
)
}

func test_mutableCopy_struct_let() throws {
func test_mutated_struct_let() throws {
assertMacroExpansion(
"""
@MutableCopy
@MutatedCopy
struct SomeStruct {
let a: Int
}
Expand All @@ -65,10 +65,10 @@ extension VACopyWithTests {
)
}

func test_mutableCopy_struct_var() throws {
func test_mutated_struct_var() throws {
assertMacroExpansion(
"""
@MutableCopy
@MutatedCopy
struct SomeStruct {
var a: Int
}
Expand All @@ -79,7 +79,7 @@ extension VACopyWithTests {
}
extension SomeStruct {
func mutableCopy(configuring: (inout SomeStruct) throws -> Void) rethrows -> SomeStruct {
func mutatedCopy(configuring: (_ it: inout SomeStruct) throws -> Void) rethrows -> SomeStruct {
var mutableCopy = self
try configuring(&mutableCopy)
Expand Down
2 changes: 1 addition & 1 deletion Tests/VACopyWithTests/VACopyWithTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import VACopyWithMacros

let testMacros: [String: Macro.Type] = [
"CopyWith": VACopyWithMacro.self,
"MutableCopy": VAMutableCopyMacro.self,
"MutatedCopy": VAMutatedCopyMacro.self,
]
#endif

Expand Down

0 comments on commit 4c6de25

Please sign in to comment.