Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Jul 11, 2024
1 parent 23ab6d9 commit 53f97ee
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 25 deletions.
121 changes: 98 additions & 23 deletions Sources/SwiftUINavigation/Internal/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,10 @@

public init<Case1: Sendable, Content1>(
_ enum: Binding<Enum>,
context issueContext: IssueContext = .issueContext(),
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column,
@ViewBuilder content: () -> CaseLet<Enum, Case1, Content1>
)
where
Expand All @@ -873,7 +876,11 @@
{
self.init(`enum`) {
content()
Default { _ExhaustivityCheckView<Enum>(issueContext: issueContext) }
Default {
_ExhaustivityCheckView<Enum>(
fileID: fileID, filePath: filePath, line: line, column: column
)
}
}
}

Expand Down Expand Up @@ -910,7 +917,10 @@

public init<Case1: Sendable, Content1, Case2: Sendable, Content2>(
_ enum: Binding<Enum>,
context issueContext: IssueContext = .issueContext(),
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column,
@ViewBuilder content: () -> TupleView<
(
CaseLet<Enum, Case1, Content1>,
Expand All @@ -931,7 +941,11 @@
self.init(`enum`) {
content.value.0
content.value.1
Default { _ExhaustivityCheckView<Enum>(issueContext: issueContext) }
Default {
_ExhaustivityCheckView<Enum>(
fileID: fileID, filePath: filePath, line: line, column: column
)
}
}
}

Expand Down Expand Up @@ -979,7 +993,10 @@

public init<Case1: Sendable, Content1, Case2: Sendable, Content2, Case3: Sendable, Content3>(
_ enum: Binding<Enum>,
context issueContext: IssueContext = .issueContext(),
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column,
@ViewBuilder content: () -> TupleView<
(
CaseLet<Enum, Case1, Content1>,
Expand All @@ -1005,7 +1022,11 @@
content.value.0
content.value.1
content.value.2
Default { _ExhaustivityCheckView<Enum>(issueContext: issueContext) }
Default {
_ExhaustivityCheckView<Enum>(
fileID: fileID, filePath: filePath, line: line, column: column
)
}
}
}

Expand Down Expand Up @@ -1065,7 +1086,10 @@
Case4: Sendable, Content4
>(
_ enum: Binding<Enum>,
context issueContext: IssueContext = .issueContext(),
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column,
@ViewBuilder content: () -> TupleView<
(
CaseLet<Enum, Case1, Content1>,
Expand Down Expand Up @@ -1096,7 +1120,11 @@
content.value.1
content.value.2
content.value.3
Default { _ExhaustivityCheckView<Enum>(issueContext: issueContext) }
Default {
_ExhaustivityCheckView<Enum>(
fileID: fileID, filePath: filePath, line: line, column: column
)
}
}
}

Expand Down Expand Up @@ -1164,7 +1192,10 @@
Case5: Sendable, Content5
>(
_ enum: Binding<Enum>,
context issueContext: IssueContext = .issueContext(),
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column,
@ViewBuilder content: () -> TupleView<
(
CaseLet<Enum, Case1, Content1>,
Expand Down Expand Up @@ -1200,7 +1231,11 @@
content.value.2
content.value.3
content.value.4
Default { _ExhaustivityCheckView<Enum>(issueContext: issueContext) }
Default {
_ExhaustivityCheckView<Enum>(
fileID: fileID, filePath: filePath, line: line, column: column
)
}
}
}

Expand Down Expand Up @@ -1276,7 +1311,10 @@
Case6: Sendable, Content6
>(
_ enum: Binding<Enum>,
context issueContext: IssueContext = .issueContext(),
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column,
@ViewBuilder content: () -> TupleView<
(
CaseLet<Enum, Case1, Content1>,
Expand Down Expand Up @@ -1317,7 +1355,11 @@
content.value.3
content.value.4
content.value.5
Default { _ExhaustivityCheckView<Enum>(issueContext: issueContext) }
Default {
_ExhaustivityCheckView<Enum>(
fileID: fileID, filePath: filePath, line: line, column: column
)
}
}
}

Expand Down Expand Up @@ -1401,7 +1443,10 @@
Case7: Sendable, Content7
>(
_ enum: Binding<Enum>,
context issueContext: IssueContext = .issueContext(),
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column,
@ViewBuilder content: () -> TupleView<
(
CaseLet<Enum, Case1, Content1>,
Expand Down Expand Up @@ -1447,7 +1492,11 @@
content.value.4
content.value.5
content.value.6
Default { _ExhaustivityCheckView<Enum>(issueContext: issueContext) }
Default {
_ExhaustivityCheckView<Enum>(
fileID: fileID, filePath: filePath, line: line, column: column
)
}
}
}

Expand Down Expand Up @@ -1539,7 +1588,10 @@
Case8: Sendable, Content8
>(
_ enum: Binding<Enum>,
context issueContext: IssueContext = .issueContext(),
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column,
@ViewBuilder content: () -> TupleView<
(
CaseLet<Enum, Case1, Content1>,
Expand Down Expand Up @@ -1590,7 +1642,11 @@
content.value.5
content.value.6
content.value.7
Default { _ExhaustivityCheckView<Enum>(issueContext: issueContext) }
Default {
_ExhaustivityCheckView<Enum>(
fileID: fileID, filePath: filePath, line: line, column: column
)
}
}
}

Expand Down Expand Up @@ -1690,7 +1746,10 @@
Case9: Sendable, Content9
>(
_ enum: Binding<Enum>,
context issueContext: IssueContext = .issueContext(),
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column,
@ViewBuilder content: () -> TupleView<
(
CaseLet<Enum, Case1, Content1>,
Expand Down Expand Up @@ -1746,24 +1805,32 @@
content.value.6
content.value.7
content.value.8
Default { _ExhaustivityCheckView<Enum>(issueContext: issueContext) }
Default {
_ExhaustivityCheckView<Enum>(
fileID: fileID, filePath: filePath, line: line, column: column
)
}
}
}
}

