| 1 | using CascadeIDE.Features.HybridIndex.Application; |
| 2 | using CascadeIDE.Features.Launch.Application; |
| 3 | using CascadeIDE.Features.Markdown.Application; |
| 4 | using CascadeIDE.Features.Shell.Application; |
| 5 | using CascadeIDE.Features.Workspace.Application; |
| 6 | using CascadeIDE.Services; |
| 7 | using Xunit; |
| 8 | |
| 9 | namespace CascadeIDE.Tests; |
| 10 | |
| 11 | public sealed class FeaturesShellApplicationExtractsTests |
| 12 | { |
| 13 | [Fact] |
| 14 | public void CommandPaletteSubtitle_handles_empty_category() |
| 15 | { |
| 16 | Assert.Equal("cid", CommandPaletteSubtitleProjection.CommandPaletteSubtitle("cid", "")); |
| 17 | Assert.Equal("cid · cat", CommandPaletteSubtitleProjection.CommandPaletteSubtitle("cid", " cat ")); |
| 18 | } |
| 19 | |
| 20 | [Fact] |
| 21 | public void GoToPaletteRipgrepPattern_builder_matches_prefixes() |
| 22 | { |
| 23 | var qx = new GoToAllQuery('x', " foo "); |
| 24 | var (px, fx, gx) = GoToPaletteRipgrepPatternBuilder.Build(qx); |
| 25 | Assert.Equal("foo", px); |
| 26 | Assert.True(fx); |
| 27 | Assert.Null(gx); |
| 28 | |
| 29 | var qt = new GoToAllQuery('t', "MyType"); |
| 30 | var (pt, ft, gt) = GoToPaletteRipgrepPatternBuilder.Build(qt); |
| 31 | Assert.Contains("MyType", pt); |
| 32 | Assert.False(ft); |
| 33 | Assert.Equal("*.cs", gt); |
| 34 | |
| 35 | var qm = new GoToAllQuery('m', "Bar"); |
| 36 | var (pm, fm, gm) = GoToPaletteRipgrepPatternBuilder.Build(qm); |
| 37 | Assert.Contains(@"\bBar\b", pm); |
| 38 | Assert.False(fm); |
| 39 | Assert.Equal("*.cs", gm); |
| 40 | } |
| 41 | |
| 42 | [Fact] |
| 43 | public void UiModeSelectionParameter_parses_common_forms() |
| 44 | { |
| 45 | Assert.Equal(3, UiModeSelectionParameter.ParseIndex(3)); |
| 46 | Assert.Equal(2, UiModeSelectionParameter.ParseIndex(2L)); |
| 47 | Assert.Equal(1, UiModeSelectionParameter.ParseIndex("1")); |
| 48 | Assert.Equal(-1, UiModeSelectionParameter.ParseIndex(long.MaxValue)); |
| 49 | Assert.Equal(-1, UiModeSelectionParameter.ParseIndex(null)); |
| 50 | } |
| 51 | |
| 52 | [Fact] |
| 53 | public void WorkspaceDirectoryFromSolutionPath_normalize_existing_file() |
| 54 | { |
| 55 | var dir = WorkspaceDirectoryFromSolutionPath.Resolve(""); |
| 56 | Assert.Equal("", dir); |
| 57 | |
| 58 | try |
| 59 | { |
| 60 | var tmp = Path.Combine(Path.GetTempPath(), "cascdirtest-" + Guid.NewGuid().ToString("n") + ".txt"); |
| 61 | File.WriteAllText(tmp, "x"); |
| 62 | var ws = WorkspaceDirectoryFromSolutionPath.Resolve(tmp); |
| 63 | Assert.Equal(Path.GetDirectoryName(tmp), ws); |
| 64 | } |
| 65 | catch |
| 66 | { |
| 67 | // temp IO optional in CI sandbox |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | [Fact] |
| 72 | public void ExpandedMarkdownDefaultExportPath_uses_filename() |
| 73 | { |
| 74 | var dir = Path.GetTempPath(); |
| 75 | var src = Path.Combine(dir, "Note.md"); |
| 76 | var path = ExpandedMarkdownDefaultExportPath.Resolve(src); |
| 77 | Assert.EndsWith("Note.expanded.md", path.Replace('/', Path.DirectorySeparatorChar), StringComparison.OrdinalIgnoreCase); |
| 78 | } |
| 79 | |
| 80 | [Fact] |
| 81 | public void HybridIndexHisPathDisplayShortener_trims_paths() |
| 82 | { |
| 83 | Assert.Equal("—", HybridIndexHisPathDisplayShortener.ShortenLikeEcam("")); |
| 84 | Assert.Equal("—", HybridIndexHisPathDisplayShortener.ShortenLikeEcam("—")); |
| 85 | |
| 86 | var withSep = $"a{Path.DirectorySeparatorChar}b{Path.DirectorySeparatorChar}File.cs"; |
| 87 | Assert.Equal("File.cs", HybridIndexHisPathDisplayShortener.ShortenLikeEcam(withSep)); |
| 88 | |
| 89 | var longNoSep = new string('a', 40); |
| 90 | var shorted = HybridIndexHisPathDisplayShortener.ShortenLikeEcam(longNoSep); |
| 91 | Assert.True(shorted.Length < longNoSep.Length); |
| 92 | } |
| 93 | |
| 94 | [Fact] |
| 95 | public void LaunchProjectRelativePath_requires_inside_solution_root() |
| 96 | { |
| 97 | var root = Path.Combine(Path.GetTempPath(), "cascade-launch-rel-" + Guid.NewGuid().ToString("n")); |
| 98 | var proj = Path.Combine(root, "nest", "p.csproj"); |
| 99 | Directory.CreateDirectory(Path.GetDirectoryName(proj)!); |
| 100 | File.WriteAllText(proj, "<Project/>"); |
| 101 | |
| 102 | Assert.True(LaunchProjectRelativePath.TryGetRelativeToSolutionDirectory(root, proj, out var rel, out var err)); |
| 103 | Assert.Null(err); |
| 104 | Assert.Equal(Path.Combine("nest", "p.csproj"), rel!, StringComparer.OrdinalIgnoreCase); |
| 105 | |
| 106 | Assert.False(LaunchProjectRelativePath.TryGetRelativeToSolutionDirectory(root, Path.Combine(Path.GetTempPath(), "outside", "x.csproj"), out _, out var err2)); |
| 107 | Assert.NotNull(err2); |
| 108 | |
| 109 | try { Directory.Delete(root, recursive: true); } catch { /* ignore */ } |
| 110 | } |
| 111 | } |
| 112 | |