| 1 | using CascadeIDE.Models; |
| 2 | using Xunit; |
| 3 | |
| 4 | namespace CascadeIDE.Tests; |
| 5 | |
| 6 | public sealed class CodeNavigationMapSettingsTests |
| 7 | { |
| 8 | [Theory] |
| 9 | [InlineData("file", CodeNavigationMapLevelKind.File)] |
| 10 | [InlineData("FILE", CodeNavigationMapLevelKind.File)] |
| 11 | [InlineData("controlFlow", CodeNavigationMapLevelKind.ControlFlow)] |
| 12 | [InlineData("CONTROLFLOW", CodeNavigationMapLevelKind.ControlFlow)] |
| 13 | [InlineData("unknown", CodeNavigationMapLevelKind.File)] |
| 14 | public void NormalizeLevel_ReturnsKnownValue(string input, string expected) |
| 15 | { |
| 16 | var actual = CodeNavigationMapSettings.NormalizeDepth(input); |
| 17 | Assert.Equal(expected, actual); |
| 18 | } |
| 19 | |
| 20 | /// <summary> |
| 21 | /// Регресс: обновление карты намерений по курсору в CF должно опираться на <c>[code_navigation_map].depth</c>, |
| 22 | /// как и основной refresh — иначе <c>CodeNavigationMapLevel</c> на VM и Depth расходятся, карта не следует за методом. |
| 23 | /// </summary> |
| 24 | [Theory] |
| 25 | [InlineData("controlFlow", true)] |
| 26 | [InlineData("CONTROLFLOW", true)] |
| 27 | [InlineData("file", false)] |
| 28 | [InlineData("unknown", false)] |
| 29 | public void IsControlFlowDepth_MatchesNormalizeDepth(string depth, bool expectedControlFlow) |
| 30 | { |
| 31 | var map = new CodeNavigationMapSettings { Depth = depth }; |
| 32 | Assert.Equal(expectedControlFlow, map.IsControlFlowDepth); |
| 33 | Assert.Equal( |
| 34 | CodeNavigationMapSettings.NormalizeDepth(depth) == CodeNavigationMapLevelKind.ControlFlow, |
| 35 | map.IsControlFlowDepth); |
| 36 | } |
| 37 | |
| 38 | /// <summary> |
| 39 | /// Параметр <c>[code_navigation_map].view</c> в <c>RunWorkspaceNavigationMapRefreshAsync</c> даёт |
| 40 | /// <c>wantList</c> / <c>wantGraph</c> — при расхождении с привязкой ComboBox к VM снова получится «тихий» баг UI. |
| 41 | /// </summary> |
| 42 | [Theory] |
| 43 | [InlineData("list", true, false)] |
| 44 | [InlineData("LIST", true, false)] |
| 45 | [InlineData("graph", false, true)] |
| 46 | [InlineData("GRAPH", false, true)] |
| 47 | [InlineData("both", true, true)] |
| 48 | [InlineData("BOTH", true, true)] |
| 49 | [InlineData("nonsense", true, false)] |
| 50 | [InlineData("", true, false)] |
| 51 | public void NormalizeView_MatchesWorkspaceRefreshWantListWantGraph( |
| 52 | string rawView, |
| 53 | bool expectedWantList, |
| 54 | bool expectedWantGraph) |
| 55 | { |
| 56 | var map = new CodeNavigationMapSettings { View = rawView }; |
| 57 | Assert.Equal(expectedWantList, map.WantsCodeNavigationMapList); |
| 58 | Assert.Equal(expectedWantGraph, map.WantsCodeNavigationMapGraph); |
| 59 | var normalized = CodeNavigationMapSettings.NormalizeView(rawView); |
| 60 | Assert.Equal(expectedWantList, normalized is "list" or "both"); |
| 61 | Assert.Equal(expectedWantGraph, normalized is "graph" or "both"); |
| 62 | } |
| 63 | |
| 64 | [Theory] |
| 65 | [InlineData("glance", CodeNavigationMapDetailLevel.Glance)] |
| 66 | [InlineData("GLANCE", CodeNavigationMapDetailLevel.Glance)] |
| 67 | [InlineData("inspect", CodeNavigationMapDetailLevel.Inspect)] |
| 68 | [InlineData("normal", CodeNavigationMapDetailLevel.Normal)] |
| 69 | [InlineData("", CodeNavigationMapDetailLevel.Normal)] |
| 70 | [InlineData("unknown", CodeNavigationMapDetailLevel.Normal)] |
| 71 | public void NormalizeDetailLevel_ReturnsKnownValue(string? raw, CodeNavigationMapDetailLevel expected) |
| 72 | { |
| 73 | Assert.Equal(expected, CodeNavigationMapSettings.NormalizeDetailLevel(raw)); |
| 74 | var map = new CodeNavigationMapSettings { DetailLevel = raw ?? "" }; |
| 75 | Assert.Equal(expected, map.NormalizedDetailLevel); |
| 76 | } |
| 77 | |
| 78 | [Theory] |
| 79 | [InlineData("radial", CodeNavigationMapRelatedGraphLayoutKind.Radial)] |
| 80 | [InlineData("top_down", CodeNavigationMapRelatedGraphLayoutKind.TopDown)] |
| 81 | [InlineData("bottom_up", CodeNavigationMapRelatedGraphLayoutKind.BottomUp)] |
| 82 | [InlineData("junk", CodeNavigationMapRelatedGraphLayoutKind.Radial)] |
| 83 | public void NormalizeRelatedGraphLayout(string raw, string expected) |
| 84 | { |
| 85 | Assert.Equal(expected, CodeNavigationMapRelatedGraphLayoutKind.Normalize(raw)); |
| 86 | var map = new CodeNavigationMapSettings { RelatedGraphLayout = raw }; |
| 87 | Assert.Equal(expected, map.NormalizedRelatedGraphLayout); |
| 88 | } |
| 89 | |
| 90 | [Theory] |
| 91 | [InlineData("auto", CodeNavigationMapControlFlowMainAxisKind.Auto)] |
| 92 | [InlineData("", CodeNavigationMapControlFlowMainAxisKind.Auto)] |
| 93 | [InlineData("junk", CodeNavigationMapControlFlowMainAxisKind.Auto)] |
| 94 | [InlineData("vertical", CodeNavigationMapControlFlowMainAxisKind.Vertical)] |
| 95 | [InlineData("HORIZONTAL", CodeNavigationMapControlFlowMainAxisKind.Horizontal)] |
| 96 | public void NormalizeControlFlowMainAxis(string raw, string expected) |
| 97 | { |
| 98 | Assert.Equal(expected, CodeNavigationMapControlFlowMainAxisKind.Normalize(raw)); |
| 99 | var map = new CodeNavigationMapSettings { ControlFlowMainAxis = raw }; |
| 100 | Assert.Equal(expected, map.NormalizedControlFlowMainAxis); |
| 101 | } |
| 102 | |
| 103 | [Theory] |
| 104 | [InlineData("", CodeNavigationMapControlFlowGrainKind.Intent)] |
| 105 | [InlineData("intent", CodeNavigationMapControlFlowGrainKind.Intent)] |
| 106 | [InlineData("INTENT", CodeNavigationMapControlFlowGrainKind.Intent)] |
| 107 | [InlineData("micro_cfg", CodeNavigationMapControlFlowGrainKind.Intent)] |
| 108 | [InlineData("detailed", CodeNavigationMapControlFlowGrainKind.Detailed)] |
| 109 | [InlineData("DETAILED", CodeNavigationMapControlFlowGrainKind.Detailed)] |
| 110 | public void NormalizeControlFlowGrain(string raw, string expected) |
| 111 | { |
| 112 | Assert.Equal(expected, CodeNavigationMapControlFlowGrainKind.Normalize(raw)); |
| 113 | var map = new CodeNavigationMapSettings { ControlFlowGrain = raw }; |
| 114 | Assert.Equal(expected, map.NormalizedControlFlowGrain); |
| 115 | Assert.Equal( |
| 116 | expected == CodeNavigationMapControlFlowGrainKind.Detailed, |
| 117 | CodeNavigationMapControlFlowGrainKind.IsDetailed(expected)); |
| 118 | Assert.Equal( |
| 119 | expected == CodeNavigationMapControlFlowGrainKind.Intent, |
| 120 | CodeNavigationMapControlFlowGrainKind.IsIntent(expected)); |
| 121 | } |
| 122 | |
| 123 | [Theory] |
| 124 | [InlineData("plus_minus", "+", "-")] |
| 125 | [InlineData("true_false", "true", "false")] |
| 126 | [InlineData("one_zero", "1", "0")] |
| 127 | public void ResolveConditionBranchLabels_FromPreset(string preset, string positive, string negative) |
| 128 | { |
| 129 | var map = new CodeNavigationMapSettings { ConditionBranchLabelPreset = preset }; |
| 130 | var pair = CodeNavigationMapConditionBranchLabels.Resolve(map); |
| 131 | Assert.Equal(positive, pair.Positive); |
| 132 | Assert.Equal(negative, pair.Negative); |
| 133 | } |
| 134 | |
| 135 | [Fact] |
| 136 | public void ResolveConditionBranchLabels_CustomOverridesPreset() |
| 137 | { |
| 138 | var map = new CodeNavigationMapSettings |
| 139 | { |
| 140 | ConditionBranchLabelPreset = CodeNavigationMapConditionBranchLabels.PresetCustom, |
| 141 | ConditionBranchPositive = "Y", |
| 142 | ConditionBranchNegative = "N" |
| 143 | }; |
| 144 | var pair = map.ResolvedConditionBranchLabels(); |
| 145 | Assert.Equal("Y", pair.Positive); |
| 146 | Assert.Equal("N", pair.Negative); |
| 147 | } |
| 148 | } |
| 149 | |