generated from wayfair-incubator/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added a method to MutatingCopyable to use a KeyPath instead of a closure * Added mutating copyable unit tests * grammar --------- Co-authored-by: Bill Dunay <wdunay@wayfair.com> Co-authored-by: Albert Bori <github@albertbori.com>
- Loading branch information
1 parent
ea8bae3
commit bb6249a
Showing
2 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// MutatingCopyableTests.swift | ||
// | ||
// | ||
// Created by Albert Bori on 12/6/23. | ||
// | ||
|
||
@testable import VSM | ||
import XCTest | ||
|
||
final class MutatingCopyableTests: XCTestCase { | ||
struct Subject: MutatingCopyable { | ||
var bar: String | ||
var baz: Bool | ||
} | ||
|
||
func testMutatingCopyableClosure() { | ||
let subject = Subject(bar: "old", baz: false) | ||
let result = subject.copy { | ||
$0.bar = "new" | ||
$0.baz = true | ||
} | ||
XCTAssertEqual(result.bar, "new") | ||
XCTAssertEqual(result.baz, true) | ||
} | ||
|
||
func testMutatingCopyableKeyPath() { | ||
let subject = Subject(bar: "old", baz: false) | ||
let result = subject | ||
.copy(mutatingPath: \.bar, value: "new") | ||
.copy(mutatingPath: \.baz, value: true) | ||
XCTAssertEqual(result.bar, "new") | ||
XCTAssertEqual(result.baz, true) | ||
} | ||
} |