From a3819b0184941a7a35fd10c4da5fa0295f15e58e Mon Sep 17 00:00:00 2001 From: walterlv Date: Mon, 12 Jan 2026 10:13:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=BC=83=E5=85=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommandMatching/AddHandlerTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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) {