mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 00:07:58 +01:00
* Added analyzer * WIP - Trying to create tests, failing with bad dependencies * Working test woo * Tidy up * Tidy up * Fix integration tests failing on command line * Use 4.11 compiler * Fix expecting 'e' as param name * Make analyzer come as part of Terminal.Gui * Add docs * Fix warnings
62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
using Terminal.Gui.Input;
|
|
using Terminal.Gui.Views;
|
|
|
|
namespace Terminal.Gui.Analyzers.Tests;
|
|
|
|
public class HandledEventArgsAnalyzerTests
|
|
{
|
|
[Theory]
|
|
[InlineData("e")]
|
|
[InlineData ("args")]
|
|
public async Task Should_ReportDiagnostic_When_EHandledNotSet_Lambda (string paramName)
|
|
{
|
|
var originalCode = $$"""
|
|
using Terminal.Gui.Views;
|
|
|
|
class TestClass
|
|
{
|
|
void Setup()
|
|
{
|
|
var b = new Button();
|
|
b.Accepting += (s, {{paramName}}) =>
|
|
{
|
|
// Forgot {{paramName}}.Handled = true;
|
|
};
|
|
}
|
|
}
|
|
""";
|
|
await new ProjectBuilder ()
|
|
.WithSourceCode (originalCode)
|
|
.WithAnalyzer (new HandledEventArgsAnalyzer ())
|
|
.ValidateAsync ();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData ("e")]
|
|
[InlineData ("args")]
|
|
public async Task Should_ReportDiagnostic_When_EHandledNotSet_Method (string paramName)
|
|
{
|
|
var originalCode = $$"""
|
|
using Terminal.Gui.Views;
|
|
using Terminal.Gui.Input;
|
|
|
|
class TestClass
|
|
{
|
|
void Setup()
|
|
{
|
|
var b = new Button();
|
|
b.Accepting += BOnAccepting;
|
|
}
|
|
private void BOnAccepting (object? sender, CommandEventArgs {{paramName}})
|
|
{
|
|
|
|
}
|
|
}
|
|
""";
|
|
await new ProjectBuilder ()
|
|
.WithSourceCode (originalCode)
|
|
.WithAnalyzer (new HandledEventArgsAnalyzer ())
|
|
.ValidateAsync ();
|
|
}
|
|
}
|