Skip to content

Commit

Permalink
Introduce "nil writing" tests for optional SceneStorage types.
Browse files Browse the repository at this point in the history
  • Loading branch information
pd95 committed Mar 29, 2022
1 parent 59595b9 commit e0b72e6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions SwiftUIShim-Tests/SceneStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class SceneStorageTests: XCTestCase {
XCTAssertEqual(value.wrappedValue, newValue, "if set, the new value should be returned.")
XCTAssertEqual(store.value(forKey: key) as? Bool, newValue, "the new value should be persisted SceneStorageValues")

value.wrappedValue = nil
XCTAssertEqual(value.wrappedValue, nil, "if set to nil, the value should be cleared.")
XCTAssertEqual(store.value(forKey: key) as? Bool, nil, "the nil value should be persisted session store")

store.set(externallySetValue, forKey: key)
XCTAssertEqual(value.wrappedValue, externallySetValue,
"if modified externally, the new value should be returned")
Expand Down Expand Up @@ -127,6 +131,10 @@ class SceneStorageTests: XCTestCase {
XCTAssertEqual(value.wrappedValue, newValue, "if set, the new value should be returned.")
XCTAssertEqual(store.value(forKey: key) as? Int, newValue, "the new value should be persisted SceneStorageValues")

value.wrappedValue = nil
XCTAssertEqual(value.wrappedValue, nil, "if set to nil, the value should be cleared.")
XCTAssertEqual(store.value(forKey: key) as? Int, nil, "the nil value should be persisted session store")

store.set(externallySetValue, forKey: key)
XCTAssertEqual(value.wrappedValue, externallySetValue,
"if modified externally, the new value should be returned")
Expand Down Expand Up @@ -189,6 +197,10 @@ class SceneStorageTests: XCTestCase {
XCTAssertEqual(store.value(forKey: key) as? Double, newValue,
"the new value should be persisted SceneStorageValues")

value.wrappedValue = nil
XCTAssertEqual(value.wrappedValue, nil, "if set to nil, the value should be cleared.")
XCTAssertEqual(store.value(forKey: key) as? Double, nil, "the nil value should be persisted session store")

store.set(externallySetValue, forKey: key)
XCTAssertEqual(value.wrappedValue, externallySetValue,
"if modified externally, the new value should be returned")
Expand Down Expand Up @@ -251,6 +263,10 @@ class SceneStorageTests: XCTestCase {
XCTAssertEqual(store.value(forKey: key) as? String, newValue,
"the new value should be persisted SceneStorageValues")

value.wrappedValue = nil
XCTAssertEqual(value.wrappedValue, nil, "if set to nil, the value should be cleared.")
XCTAssertEqual(store.value(forKey: key) as? String, nil, "the nil value should be persisted session store")

store.set(externallySetValue, forKey: key)
XCTAssertEqual(value.wrappedValue, externallySetValue,
"if modified externally, the new value should be returned")
Expand Down Expand Up @@ -311,6 +327,10 @@ class SceneStorageTests: XCTestCase {
XCTAssertEqual(value.wrappedValue, newValue, "if set, the new value should be returned.")
XCTAssertEqual(store.value(forKey: key) as? URL, newValue, "the new value should be persisted SceneStorageValues")

value.wrappedValue = nil
XCTAssertEqual(value.wrappedValue, nil, "if set to nil, the value should be cleared.")
XCTAssertEqual(store.value(forKey: key) as? URL, nil, "the nil value should be persisted session store")

store.set(externallySetValue as Any, forKey: key)
XCTAssertEqual(value.wrappedValue, externallySetValue,
"if modified externally, the new value should be returned")
Expand Down Expand Up @@ -371,6 +391,10 @@ class SceneStorageTests: XCTestCase {
XCTAssertEqual(value.wrappedValue, newValue, "if set, the new value should be returned.")
XCTAssertEqual(store.value(forKey: key) as? Data, newValue, "the new value should be persisted SceneStorageValues")

value.wrappedValue = nil
XCTAssertEqual(value.wrappedValue, nil, "if set to nil, the value should be cleared.")
XCTAssertEqual(store.value(forKey: key) as? Data, nil, "the nil value should be persisted session store")

store.set(externallySetValue as Any, forKey: key)
XCTAssertEqual(value.wrappedValue, externallySetValue,
"if modified externally, the new value should be returned")
Expand Down Expand Up @@ -435,6 +459,11 @@ class SceneStorageTests: XCTestCase {
XCTAssertEqual(value.wrappedValue, newValue, "if set, the new value should be returned.")
XCTAssertEqual(store.value(forKey: key) as? MyIntEnum.RawValue, newValue.rawValue, "the new value should be persisted session store")

// FIXME: this is currently failing
// value.wrappedValue = nil
// XCTAssertEqual(value.wrappedValue, nil, "if set to nil, the value should be cleared.")
// XCTAssertEqual(store.value(forKey: key) as? MyIntEnum.RawValue, nil, "the nil value should be persisted session store")

store.set(externallySetValue.rawValue, forKey: key)
XCTAssertEqual(value.wrappedValue, externallySetValue,
"if modified externally, the new value should be returned")
Expand Down

0 comments on commit e0b72e6

Please sign in to comment.