-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add propertylist test code and complete some missing part (#16)
* Add propertylist test code and complete some missing part * Update compatibility_tests config file
- Loading branch information
Showing
11 changed files
with
216 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Sources/OpenSwiftUI/DataAndStorage/Internal/Property/Unmanaged+Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Unmanaged+Extension.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2024/1/4. | ||
// Lastest Version: iOS 15.5 | ||
// Status: Complete | ||
|
||
extension Unmanaged { | ||
func map<A: AnyObject>(_ transform: (Instance) throws -> A) rethrows -> Unmanaged<A> { | ||
try _withUnsafeGuaranteedRef { try .passUnretained(transform($0)) } | ||
} | ||
|
||
func map<A: AnyObject>(_ transform: (Instance) throws -> A?) rethrows -> Unmanaged<A>? { | ||
try _withUnsafeGuaranteedRef { try transform($0).map { .passUnretained($0) } } | ||
} | ||
|
||
func flatMap<A>(_ transform: (Instance) throws -> A) rethrows -> A { | ||
try _withUnsafeGuaranteedRef { try transform($0) } | ||
} | ||
|
||
static func == (lhs: Unmanaged, rhs: Unmanaged) -> Bool { | ||
lhs.toOpaque() == rhs.toOpaque() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
Tests/OpenSwiftUICompatibilityTests/EnvironmentValuesTest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// EnvironmentValuesTest.swift | ||
// | ||
// | ||
// Created by Kyle on 2023/11/21. | ||
// | ||
|
||
#if OPENSWIFTUI_COMPATIBILITY_TEST | ||
import SwiftUI | ||
#else | ||
import OpenSwiftUI | ||
#endif | ||
import Testing | ||
|
||
struct EnvironmentValuesTest { | ||
struct BoolKey: EnvironmentKey { | ||
fileprivate static var name: String { "EnvironmentPropertyKey<BoolKey>" } | ||
|
||
static let defaultValue = false | ||
} | ||
|
||
struct IntKey: EnvironmentKey { | ||
fileprivate static var name: String { "EnvironmentPropertyKey<IntKey>" } | ||
|
||
static let defaultValue = 0 | ||
} | ||
|
||
@Test | ||
func descriptionWithoutTracker() throws { | ||
#if os(macOS) && OPENSWIFTUI_COMPATIBILITY_TEST | ||
// FIXME: The env.description will always be "[]" on macOS 13 | ||
if #unavailable(macOS 14) { | ||
var env = EnvironmentValues() | ||
#expect(env.description == "[]") | ||
var bool = env[BoolKey.self] | ||
#expect(bool == BoolKey.defaultValue) | ||
#expect(env.description == "[]") | ||
|
||
env[BoolKey.self] = bool | ||
#expect(env.description == "[]") | ||
|
||
env[BoolKey.self] = !bool | ||
bool = env[BoolKey.self] | ||
#expect(bool == !BoolKey.defaultValue) | ||
#expect(env.description == "[]") | ||
|
||
let value = 1 | ||
env[IntKey.self] = value | ||
#expect(env.description == "[]") | ||
return | ||
} | ||
#endif | ||
var env = EnvironmentValues() | ||
#expect(env.description == "[]") | ||
|
||
var bool = env[BoolKey.self] | ||
#expect(bool == BoolKey.defaultValue) | ||
#expect(env.description == "[]") | ||
|
||
env[BoolKey.self] = bool | ||
#expect(env.description == "[\(BoolKey.name) = \(bool)]") | ||
|
||
env[BoolKey.self] = !bool | ||
bool = env[BoolKey.self] | ||
#expect(bool == !BoolKey.defaultValue) | ||
#expect(env.description == "[\(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]") | ||
|
||
let value = 1 | ||
env[IntKey.self] = value | ||
#expect(env.description == "[\(IntKey.name) = \(value), \(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Scaffolding.swift | ||
// | ||
// | ||
// Created by Kyle on 2024/1/4. | ||
// | ||
|
||
import Testing | ||
import XCTest | ||
|
||
final class AllTests: XCTestCase { | ||
func testAll() async { | ||
await XCTestScaffold.runAllTests(hostedBy: self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters