-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPlaceholders.swift
More file actions
105 lines (83 loc) · 3.5 KB
/
Placeholders.swift
File metadata and controls
105 lines (83 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//=----------------------------------------------------------------------------=
// This source file is part of the DiffableTextViews open source project.
//
// Copyright (c) 2022 Oscar Byström Ericsson
// Licensed under Apache License, Version 2.0
//
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
//=----------------------------------------------------------------------------=
#if DEBUG
@testable import DiffableTextKitXPattern
import XCTest
//*============================================================================*
// MARK: * Placeholders x Tests
//*============================================================================*
final class PlaceholdersTests: XCTestCase {
typealias Placeholders = PatternTextPlaceholders
//=------------------------------------------------------------------------=
// MARK: State
//=------------------------------------------------------------------------=
lazy var none = Placeholders()
lazy var some = Placeholders(("#", \.isNumber))
lazy var many = Placeholders(["#": \.isNumber, "@": \.isLetter])
//=------------------------------------------------------------------------=
// MARK: Tests x Init
//=------------------------------------------------------------------------=
func testExpressibleByDictionaryLiteral() {
XCTAssertEqual(none, [:])
XCTAssertEqual(some, ["#": \.isNumber])
XCTAssertEqual(many, ["#": \.isNumber, "@": \.isLetter])
}
//=------------------------------------------------------------------------=
// MARK: Tests x Accessors
//=------------------------------------------------------------------------=
func testNoneSomeManySubscript() {
AssertSubscriptResults(none) {[
("#", "1", nil),
("#", "A", nil),
("@", "1", nil),
("@", "A", nil),
("_", "1", nil),
("_", "A", nil)]}
AssertSubscriptResults(some) {[
("#", "1", true ),
("#", "A", false),
("@", "1", nil),
("@", "A", nil),
("_", "1", nil),
("_", "A", nil)]}
AssertSubscriptResults(many) {[
("#", "1", true ),
("#", "A", false),
("@", "1", false),
("@", "A", true ),
("_", "1", nil),
("_", "A", nil)]}
}
//=------------------------------------------------------------------------=
// MARK: Tests x Utilities
//=------------------------------------------------------------------------=
func testNoneSomeManyEquation() {
XCTAssertEqual(none, none)
XCTAssertEqual(some, some)
XCTAssertEqual(many, many)
XCTAssertNotEqual(none, some)
XCTAssertNotEqual(none, many)
XCTAssertNotEqual(some, many)
XCTAssertNotEqual(
Placeholders(("A", { _ in true })),
Placeholders(("_", { _ in true })))
XCTAssertNotEqual(
Placeholders(["A": { _ in true }, "B": { _ in true }]),
Placeholders(["A": { _ in true }, "_": { _ in true }]))
}
//=------------------------------------------------------------------------=
// MARK: Assertions
//=------------------------------------------------------------------------=
func AssertSubscriptResults(_ instance: Placeholders, _ scenarios: () -> [(Character, Character, Bool?)]) {
for scenario in scenarios() {
XCTAssertEqual(instance[scenario.0]?(scenario.1), scenario.2)
}
}
}
#endif