Skip to content

Commit 2fbfa34

Browse files
committed
Cleanup n' some tests.
1 parent f923f83 commit 2fbfa34

File tree

7 files changed

+49
-19
lines changed

7 files changed

+49
-19
lines changed

Sources/DiffableTextKit/Utilities/Info.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,36 @@ ExpressibleByStringInterpolation, ExpressibleByStringLiteral {
3939
#endif
4040
}
4141

42+
@inlinable @inline(__always) public init(stringLiteral content: String) {
43+
self.init([content])
44+
}
45+
4246
//=------------------------------------------------------------------------=
4347
// MARK: Initializers
4448
//=------------------------------------------------------------------------=
4549

46-
@inlinable @inline(__always) public init(stringLiteral content: String) {
47-
self.init([content])
50+
@inlinable @inline(__always) init(_ instance: @autoclosure () -> Self) {
51+
self = instance()
4852
}
49-
50-
@inlinable @inline(__always) public init(@Info _ info: () -> Self) {
51-
self.init(info())
53+
54+
@inlinable @inline(__always) public init(_ error: @autoclosure () -> any Error) {
55+
self.init([String(describing: error())])
56+
}
57+
58+
@inlinable @inline(__always) public init(_ instances: @autoclosure () -> [Self]) {
59+
self.init(instances().map(\.description))
5260
}
5361

5462
@inlinable @inline(__always) public init(_ transform: (inout Self) -> Void) {
5563
self.init({ var instance = Self(); transform(&instance); return instance }())
5664
}
5765

58-
@inlinable @inline(__always) public init(_ error: @autoclosure () -> any Error) {
59-
self.init([String(describing: error())])
60-
}
66+
//=------------------------------------------------------------------------=
67+
// MARK: Initializers
68+
//=------------------------------------------------------------------------=
6169

62-
@inlinable @inline(__always) public init(_ instances: @autoclosure () -> [Self]) {
63-
self.init(instances().map(\.description))
70+
@inlinable @inline(__always) public init(@Info _ instance: () -> Self) {
71+
self.init(instance())
6472
}
6573

6674
@inlinable @inline(__always) public static func buildBlock(_ instances: Self...) -> Self {

Tests/DiffableTextKitTests/Mock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct Mock: DiffableTextStyle {
5555
}
5656

5757
func resolve(_ proposal: Proposal, with cache: inout Void) throws -> Commit<Value> {
58-
interpret(proposal.merged().characters)
58+
interpret(proposal.lazy.merged().nonvirtuals())
5959
}
6060
}
6161

Tests/DiffableTextKitTests/Styles/Constant.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import XCTest
1717
// MARK: * Constant x Tests
1818
//*============================================================================*
1919

20-
final class ConstantTests: XCTestCase {
20+
final class ConstantTextStyleTests: XCTestCase {
2121

2222
//=------------------------------------------------------------------------=
2323
// MARK: Tests

Tests/DiffableTextKitTests/Styles/Equals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import XCTest
1717
// MARK: * Equals x Tests
1818
//*============================================================================*
1919

20-
final class EqualsTests: XCTestCase {
20+
final class EqualsTextStyleTests: XCTestCase {
2121

2222
//=------------------------------------------------------------------------=
2323
// MARK: Tests

Tests/DiffableTextKitTests/Styles/Normal.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import XCTest
1717
// MARK: * Normal x Tests
1818
//*============================================================================*
1919

20-
final class NormalTests: XCTestCase {
20+
final class NormalTextStyleTests: XCTestCase {
2121

2222
//=------------------------------------------------------------------------=
2323
// MARK: State
@@ -38,9 +38,9 @@ final class NormalTests: XCTestCase {
3838
}
3939

4040
func testResolve() {
41-
let base = Snapshot("13") + Snapshot("o(><)o", as: .phantom)
42-
let middle = base.index(base.startIndex, offsetBy: 1)
43-
let proposal = Proposal(base, with: "2", in: middle ..< middle)
41+
let snapshot = Snapshot("13") + Snapshot("o(><)o", as: .phantom)
42+
let position = snapshot.index(snapshot.startIndex, offsetBy: 01)
43+
let proposal = Proposal(snapshot, with: "2", in: position ..< position)
4444

4545
let resolved = try! normal.resolve(proposal)
4646

Tests/DiffableTextKitTests/Styles/Prefix.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import XCTest
1717
// MARK: * Prefix x Tests
1818
//*============================================================================*
1919

20-
final class PrefixTests: XCTestCase {
20+
final class PrefixTextStyleTests: XCTestCase {
2121

2222
typealias C = Offset<Character>
2323

@@ -34,6 +34,17 @@ final class PrefixTests: XCTestCase {
3434
Commit("🇺🇸", Snapshot("🇸🇪", as: .phantom) + "🇺🇸"))
3535
}
3636

37+
func testResolve() {
38+
let snapshot = Snapshot("")
39+
let proposal = Proposal(snapshot, with: "🇺🇸", in: snapshot.endIndex ..< snapshot.endIndex)
40+
41+
let mock = Mock().prefix("🇸🇪")
42+
let resolved = try! mock.resolve(proposal)
43+
44+
XCTAssertEqual(resolved.value, "🇺🇸")
45+
XCTAssertEqual(resolved.snapshot, Snapshot("🇸🇪", as: .phantom) + "🇺🇸")
46+
}
47+
3748
func testSelectionInBaseIsOffsetByPrefixSize() {
3849
let characters = "0123456789"
3950

Tests/DiffableTextKitTests/Styles/Suffix.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import XCTest
1717
// MARK: * Suffix x Tests
1818
//*============================================================================*
1919

20-
final class SuffixTests: XCTestCase {
20+
final class SuffixTextStyleTests: XCTestCase {
2121

2222
typealias C = Offset<Character>
2323

@@ -34,6 +34,17 @@ final class SuffixTests: XCTestCase {
3434
Commit("🇺🇸", "🇺🇸" + Snapshot("🇸🇪", as: .phantom)))
3535
}
3636

37+
func testResolve() {
38+
let snapshot = Snapshot("")
39+
let proposal = Proposal(snapshot, with: "🇺🇸", in: snapshot.endIndex ..< snapshot.endIndex)
40+
41+
let mock = Mock().suffix("🇸🇪")
42+
let resolved = try! mock.resolve(proposal)
43+
44+
XCTAssertEqual(resolved.value, "🇺🇸")
45+
XCTAssertEqual(resolved.snapshot, "🇺🇸" + Snapshot("🇸🇪", as: .phantom))
46+
}
47+
3748
func testSelectionIsSame() {
3849
let characters = "0123456789"
3950

0 commit comments

Comments
 (0)