| 1 | using CascadeIDE.Models; |
| 2 | using Xunit; |
| 3 | |
| 4 | namespace CascadeIDE.Tests; |
| 5 | |
| 6 | public sealed class FileRelationsAndControlFlowIntentGraphSettingsTests |
| 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 = FileRelationsAndControlFlowIntentGraphSettings.NormalizeDepth(input); |
| 17 | Assert.Equal(expected, actual); |
| 18 | } |
| 19 | |
| 20 | /// <summary> |
| 21 | /// Регресс: обновление карты намерений по курсору в CF должно опираться на |
| 22 | /// <c>[code_navigation.file_relations_and_control_flow_intent_graph].depth</c>, как и основной refresh. |
| 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 FileRelationsAndControlFlowIntentGraphSettings { Depth = depth }; |
| 32 | Assert.Equal(expectedControlFlow, map.IsControlFlowDepth); |
| 33 | Assert.Equal( |
| 34 | FileRelationsAndControlFlowIntentGraphSettings.NormalizeDepth(depth) == CodeNavigationMapLevelKind.ControlFlow, |
| 35 | map.IsControlFlowDepth); |
| 36 | } |
| 37 | |
| 38 | /// <summary> |
| 39 | /// <c>view</c> в <c>RunWorkspaceNavigationMapRefreshAsync</c> даёт <c>wantList</c> / <c>wantGraph</c>. |
| 40 | /// </summary> |
| 41 | [Theory] |
| 42 | [InlineData("list", true, false)] |
| 43 | [InlineData("LIST", true, false)] |
| 44 | [InlineData("graph", false, true)] |
| 45 | [InlineData("GRAPH", false, true)] |
| 46 | [InlineData("both", true, true)] |
| 47 | [InlineData("BOTH", true, true)] |
| 48 | [InlineData("nonsense", true, false)] |
| 49 | [InlineData("", true, false)] |
| 50 | public void NormalizeView_MatchesWorkspaceRefreshWantListWantGraph( |
| 51 | string rawView, |
| 52 | bool expectedWantList, |
| 53 | bool expectedWantGraph) |
| 54 | { |
| 55 | var map = new FileRelationsAndControlFlowIntentGraphSettings { View = rawView }; |
| 56 | Assert.Equal(expectedWantList, map.WantsWorkspaceNavigationMapList); |
| 57 | Assert.Equal(expectedWantGraph, map.WantsWorkspaceNavigationMapGraph); |
| 58 | var normalized = FileRelationsAndControlFlowIntentGraphSettings.NormalizeView(rawView); |
| 59 | Assert.Equal(expectedWantList, normalized is "list" or "both"); |
| 60 | Assert.Equal(expectedWantGraph, normalized is "graph" or "both"); |
| 61 | } |
| 62 | |
| 63 | [Theory] |
| 64 | [InlineData("glance", CodeNavigationMapDetailLevel.Glance)] |
| 65 | [InlineData("GLANCE", CodeNavigationMapDetailLevel.Glance)] |
| 66 | [InlineData("inspect", CodeNavigationMapDetailLevel.Inspect)] |
| 67 | [InlineData("normal", CodeNavigationMapDetailLevel.Normal)] |
| 68 | [InlineData("", CodeNavigationMapDetailLevel.Normal)] |
| 69 | [InlineData("unknown", CodeNavigationMapDetailLevel.Normal)] |
| 70 | public void NormalizeDetailLevel_ReturnsKnownValue(string? raw, CodeNavigationMapDetailLevel expected) |
| 71 | { |
| 72 | Assert.Equal(expected, FileRelationsAndControlFlowIntentGraphSettings.NormalizeDetailLevel(raw)); |
| 73 | var map = new FileRelationsAndControlFlowIntentGraphSettings { DetailLevel = raw ?? "" }; |
| 74 | Assert.Equal(expected, map.NormalizedDetailLevel); |
| 75 | } |
| 76 | |
| 77 | [Theory] |
| 78 | [InlineData(-5, 0.15)] |
| 79 | [InlineData(0, 0.15)] |
| 80 | [InlineData(0.2, 0.2)] |
| 81 | [InlineData(2, 2)] |
| 82 | [InlineData(42, 10)] |
| 83 | [InlineData(double.PositiveInfinity, FileRelationsAndControlFlowIntentGraphSettings.DefaultCaretIdleRefreshSeconds)] |
| 84 | [InlineData(double.NaN, FileRelationsAndControlFlowIntentGraphSettings.DefaultCaretIdleRefreshSeconds)] |
| 85 | public void NormalizeCaretIdleRefreshSeconds_ClampsAndFallsBack(double raw, double expected) |
| 86 | { |
| 87 | Assert.Equal(expected, FileRelationsAndControlFlowIntentGraphSettings.NormalizeCaretIdleRefreshSeconds(raw), 6); |
| 88 | var map = new FileRelationsAndControlFlowIntentGraphSettings { CaretIdleRefreshSeconds = raw }; |
| 89 | Assert.Equal(expected, map.NormalizedCaretIdleRefreshSeconds, 6); |
| 90 | } |
| 91 | |
| 92 | [Fact] |
| 93 | public void SuspendEditorSideEffectsWhileSelecting_DefaultsToFalse() |
| 94 | { |
| 95 | var map = new FileRelationsAndControlFlowIntentGraphSettings(); |
| 96 | Assert.False(map.SuspendEditorSideEffectsWhileSelecting); |
| 97 | } |
| 98 | } |
| 99 | |