Forge
csharpdeeb25a2
1using CascadeIDE.Features.Documents;
2using CascadeIDE.Models;
3using Xunit;
4
5namespace CascadeIDE.Tests;
6
7/// <summary>
8/// Регрессия: нормализация путей в дереве решения не должна ронять синхронизацию выбора / открытие из карты намерений.
9/// </summary>
10public sealed class SolutionTreePathTests
11{
12 [Fact]
13 public void TryGetFullPath_embedded_null_returns_false_without_throwing()
14 {
15 var bad = "a\0b\\file.cs";
16 Assert.False(SolutionTreePath.TryGetFullPath(bad, out var full));
17 Assert.Equal("", full);
18 }
19
20 [Fact]
21 public void TryGetFullPath_valid_temp_directory_matches_path_get_full_path()
22 {
23 var tmp = Path.GetTempPath();
24 Assert.True(SolutionTreePath.TryGetFullPath(tmp, out var full));
25 Assert.Equal(CanonicalFilePath.Normalize(tmp), full);
26 }
27
28 [Fact]
29 public void FindItemByFullPath_skips_unnormalizable_nodes_and_finds_matching_file()
30 {
31 var goodPath = Path.Combine(Path.GetTempPath(), "cascade_solution_tree_test_" + Guid.NewGuid().ToString("n") + ".cs");
32 File.WriteAllText(goodPath, "//");
33 try
34 {
35 var goodNorm = CanonicalFilePath.Normalize(goodPath);
36 var root = SolutionItem.CreateSolution("s", @"C:\x.sln");
37 root.Children.Add(SolutionItem.CreateFile("bad-null", "a\0broken.cs"));
38 root.Children.Add(SolutionItem.CreateFile("good", goodPath));
39
40 var found = SolutionTreePath.FindItemByFullPath(new[] { root }, goodNorm);
41 Assert.NotNull(found);
42 Assert.Equal("good", found.Title);
43 Assert.Equal(goodNorm, CanonicalFilePath.Normalize(found.FullPath!));
44 }
45 finally
46 {
47 try
48 {
49 File.Delete(goodPath);
50 }
51 catch
52 {
53 // ignore
54 }
55 }
56 }
57
58 [Fact]
59 public void FindItemByFullPath_returns_null_when_only_broken_paths()
60 {
61 var root = SolutionItem.CreateSolution("s", @"C:\x.sln");
62 root.Children.Add(SolutionItem.CreateFile("bad", "x\0y.cs"));
63
64 var found = SolutionTreePath.FindItemByFullPath(new[] { root }, CanonicalFilePath.Normalize(Path.GetTempPath()));
65 Assert.Null(found);
66 }
67}
68
View only · write via MCP/CIDE