public struct _ExhaustivityCheckView<Enum>: View {
@EnvironmentObject private var `enum`: BindingObject<Enum>
let issueContext: IssueContext
let fileID: StaticString
let filePath: StaticString
let line: UInt
let column: UInt

public var body: some View {
#if DEBUG
let message = """
Warning: Switch.body@\(issueContext.fileID):\(issueContext.line)
Warning: Switch.body@\(fileID):\(line)
"Switch" did not handle "\(describeCase(self.enum.wrappedValue.wrappedValue))"
Make sure that you exhaustively provide a "CaseLet" view for each case in "\(Enum.self)", \
provide a "Default" view at the end of the "Switch", or use an "IfCaseLet" view instead.
Make sure that you exhaustively provide a "CaseLet" view for each case in \
"\(Enum.self)", provide a "Default" view at the end of the "Switch", or use an \
"IfCaseLet" view instead.
"""
VStack(spacing: 17) {
self.exclamation()
Expand All @@ -1775,7 +1842,15 @@
.foregroundColor(.white)
.padding()
.background(Color.red.edgesIgnoringSafeArea(.all))
.onAppear { reportIssue(message, context: issueContext) }
.onAppear {
reportIssue(
message,
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
}
#else
EmptyView()
#endif
Expand Down
4 changes: 4 additions & 0 deletions Tests/SwiftUINavigationTests/BindingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
case outOfStock(isOnBackOrder: Bool)
}

@MainActor
func testCaseLookup() throws {
@Binding var status: Status
_status = Binding(initialValue: .inStock(quantity: 1))
Expand All @@ -22,6 +23,7 @@
XCTAssertEqual(status, .inStock(quantity: 2))
}

@MainActor
func testCaseCannotReplaceOtherCase() throws {
@Binding var status: Status
_status = Binding(initialValue: .inStock(quantity: 1))
Expand All @@ -34,6 +36,7 @@
XCTAssertEqual(status, .outOfStock(isOnBackOrder: true))
}

@MainActor
func testDestinationCannotReplaceOtherDestination() throws {
#if os(iOS) || os(macOS)
try XCTSkipIf(ProcessInfo.processInfo.environment["CI"] != nil)
Expand All @@ -52,6 +55,7 @@
}

extension Binding {
@MainActor
fileprivate init(initialValue: Value) {
var value = initialValue
self.init(
Expand Down
3 changes: 1 addition & 2 deletions Tests/SwiftUINavigationTests/ButtonStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import XCTest

final class ButtonStateTests: XCTestCase {
@MainActor
func testAsyncAnimationWarning() async {
XCTExpectFailure {
$0.compactDescription == """
An animated action was performed asynchronously: …
failed - An animated action was performed asynchronously: …
Action:
ButtonStateAction.send(
Expand Down
2 changes: 2 additions & 0 deletions Tests/SwiftUINavigationTests/SwiftUINavigationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@testable import SwiftUINavigation

final class SwiftUINavigationTests: XCTestCase {
@MainActor
func testBindingUnwrap() throws {
var value: Int?
let binding = Binding(get: { value }, set: { value = $0 })
Expand All @@ -29,6 +30,7 @@
XCTAssertEqual(unwrapped.wrappedValue, 1729)
}

@MainActor
func testBindingCase() throws {
struct MyError: Error, Equatable {}
var value: Result<Int, MyError>? = nil
Expand Down

0 comments on commit 53f97ee

Please sign in to comment.