Skip to content

Commit

Permalink
annotating docs, verifying change counts increment
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed Jul 9, 2023
1 parent b4f508f commit 0ddc9b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Sources/Automerge/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ public class Document: @unchecked Sendable {
}

/// Returns a set of change hashes that represent the current state of the document.
///
/// The number of change hashes returned represents the number of concurrent changes the document tracks.
public func heads() -> Set<ChangeHash> {
queue.sync {
Set(self.doc.wrapErrors { $0.heads().map { ChangeHash(bytes: $0) } })
Expand Down
16 changes: 13 additions & 3 deletions Tests/AutomergeTests/TestHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@ class HistoryTests: XCTestCase {
try! doc.put(obj: ObjId.ROOT, key: "key", value: .String("two"))
XCTAssertEqual(doc.changes().count, 2)

try! doc.put(obj: ObjId.ROOT, key: "key", value: .String("three"))
XCTAssertEqual(doc.changes().count, 3)

let replicaDoc = doc.fork()
XCTAssertEqual(doc.heads(), replicaDoc.heads())
XCTAssertEqual(doc.changes(), replicaDoc.changes())

try! doc.put(obj: ObjId.ROOT, key: "key", value: .String("three"))
XCTAssertEqual(doc.changes().count, 3)
XCTAssertEqual(replicaDoc.changes().count, 2)

try doc.put(obj: ObjId.ROOT, key: "newkey", value: .String("beta"))
try replicaDoc.put(obj: ObjId.ROOT, key: "newkey", value: .String("alpha"))
XCTAssertEqual(doc.changes().count, 4)
XCTAssertEqual(replicaDoc.changes().count, 3)

try doc.merge(other: replicaDoc)
XCTAssertEqual(doc.changes().count, 5)
XCTAssertEqual(replicaDoc.changes().count, 3)
}
}

0 comments on commit 0ddc9b7

Please sign in to comment.