Forge
csharpdeeb25a2
1#nullable enable
2using CascadeIDE.Cockpit.Graph;
3using CascadeIDE.Features.WorkspaceNavigation.Application;
4using CascadeIDE.Models;
5using CascadeIDE.Services.SkiaInstruments;
6using Xunit;
7
8namespace CascadeIDE.Tests;
9
10public sealed class CodeNavigationMapControlFlowDeclutterTests
11{
12 [Fact]
13 public void TryTransform_Normal_CollapsesWhenFanOutAtLeastFour()
14 {
15 var doc = new GraphDocument
16 {
17 AnchorPath = @"D:\w\A.cs",
18 Nodes =
19 [
20 new GraphNode { Id = "h", Path = @"D:\w\A.cs", Kind = "condition_step", Label = "?" },
21 new GraphNode { Id = "a", Path = @"D:\w\A.cs", Kind = "call_step", Label = "1" },
22 new GraphNode { Id = "b", Path = @"D:\w\A.cs", Kind = "call_step", Label = "2" },
23 new GraphNode { Id = "c", Path = @"D:\w\A.cs", Kind = "call_step", Label = "3" },
24 new GraphNode { Id = "d", Path = @"D:\w\A.cs", Kind = "call_step", Label = "4" },
25 new GraphNode { Id = "e", Path = @"D:\w\A.cs", Kind = "call_step", Label = "5" },
26 ],
27 Edges =
28 [
29 new GraphEdge { FromId = "h", ToId = "a", Kind = "MultiBranch" },
30 new GraphEdge { FromId = "h", ToId = "b", Kind = "MultiBranch" },
31 new GraphEdge { FromId = "h", ToId = "c", Kind = "MultiBranch" },
32 new GraphEdge { FromId = "h", ToId = "d", Kind = "MultiBranch" },
33 new GraphEdge { FromId = "h", ToId = "e", Kind = "MultiBranch" },
34 ]
35 };
36
37 var state = new CodeNavigationMapPipelineState(
38 doc,
39 CodeNavigationMapLevelKind.ControlFlow,
40 new SkiaInstrumentViewport(300, 140),
41 CodeNavigationMapDetailLevel.Normal,
42 CodeNavigationMapRelatedGraphLayoutKind.Radial,
43 CodeNavigationMapControlFlowMainAxisKind.Auto,
44 null,
45 3,
46 0,
47 5,
48 false);
49
50 var result = CodeNavigationMapControlFlowDeclutter.TryTransform(state);
51 Assert.NotNull(result);
52 Assert.Contains(result.Nodes, n => n.Label == "+2");
53 Assert.Equal(4, result.Edges.Count(e =>
54 e.Kind?.Contains("multibranch", StringComparison.OrdinalIgnoreCase) == true));
55 }
56}
57
View only · write via MCP/CIDE