Skip to content

Commit c68fe54

Browse files
committed
Cleanup.
1 parent e4708c9 commit c68fe54

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

Sources/DiffableTextKit/Models/Proposal.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,15 @@ public struct Proposal {
6363

6464
@inlinable init(_ proposal: Proposal) { self.proposal = proposal }
6565

66-
//=--------------------------------------------------------------------=
67-
// MARK: Accessors
68-
//=--------------------------------------------------------------------=
69-
70-
@inlinable public var base: Snapshot { proposal.base }
71-
72-
@inlinable public var replacement: Snapshot { proposal.replacement }
73-
74-
@inlinable public var range: Range<Snapshot.Index> { proposal.range }
75-
7666
//=--------------------------------------------------------------------=
7767
// MARK: Utilities
7868
//=--------------------------------------------------------------------=
7969

8070
/// Returns a lazy snapshot with the proposed change applied to it.
81-
@inlinable public func merged() -> LazySequence<FlattenSequence<[Snapshot.SubSequence]>> {
82-
[base[..<range.lowerBound], replacement[...], base[range.upperBound...]].lazy.joined()
71+
@inlinable public func merged() -> LazySequence<FlattenSequence<[Slice<Snapshot>]>> {[
72+
proposal.base[..<proposal.range.lowerBound],
73+
proposal.replacement[...], /*-------------*/
74+
proposal.base[proposal.range.upperBound...]].lazy.joined()
8375
}
8476
}
8577
}

Tests/DiffableTextKitTests/Models/Proposal.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,26 @@ import XCTest
1818
//*============================================================================*
1919

2020
final class ProposalTests: XCTestCase {
21-
typealias C = Offset<Character>
22-
21+
2322
//=------------------------------------------------------------------------=
2423
// MARK: Tests
2524
//=------------------------------------------------------------------------=
2625

2726
func testMerged() {
2827
let snapshot = Snapshot("AxxxE")
2928
let replacement = Snapshot( "BCD" )
30-
let range = snapshot.indices(at: C(1) ..< 4)
29+
let range = snapshot.indices(at: Offset<Character>(1) ..< 4)
3130
let proposal = Proposal(snapshot, with: replacement, in: range)
3231
XCTAssertEqual(proposal.merged(), "ABCDE")
3332
}
33+
34+
func testLazyMerged() {
35+
let snapshot = Snapshot("AxxxE")
36+
let replacement = Snapshot( "BCD" )
37+
let range = snapshot.indices(at: Offset<Character>(1) ..< 4)
38+
let proposal = Proposal(snapshot, with: replacement, in: range)
39+
XCTAssertEqual(Snapshot(proposal.lazy.merged()), "ABCDE")
40+
}
3441
}
3542

3643
#endif

Tests/DiffableTextKitTests/Models/Snapshot.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ final class SnapshotTests: XCTestCase {
9191
snapshot.append(Symbol(" "))
9292
let index = snapshot.endIndex;snapshot.select(index)
9393
snapshot.append(Symbol(" "))
94-
9594
XCTAssertEqual(snapshot.selection, Selection(index))
9695
}
9796

@@ -183,7 +182,6 @@ final class SnapshotTests: XCTestCase {
183182

184183
func testNumberOfAttributesMustEqualNumberOfJointCharacters() {
185184
snapshot = Snapshot("🇸🇪🇺🇸".unicodeScalars.map(Character.init))
186-
187185
XCTAssertEqual(snapshot.characters.count, 2)
188186
XCTAssertEqual(snapshot.attributes.count, 4)
189187
Assert("🇸🇪🇺🇸", [.content, .content, .content, .content])

0 commit comments

Comments
 (0)