| 1 | using Xunit; |
| 2 | |
| 3 | namespace CascadeIDE.Tests; |
| 4 | |
| 5 | public sealed class ControlFlowSubgraphTextPresenterTests |
| 6 | { |
| 7 | [Fact] |
| 8 | public void Render_LinearGraph_ReturnsSingleLineChain() |
| 9 | { |
| 10 | const string json = """ |
| 11 | { |
| 12 | "mode": "subgraph", |
| 13 | "anchor_path": "D:\\w\\Demo.cs", |
| 14 | "nodes": [ |
| 15 | { "id": "n0", "kind": "anchor", "label": "Demo.cs", "path": "D:\\w\\Demo.cs", "relative_path": "", "rationale": "method A" }, |
| 16 | { "id": "n1", "kind": "call_step", "label": "B", "path": "D:\\w\\Demo.cs", "relative_path": "", "rationale": "call B" }, |
| 17 | { "id": "n2", "kind": "call_step", "label": "C", "path": "D:\\w\\Demo.cs", "relative_path": "", "rationale": "call C" } |
| 18 | ], |
| 19 | "edges": [ |
| 20 | { "from_id": "n0", "to_id": "n1", "kind": "Call", "related_kind": "Call" }, |
| 21 | { "from_id": "n1", "to_id": "n2", "kind": "Call", "related_kind": "Call" } |
| 22 | ] |
| 23 | } |
| 24 | """; |
| 25 | |
| 26 | var text = ControlFlowSubgraphTextPresenter.Render(json); |
| 27 | Assert.Equal("A -(Call)-> B -(Call)-> C", text); |
| 28 | } |
| 29 | |
| 30 | [Fact] |
| 31 | public void Render_BranchedGraph_UsesTreeShape() |
| 32 | { |
| 33 | const string json = """ |
| 34 | { |
| 35 | "mode": "subgraph", |
| 36 | "anchor_path": "D:\\w\\Demo.cs", |
| 37 | "nodes": [ |
| 38 | { "id": "n0", "kind": "anchor", "label": "Demo.cs", "path": "D:\\w\\Demo.cs", "relative_path": "", "rationale": "method A" }, |
| 39 | { "id": "n1", "kind": "condition_step", "label": "IF", "path": "D:\\w\\Demo.cs", "relative_path": "", "rationale": "if condition" }, |
| 40 | { "id": "n2", "kind": "exit_step", "label": "RET", "path": "D:\\w\\Demo.cs", "relative_path": "", "rationale": "return" }, |
| 41 | { "id": "n3", "kind": "call_step", "label": "DoWork", "path": "D:\\w\\Demo.cs", "relative_path": "", "rationale": "call DoWork" } |
| 42 | ], |
| 43 | "edges": [ |
| 44 | { "from_id": "n0", "to_id": "n1", "kind": "ConditionalCall", "related_kind": "ConditionalCall" }, |
| 45 | { "from_id": "n1", "to_id": "n2", "kind": "Exit", "related_kind": "Exit" }, |
| 46 | { "from_id": "n1", "to_id": "n3", "kind": "Merge", "related_kind": "Call" } |
| 47 | ] |
| 48 | } |
| 49 | """; |
| 50 | |
| 51 | var text = ControlFlowSubgraphTextPresenter.Render(json); |
| 52 | Assert.Contains("A", text, StringComparison.Ordinal); |
| 53 | Assert.Contains("|-- (Exit) R", text, StringComparison.Ordinal); |
| 54 | Assert.Contains("`-- (Merge) DoWork", text, StringComparison.Ordinal); |
| 55 | } |
| 56 | } |
| 57 | |