diff --git a/tests/DotNetCampus.CommandLine.Tests/CommandMatching/AddHandlerTests.cs b/tests/DotNetCampus.CommandLine.Tests/CommandMatching/AddHandlerTests.cs index 91e6a50..b8bee3b 100644 --- a/tests/DotNetCampus.CommandLine.Tests/CommandMatching/AddHandlerTests.cs +++ b/tests/DotNetCampus.CommandLine.Tests/CommandMatching/AddHandlerTests.cs @@ -224,6 +224,7 @@ public async Task AddHandler_TypedDelegate(string[] args, string expectedCommand await Task.Yield(); matched = o.Value; }) + .AddHandler(_ => { }) .RunAsync(); var matchedTypeName = result.HandledBy!.GetType().Name; @@ -232,6 +233,26 @@ public async Task AddHandler_TypedDelegate(string[] args, string expectedCommand Assert.AreEqual(expectedValue, matched); } + [TestMethod] + [DataRow(TestCommandLineStyle.Flexible, DisplayName = "[Flexible] foo")] + [DataRow(TestCommandLineStyle.DotNet, DisplayName = "[DotNet] foo")] + [DataRow(TestCommandLineStyle.Gnu, DisplayName = "[Gnu] foo")] + [DataRow(TestCommandLineStyle.Windows, DisplayName = "[Windows] foo")] + public void AddHandler_Discard /* 弃元 */(TestCommandLineStyle style) + { + // Arrange + var commandLine = CommandLine.Parse([], style.ToParsingOptions()); + + // Act + var result = commandLine + .AddHandler(_ => { }) + .Run(); + var matchedTypeName = result.HandledBy!.GetType().Name; + + // Assert + Assert.AreEqual(nameof(DefaultOptions), matchedTypeName); + } + // ReSharper disable once RedundantAssignment private int RunWithExitCode(ref T field, T value) {