diff --git a/Sources/TCADiagramLib/Internal/Parser.swift b/Sources/TCADiagramLib/Internal/Parser.swift index 3120bed..c3eedf1 100644 --- a/Sources/TCADiagramLib/Internal/Parser.swift +++ b/Sources/TCADiagramLib/Internal/Parser.swift @@ -71,7 +71,11 @@ extension SourceFileSyntax { private func predicateReducerProtocol(_ node: Syntax) throws -> String? { if let node = StructDeclSyntax(node), - node.inheritanceClause?.tokens(viewMode: .fixedUp).contains(where: { $0.tokenKind == .identifier("ReducerProtocol") }) == true + node.inheritanceClause?.tokens(viewMode: .fixedUp) + .contains(where: { + $0.tokenKind == .identifier("ReducerProtocol") + || $0.tokenKind == .identifier("Reducer") + }) == true { return node.identifier.text } diff --git a/Tests/TCADiagramLibTests/DiagramTests.swift b/Tests/TCADiagramLibTests/DiagramTests.swift index a26c1c1..0aa0094 100644 --- a/Tests/TCADiagramLibTests/DiagramTests.swift +++ b/Tests/TCADiagramLibTests/DiagramTests.swift @@ -45,4 +45,26 @@ final class DiagramTests: XCTestCase { """ XCTAssertEqual(result, expected) } + + func testReducerExample() throws { + let result = try Diagram.dump(reducerSampleSource) + let expected = """ + ```mermaid + %%{ init : { "theme" : "default", "flowchart" : { "curve" : "monotoneY" }}}%% + graph LR + SelfLessonDetail -- optional --> DoubleIfLetChild + SelfLessonDetail ---> DoubleScopeChild + SelfLessonDetail ---> Payment + SelfLessonDetail -- optional --> SantaWeb + SelfLessonDetail -- optional --> SelfLessonDetailFilter + + DoubleIfLetChild(DoubleIfLetChild: 1) + DoubleScopeChild(DoubleScopeChild: 1) + Payment(Payment: 1) + SantaWeb(SantaWeb: 1) + SelfLessonDetailFilter(SelfLessonDetailFilter: 1) + ``` + """ + XCTAssertEqual(result, expected) + } } diff --git a/Tests/TCADiagramLibTests/Resources/Sources.swift b/Tests/TCADiagramLibTests/Resources/Sources.swift index ced5224..f1f0741 100644 --- a/Tests/TCADiagramLibTests/Resources/Sources.swift +++ b/Tests/TCADiagramLibTests/Resources/Sources.swift @@ -137,3 +137,66 @@ let reducerProtocolSampleSource: [String] = [ } """ ] + +let reducerSampleSource: [String] = [ + """ + public struct SelfLessonDetail: Reducer { + @Dependency(\\.environmentSelfLessonDetail) private var environment + + public init() {} + + public var body: some Reducer { + BindingReducer() + Scope(state: \\State.payment, action: /Action.payment) { + Payment() + } + + Scope(state: \\.subState, action: .self) { + Scope( + state: /State.SubState.promotionWeb, + action: /Action.promotionWeb + ) { + DoubleScopeChild() + } + } + + Reduce { state, action in + switch action { + case default: + return .none + } + } + .ifLet(\\.filter, action: /Action.filter) { + SelfLessonDetailFilter() + } + .ifLet(\\.selection, action: /Action.web) { + SantaWeb() + } + .ifLet(\\SelfLessonDetail.State.selection, action: /SelfLessonDetail.Action.webView) { + EmptyReducer() + .ifLet(\\Identified.value, action: .self) { + DoubleIfLetChild() + } + } + } + } + """, + """ + extension SelfLessonDetail { + public enum Action: Equatable { + } + } + extension Payment { + public enum Action: Equatable { + } + } + extension SantaWeb { + public enum Action: Equatable { + } + } + extension SelfLessonDetailFilter { + public enum Action: Equatable { + } + } + """ +]