| 1 | using CascadeIDE.Features.Editor.Application.Monaco; |
| 2 | using CascadeIDE.Services; |
| 3 | using Microsoft.CodeAnalysis; |
| 4 | using Xunit; |
| 5 | |
| 6 | namespace CascadeIDE.Tests; |
| 7 | |
| 8 | public sealed class MonacoEditorPresentationProjectorTests |
| 9 | { |
| 10 | [Fact] |
| 11 | public void Diagnostics_use_line_first_decorations() |
| 12 | { |
| 13 | var strips = new[] |
| 14 | { |
| 15 | new EditorDiagnosticStrip(0, 5, DiagnosticSeverity.Error, "CS0246", "Type not found", 14, 1), |
| 16 | }; |
| 17 | |
| 18 | var decos = MonacoEditorDiagnosticsMapper.ToDecorations(strips); |
| 19 | Assert.Single(decos); |
| 20 | Assert.Equal(14, decos[0].StartLine); |
| 21 | Assert.True(decos[0].IsWholeLine); |
| 22 | Assert.Equal("squiggly-error", decos[0].ClassName); |
| 23 | } |
| 24 | |
| 25 | [Fact] |
| 26 | public void Diagnostic_inlays_use_at_end_of_line_flag() |
| 27 | { |
| 28 | var strips = new[] |
| 29 | { |
| 30 | new EditorDiagnosticStrip(0, 5, DiagnosticSeverity.Error, "CS0246", "Type not found", 3, 1), |
| 31 | }; |
| 32 | |
| 33 | var inlays = MonacoEditorDiagnosticsMapper.ToDiagnosticInlays(strips); |
| 34 | Assert.Single(inlays); |
| 35 | Assert.True(inlays[0].AtEndOfLine); |
| 36 | Assert.Equal("diagnostic-error", inlays[0].Kind); |
| 37 | } |
| 38 | |
| 39 | [Fact] |
| 40 | public void MergeInlayHints_suppresses_var_on_diagnostic_lines() |
| 41 | { |
| 42 | const string text = "var x = 1;\nvar bad = y;"; |
| 43 | var strips = new[] |
| 44 | { |
| 45 | new EditorDiagnosticStrip(10, 3, DiagnosticSeverity.Error, "CS0103", "y", 2, 11), |
| 46 | }; |
| 47 | var varParts = new[] |
| 48 | { |
| 49 | new EditorTrailingInlayPart(3, " int"), |
| 50 | new EditorTrailingInlayPart(15, " error"), |
| 51 | }; |
| 52 | |
| 53 | var hints = MonacoEditorPresentationProjector.MergeInlayHints(text, strips, varParts); |
| 54 | Assert.Equal(2, hints.Count); |
| 55 | Assert.DoesNotContain(hints, h => h.Line == 2 && h.Kind == "type"); |
| 56 | Assert.Contains(hints, h => h.Line == 2 && h.AtEndOfLine); |
| 57 | Assert.Contains(hints, h => h.Line == 1 && !h.AtEndOfLine); |
| 58 | } |
| 59 | } |
| 60 | |