| 1 | using CascadeIDE.Features.WorkspaceNavigation.Application; |
| 2 | using CascadeIDE.ViewModels; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class CodeNavigationControlFlowGlyphComposerTests |
| 8 | { |
| 9 | private static CodeNavigationMapGraphSceneVm Scene(bool useLegendColumn, bool showGlyphs) => |
| 10 | new() |
| 11 | { |
| 12 | Nodes = [], |
| 13 | Edges = [], |
| 14 | UseLegendColumn = useLegendColumn, |
| 15 | ShowNodeLegendGlyphs = showGlyphs |
| 16 | }; |
| 17 | |
| 18 | private static CodeNavigationMapGraphNodeLayout Node( |
| 19 | string id, |
| 20 | string kind, |
| 21 | int line, |
| 22 | bool anchor = false, |
| 23 | int? legend = null, |
| 24 | CodeNavigationMapNodeShape shape = CodeNavigationMapNodeShape.Circle, |
| 25 | string label = "x") => |
| 26 | new() |
| 27 | { |
| 28 | Id = id, |
| 29 | Kind = kind, |
| 30 | FullPath = @"C:\x\A.cs", |
| 31 | Label = label, |
| 32 | Center = default, |
| 33 | Radius = 9, |
| 34 | IsAnchor = anchor, |
| 35 | LineStart = line, |
| 36 | Shape = shape, |
| 37 | LegendIndex = legend |
| 38 | }; |
| 39 | |
| 40 | [Fact] |
| 41 | public void Exit_yields_empty_glyph_and_arrow_flag() |
| 42 | { |
| 43 | var n = Node("e", "exit_step", 99); |
| 44 | var (g, a) = CodeNavigationControlFlowGlyphComposer.BuildTextGlyph(n, Scene(false, false)); |
| 45 | Assert.Equal("", g); |
| 46 | Assert.True(a); |
| 47 | Assert.Equal(ControlFlowNodeVisualKind.Exit, CodeNavigationControlFlowGlyphComposer.ResolveVisualKind(n)); |
| 48 | } |
| 49 | |
| 50 | [Fact] |
| 51 | public void Protected_step_shows_T() |
| 52 | { |
| 53 | var n = Node("p", "protected_step", 2); |
| 54 | var (g, _) = CodeNavigationControlFlowGlyphComposer.BuildTextGlyph(n, Scene(false, false)); |
| 55 | Assert.Equal("T", g); |
| 56 | } |
| 57 | |
| 58 | [Fact] |
| 59 | public void Handler_shows_bang() |
| 60 | { |
| 61 | var n = Node("h", "handler_step", 6); |
| 62 | var (g, _) = CodeNavigationControlFlowGlyphComposer.BuildTextGlyph(n, Scene(false, false)); |
| 63 | Assert.Equal("!", g); |
| 64 | } |
| 65 | |
| 66 | [Fact] |
| 67 | public void Legend_number_when_column_or_node_glyphs() |
| 68 | { |
| 69 | var n = Node("s", "call_step", 3, legend: 4); |
| 70 | var (g1, _) = CodeNavigationControlFlowGlyphComposer.BuildTextGlyph(n, Scene(useLegendColumn: true, showGlyphs: false)); |
| 71 | Assert.Equal("4", g1); |
| 72 | var (g2, _) = CodeNavigationControlFlowGlyphComposer.BuildTextGlyph(n, Scene(useLegendColumn: false, showGlyphs: true)); |
| 73 | Assert.Equal("4", g2); |
| 74 | } |
| 75 | |
| 76 | [Fact] |
| 77 | public void Condition_shows_question_and_diamond() |
| 78 | { |
| 79 | var n = Node("c", "condition_step", 5); |
| 80 | var (g, _) = CodeNavigationControlFlowGlyphComposer.BuildTextGlyph(n, Scene(false, false)); |
| 81 | Assert.Equal("?", g); |
| 82 | Assert.Equal(ControlFlowNodeVisualKind.Diamond, CodeNavigationControlFlowGlyphComposer.ResolveVisualKind(n)); |
| 83 | } |
| 84 | } |
| 85 | |