Skip to content

Commit 5bce9ad

Browse files
committed
Cleanup. Tests: PrefixTextStyle & SuffixTextStyle
1 parent d72049e commit 5bce9ad

File tree

8 files changed

+119
-25
lines changed

8 files changed

+119
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ import SwiftUI
164164

165165
struct ContentView: View {
166166

167-
typealias Number = String // [Character]
167+
typealias Number = String // Array<Character>
168168

169169
//=------------------------------------------------------------------------=
170170

Sources/DiffableTextKit/Models/Snapshot.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// MARK: * Snapshot
1212
//*============================================================================*
1313

14-
/// A collection of characters, attributes and an optional anchor.
14+
/// A collection of characters, attributes and an optional selection.
1515
///
1616
/// ```
1717
/// |+|1|2|_|(|3|4|5|)|_|6|7|8|-|9|#|-|#|#|~

Sources/DiffableTextKit/Utilities/Slice.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//=----------------------------------------------------------------------------=
99

1010
//*============================================================================*
11-
// MARK: * Suffix [...]
11+
// MARK: * Slice [...]
1212
//*============================================================================*
1313

1414
extension BidirectionalCollection {

Tests/DiffableTextKitTests/Mock.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ import Foundation
1515
//*============================================================================*
1616

1717
struct Mock: DiffableTextStyle {
18-
typealias Value = Int
18+
typealias Value = String
1919

2020
//=------------------------------------------------------------------------=
2121
// MARK: State
2222
//=------------------------------------------------------------------------=
2323

2424
var locale: Locale
25+
26+
//=------------------------------------------------------------------------=
27+
// MARK: Initializers
28+
//=------------------------------------------------------------------------=
29+
30+
init(locale: Locale = .autoupdatingCurrent) { self.locale = locale }
2531

2632
//=------------------------------------------------------------------------=
2733
// MARK: Transformations
@@ -36,15 +42,15 @@ struct Mock: DiffableTextStyle {
3642
//=------------------------------------------------------------------------=
3743

3844
func format(_ value: Value, with cache: inout Void) -> String {
39-
fatalError()
45+
value
4046
}
4147

4248
func interpret(_ value: Value, with cache: inout Void) -> Commit<Value> {
43-
fatalError()
49+
Commit(value, Snapshot(value))
4450
}
4551

4652
func resolve(_ proposal: Proposal, with cache: inout Void) throws -> Commit<Value> {
47-
fatalError()
53+
interpret(proposal.merged().characters)
4854
}
4955
}
5056

Tests/DiffableTextKitTests/Models/Status.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ final class StatusTests: XCTestCase {
3131
//=------------------------------------------------------------------------=
3232

3333
func testMergeReplacesInequalValues() {
34-
var status = Status(en_US, 0, false)
35-
let changes = status.merge(Status(sv_SE, 1, true))
36-
let result = Status(sv_SE, 1, true)
34+
var status = Status(en_US, "0", false)
35+
let changes = status.merge(Status(sv_SE, "1", true))
36+
let result = Status(sv_SE, "1", true)
3737

3838
XCTAssertEqual(status, result)
3939
XCTAssertEqual(changes, [.style, .value, .focus])
@@ -43,8 +43,8 @@ final class StatusTests: XCTestCase {
4343
let en_US = en_US.equals(())
4444
let sv_SE = sv_SE.equals(())
4545

46-
var status0 = Status(en_US, 0, false)
47-
let status1 = Status(sv_SE, 1, true)
46+
var status0 = Status(en_US, "0", false)
47+
let status1 = Status(sv_SE, "1", true)
4848
let changes = status0.merge( status1)
4949

5050
XCTAssertEqual(status0, status1)
@@ -58,24 +58,24 @@ final class StatusTests: XCTestCase {
5858

5959
func testMemberWiseInequal() {
6060
XCTAssertEqual(
61-
Status(en_US, 0, false) .!=
62-
Status(en_US, 0, false), [])
61+
Status(en_US, "0", false) .!=
62+
Status(en_US, "0", false), [])
6363

6464
XCTAssertEqual(
65-
Status(en_US, 0, false) .!=
66-
Status(sv_SE, 0, false), [.style])
65+
Status(en_US, "0", false) .!=
66+
Status(sv_SE, "0", false), [.style])
6767

6868
XCTAssertEqual(
69-
Status(en_US, 0, false) .!=
70-
Status(en_US, 1, false), [.value])
69+
Status(en_US, "0", false) .!=
70+
Status(en_US, "1", false), [.value])
7171

7272
XCTAssertEqual(
73-
Status(en_US, 0, false) .!=
74-
Status(en_US, 0, true), [.focus])
73+
Status(en_US, "0", false) .!=
74+
Status(en_US, "0", true), [.focus])
7575

7676
XCTAssertEqual(
77-
Status(en_US, 0, false) .!=
78-
Status(sv_SE, 1, true), [.style, .value, .focus])
77+
Status(en_US, "0", false) .!=
78+
Status(sv_SE, "1", true), [.style, .value, .focus])
7979

8080
}
8181
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//=----------------------------------------------------------------------------=
2+
// This source file is part of the DiffableTextViews open source project.
3+
//
4+
// Copyright (c) 2022 Oscar Byström Ericsson
5+
// Licensed under Apache License, Version 2.0
6+
//
7+
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
8+
//=----------------------------------------------------------------------------=
9+
10+
#if DEBUG
11+
12+
@testable import DiffableTextKit
13+
14+
import XCTest
15+
16+
//*============================================================================*
17+
// MARK: * Prefix x Tests
18+
//*============================================================================*
19+
20+
final class PrefixTests: XCTestCase {
21+
22+
//=------------------------------------------------------------------------=
23+
// MARK: Assertions
24+
//=------------------------------------------------------------------------=
25+
26+
func OK(prefix: String, value: String, format: String) {
27+
let style = Mock().prefix(prefix); XCTAssertEqual(style.format(value), format)
28+
}
29+
30+
func OK(prefix: String, value: String, interpret: Commit<String>) {
31+
let style = Mock().prefix(prefix); XCTAssertEqual(style.interpret(value), interpret)
32+
}
33+
34+
//=------------------------------------------------------------------------=
35+
// MARK: Tests
36+
//=------------------------------------------------------------------------=
37+
38+
func test() {
39+
OK(prefix: "🇸🇪", value: "🇺🇸", format: "🇸🇪🇺🇸")
40+
OK(prefix: "🇸🇪", value: "🇺🇸", interpret: Commit("🇺🇸", Snapshot("🇸🇪", as: .phantom) + "🇺🇸"))
41+
}
42+
}
43+
44+
#endif
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//=----------------------------------------------------------------------------=
2+
// This source file is part of the DiffableTextViews open source project.
3+
//
4+
// Copyright (c) 2022 Oscar Byström Ericsson
5+
// Licensed under Apache License, Version 2.0
6+
//
7+
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
8+
//=----------------------------------------------------------------------------=
9+
10+
#if DEBUG
11+
12+
@testable import DiffableTextKit
13+
14+
import XCTest
15+
16+
//*============================================================================*
17+
// MARK: * Suffix x Tests
18+
//*============================================================================*
19+
20+
final class SuffixTests: XCTestCase {
21+
22+
//=------------------------------------------------------------------------=
23+
// MARK: Assertions
24+
//=------------------------------------------------------------------------=
25+
26+
func OK(value: String, suffix: String, format: String) {
27+
let style = Mock().suffix(suffix); XCTAssertEqual(style.format(value), format)
28+
}
29+
30+
func OK(value: String, suffix: String, interpret: Commit<String>) {
31+
let style = Mock().suffix(suffix); XCTAssertEqual(style.interpret(value), interpret)
32+
}
33+
34+
//=------------------------------------------------------------------------=
35+
// MARK: Tests
36+
//=------------------------------------------------------------------------=
37+
38+
func test() {
39+
OK(value: "🇸🇪", suffix: "🇺🇸", format: "🇸🇪🇺🇸")
40+
OK(value: "🇸🇪", suffix: "🇺🇸", interpret: Commit("🇸🇪", "🇸🇪" + Snapshot("🇺🇸", as: .phantom)))
41+
}
42+
}
43+
44+
#endif

Tests/DiffableTextKitTests/Utilities/Suffix.swift renamed to Tests/DiffableTextKitTests/Utilities/Slice.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
import XCTest
1515

1616
//*============================================================================*
17-
// MARK: * Suffix x Tests
17+
// MARK: * Slice x Tests
1818
//*============================================================================*
1919

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

2222
//=------------------------------------------------------------------------=
23-
// MARK: Tests x While
23+
// MARK: Tests x Suffix
2424
//=------------------------------------------------------------------------=
2525

2626
func testSuffixWhile() {

0 commit comments

Comments
 (0)