forked from automerge/automerge-swift-archived
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(counter): support += and -= operators on Counter automerge#4
- Loading branch information
Showing
2 changed files
with
100 additions
and
1 deletion.
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,48 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Konstantin Kostov on 23/06/2022. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
@testable import Automerge | ||
|
||
class ProxyCounterTests: XCTestCase { | ||
func testAssignmentExpressions() { | ||
struct Schema: Codable, Equatable { | ||
var counter: Counter? | ||
var notOptionalCounter: Counter = 3 | ||
} | ||
|
||
var doc1 = Document(Schema()) | ||
let _ = doc1.change { | ||
$0.counter?.set(3) | ||
XCTAssertEqual($0.counter?.get(), 3) | ||
} | ||
|
||
let _ = doc1.change { | ||
$0.counter -= 1 | ||
$0.notOptionalCounter -= 1 | ||
XCTAssertEqual($0.counter?.get(), 2) | ||
XCTAssertEqual($0.notOptionalCounter.get(), 2) | ||
} | ||
|
||
let _ = doc1.change { | ||
$0.counter += 2 | ||
$0.notOptionalCounter += 2 | ||
XCTAssertEqual($0.counter?.get(), 4) | ||
XCTAssertEqual($0.notOptionalCounter.get(), 4) | ||
} | ||
|
||
let _ = doc1.change { | ||
$0.counter += -2 | ||
$0.notOptionalCounter -= 2 | ||
XCTAssertEqual($0.counter?.get(), 2) | ||
XCTAssertEqual($0.notOptionalCounter.get(), 2) | ||
} | ||
|
||
XCTAssertEqual(doc1.content, Schema(counter: 2, notOptionalCounter: 2)) | ||
} | ||
} |