| 1 | using CascadeIDE.Cockpit.Channels.TraceFlow; |
| 2 | using CascadeIDE.Cockpit.Graph; |
| 3 | using CascadeIDE.Services; |
| 4 | using Xunit; |
| 5 | |
| 6 | namespace CascadeIDE.Tests; |
| 7 | |
| 8 | public sealed class CodeFlowTraceChannelTests |
| 9 | { |
| 10 | [Fact] |
| 11 | public void Build_PrefersNonExitBranch() |
| 12 | { |
| 13 | var doc = new GraphDocument |
| 14 | { |
| 15 | AnchorPath = @"D:\w\A.cs", |
| 16 | Nodes = |
| 17 | [ |
| 18 | Node("n0", "anchor"), |
| 19 | Node("n1", "condition_step"), |
| 20 | Node("n2", "exit_step"), |
| 21 | Node("n3", "call_step") |
| 22 | ], |
| 23 | Edges = |
| 24 | [ |
| 25 | Edge("n0", "n1", "ConditionalCall"), |
| 26 | Edge("n1", "n2", "Exit"), |
| 27 | Edge("n1", "n3", "Call") |
| 28 | ] |
| 29 | }; |
| 30 | |
| 31 | var channel = new CodeFlowTraceChannel(); |
| 32 | var snapshot = channel.Build(new TraceFlowChannelContext(doc, 0, "")); |
| 33 | |
| 34 | Assert.Contains("n0", snapshot.HighlightedNodeIds); |
| 35 | Assert.Contains("n1", snapshot.HighlightedNodeIds); |
| 36 | Assert.Contains("n3", snapshot.HighlightedNodeIds); |
| 37 | Assert.Contains("n0->n1", snapshot.HighlightedEdgeKeys); |
| 38 | Assert.Contains("n1->n3", snapshot.HighlightedEdgeKeys); |
| 39 | Assert.DoesNotContain("n1->n2", snapshot.HighlightedEdgeKeys); |
| 40 | } |
| 41 | |
| 42 | private static GraphNode Node(string id, string kind) => new() |
| 43 | { |
| 44 | Id = id, |
| 45 | Path = @"D:\w\A.cs", |
| 46 | Kind = kind, |
| 47 | Label = id |
| 48 | }; |
| 49 | |
| 50 | private static GraphEdge Edge(string from, string to, string kind) => new() |
| 51 | { |
| 52 | FromId = from, |
| 53 | ToId = to, |
| 54 | Kind = kind, |
| 55 | RelationKind = kind |
| 56 | }; |
| 57 | } |
| 58 | |