From f965b832d215e9930484745d626c0c7ab8072218 Mon Sep 17 00:00:00 2001 From: Jaeyoung Yoon Date: Fri, 6 Oct 2023 12:26:39 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=AA=20Add=20reducer=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tests/TCADiagramLibTests/DiagramTests.swift | 22 +++++++ .../Resources/Sources.swift | 63 +++++++++++++++++++ 2 files changed, 85 insertions(+) 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 { + } + } + """ +] From 7748ff1ed904dcc6192a08168c9c7314e56305f8 Mon Sep 17 00:00:00 2001 From: Jaeyoung Yoon Date: Fri, 6 Oct 2023 12:26:52 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=91=94=20Parse=20reducer=20inheritanc?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/TCADiagramLib/Internal/Parser.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 }