Forge
csharpdeeb25a2
1using System.Text.Json;
2using CascadeIDE.Services.CodeNavigation;
3using Xunit;
4
5namespace CascadeIDE.Tests;
6
7/// <summary>
8/// Регресс: intent-зерно subgraph (ADR 0053 / 0151) компактнее пошагового CFG на том же методе.
9/// </summary>
10public sealed class CodeNavigationMethodIntentSubgraphBuilderTests
11{
12 private const string FakePath = @"D:\sandbox\GrainIntentTest.cs";
13
14 [Fact]
15 public void Intent_HasFewerNodesThanDetailed_ForClassicForLoop_AndHasLoopStep()
16 {
17 var source =
18 """
19 class C {
20 void M() {
21 for (int i = 0; i < N; i++) {
22 Foo();
23 }
24 }
25 }
26 """;
27
28 using var intentDoc = JsonDocument.Parse(
29 CodeNavigationMethodIntentSubgraphBuilder.BuildJson(FakePath, source, line: 3, column: 14, 64, 64));
30 using var detailedDoc = JsonDocument.Parse(
31 CodeNavigationControlFlowSubgraphBuilder.BuildJson(FakePath, source, line: 3, column: 14, 64, 64));
32
33 var intentCount = intentDoc.RootElement.GetProperty("nodes").GetArrayLength();
34 var detailedCount = detailedDoc.RootElement.GetProperty("nodes").GetArrayLength();
35
36 Assert.True(intentCount < detailedCount);
37
38 var loopStep = false;
39 foreach (var n in intentDoc.RootElement.GetProperty("nodes").EnumerateArray())
40 {
41 if (string.Equals(n.GetProperty("kind").GetString(), "loop_step", StringComparison.Ordinal))
42 {
43 loopStep = true;
44 break;
45 }
46 }
47
48 Assert.True(loopStep);
49 }
50}
51
View only · write via MCP/CIDE