-
-
Notifications
You must be signed in to change notification settings - Fork 121
/
DefaultsSetTests.swift
60 lines (51 loc) · 1.65 KB
/
DefaultsSetTests.swift
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
import Foundation
import Testing
import Defaults
private let suite_ = createSuite()
private let fixtureSet = Set(1...5)
extension Defaults.Keys {
fileprivate static let set = Key<Set<Int>>("setInt", default: fixtureSet, suite: suite_)
}
@Suite(.serialized)
final class DefaultsSetTests {
init() {
Defaults.removeAll(suite: suite_)
}
deinit {
Defaults.removeAll(suite: suite_)
}
@Test
func testKey() {
let key = Defaults.Key<Set<Int>>("independentSetKey", default: fixtureSet, suite: suite_)
#expect(Defaults[key].count == fixtureSet.count)
Defaults[key].insert(6)
#expect(Defaults[key] == Set(1...6))
}
@Test
func testOptionalKey() {
let key = Defaults.Key<Set<Int>?>("independentSetOptionalKey", suite: suite_) // swiftlint:disable:this discouraged_optional_collection
#expect(Defaults[key] == nil)
Defaults[key] = fixtureSet
#expect(Defaults[key]?.count == fixtureSet.count)
Defaults[key]?.insert(6)
#expect(Defaults[key] == Set(1...6))
}
@Test
func testArrayKey() {
let key = Defaults.Key<[Set<Int>]>("independentSetArrayKey", default: [fixtureSet], suite: suite_)
#expect(Defaults[key][0].count == fixtureSet.count)
Defaults[key][0].insert(6)
#expect(Defaults[key][0] == Set(1...6))
Defaults[key].append(Set(1...4))
#expect(Defaults[key][1] == Set(1...4))
}
@Test
func testDictionaryKey() {
let key = Defaults.Key<[String: Set<Int>]>("independentSetArrayKey", default: ["0": fixtureSet], suite: suite_)
#expect(Defaults[key]["0"]?.count == fixtureSet.count)
Defaults[key]["0"]?.insert(6)
#expect(Defaults[key]["0"] == Set(1...6))
Defaults[key]["1"] = Set(1...4)
#expect(Defaults[key]["1"] == Set(1...4))
}
}