2021-05-16 20:21:17 +08:00
|
|
|
import Foundation
|
2024-09-26 05:17:26 +08:00
|
|
|
import Testing
|
2021-05-16 20:21:17 +08:00
|
|
|
import Defaults
|
2024-09-26 05:17:26 +08:00
|
|
|
|
|
|
|
private let suite_ = createSuite()
|
2021-05-16 20:21:17 +08:00
|
|
|
|
|
|
|
private let fixtureSet = Set(1...5)
|
|
|
|
|
|
|
|
extension Defaults.Keys {
|
2024-09-26 05:17:26 +08:00
|
|
|
fileprivate static let set = Key<Set<Int>>("setInt", default: fixtureSet, suite: suite_)
|
2021-05-16 20:21:17 +08:00
|
|
|
}
|
|
|
|
|
2024-09-26 05:17:26 +08:00
|
|
|
@Suite(.serialized)
|
|
|
|
final class DefaultsSetTests {
|
|
|
|
init() {
|
|
|
|
Defaults.removeAll(suite: suite_)
|
2021-05-16 20:21:17 +08:00
|
|
|
}
|
|
|
|
|
2024-09-26 05:17:26 +08:00
|
|
|
deinit {
|
|
|
|
Defaults.removeAll(suite: suite_)
|
2021-05-16 20:21:17 +08:00
|
|
|
}
|
|
|
|
|
2024-09-26 05:17:26 +08:00
|
|
|
@Test
|
2021-05-16 20:21:17 +08:00
|
|
|
func testKey() {
|
2024-09-26 05:17:26 +08:00
|
|
|
let key = Defaults.Key<Set<Int>>("independentSetKey", default: fixtureSet, suite: suite_)
|
|
|
|
#expect(Defaults[key].count == fixtureSet.count)
|
2021-05-16 20:21:17 +08:00
|
|
|
Defaults[key].insert(6)
|
2024-09-26 05:17:26 +08:00
|
|
|
#expect(Defaults[key] == Set(1...6))
|
2021-05-16 20:21:17 +08:00
|
|
|
}
|
|
|
|
|
2024-09-26 05:17:26 +08:00
|
|
|
@Test
|
2021-05-16 20:21:17 +08:00
|
|
|
func testOptionalKey() {
|
2024-09-26 05:17:26 +08:00
|
|
|
let key = Defaults.Key<Set<Int>?>("independentSetOptionalKey", suite: suite_) // swiftlint:disable:this discouraged_optional_collection
|
|
|
|
#expect(Defaults[key] == nil)
|
2021-05-16 20:21:17 +08:00
|
|
|
Defaults[key] = fixtureSet
|
2024-09-26 05:17:26 +08:00
|
|
|
#expect(Defaults[key]?.count == fixtureSet.count)
|
2021-05-16 20:21:17 +08:00
|
|
|
Defaults[key]?.insert(6)
|
2024-09-26 05:17:26 +08:00
|
|
|
#expect(Defaults[key] == Set(1...6))
|
2021-05-16 20:21:17 +08:00
|
|
|
}
|
|
|
|
|
2024-09-26 05:17:26 +08:00
|
|
|
@Test
|
2021-05-16 20:21:17 +08:00
|
|
|
func testArrayKey() {
|
2024-09-26 05:17:26 +08:00
|
|
|
let key = Defaults.Key<[Set<Int>]>("independentSetArrayKey", default: [fixtureSet], suite: suite_)
|
|
|
|
#expect(Defaults[key][0].count == fixtureSet.count)
|
2021-05-16 20:21:17 +08:00
|
|
|
Defaults[key][0].insert(6)
|
2024-09-26 05:17:26 +08:00
|
|
|
#expect(Defaults[key][0] == Set(1...6))
|
2021-05-16 20:21:17 +08:00
|
|
|
Defaults[key].append(Set(1...4))
|
2024-09-26 05:17:26 +08:00
|
|
|
#expect(Defaults[key][1] == Set(1...4))
|
2021-05-16 20:21:17 +08:00
|
|
|
}
|
|
|
|
|
2024-09-26 05:17:26 +08:00
|
|
|
@Test
|
2021-05-16 20:21:17 +08:00
|
|
|
func testDictionaryKey() {
|
2024-09-26 05:17:26 +08:00
|
|
|
let key = Defaults.Key<[String: Set<Int>]>("independentSetArrayKey", default: ["0": fixtureSet], suite: suite_)
|
|
|
|
#expect(Defaults[key]["0"]?.count == fixtureSet.count)
|
2021-05-16 20:21:17 +08:00
|
|
|
Defaults[key]["0"]?.insert(6)
|
2024-09-26 05:17:26 +08:00
|
|
|
#expect(Defaults[key]["0"] == Set(1...6))
|
2021-05-16 20:21:17 +08:00
|
|
|
Defaults[key]["1"] = Set(1...4)
|
2024-09-26 05:17:26 +08:00
|
|
|
#expect(Defaults[key]["1"] == Set(1...4))
|
2021-05-16 20:21:17 +08:00
|
|
|
}
|
|
|
|
}
|