multi-instance bug test case

CSharp · Console

/Program.cs

//switch version to check the result
//@nuget: CommandLineParser -Version 2.9.0-preview1
//nuget: CommandLineParser -Version 2.8.0
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using CommandLine;
//using FluentAssertions;
//using Xunit;

namespace CommandLine.Tests
{
class Program
{
   public static void  Main()
   {
	    new MultInstanceMoreTests().Sequence_with_similar_values_should_be_kept();
   }
}
    public class MultInstanceMoreTests
    {
       // [Fact]
      //  [Trait("category", "multi")]
        public void Sequence_with_similar_values_should_be_kept()
        {
            //var text = "--function-modeling None,Database,CodeModels -q a.litedb";
            var text = "x1 x2 x3 -c x1"; // x1 is th same in option and Value(0)		
            Console.WriteLine($"args= {text}");
            var args = text.Split();
            var parser = new Parser(with =>
            {
                with.HelpWriter = Console.Out;  
				
            });
            var result = parser.ParseArguments<Options>(args);
			var options= (result as Parsed<Options>).Value;
             options.Dump();
			//fail in xunit
           // options.Compress.Should().BeEquivalentTo(new[] { "x1" });
          //  options.InputDirs.Should().BeEquivalentTo(new[] { "x1","x2","x3" });

        }       
        public class Options
        {        

            [Option('c', "compress",
                HelpText = "Compress Match Pattern, Pipe Separated (|) ",
                Separator = '|',               
                Default = new[]
                {
            "*.txt", "*.log", "*.ini"
                })]
            public IEnumerable<string> Compress { get; set; }

            [Value(0,
                HelpText = "Input Directories.",               
                Required = true)]
            public IEnumerable<string> InputDirs { get; set; }


            [Option('n', "name",
                HelpText = "Metadata Name.",
                Default = "WILDCARD")]
            public string Name { get; set; }
        }
    }    
}

/*
v2.8.0  correct
args= x1 x2 x3 -c x1
Dumping object(CommandLine.Tests.Options)
 Compress   : [
             x1
]
 InputDirs  : [
             x1
             ,
             x2
             ,
             x3
]
 Name       : WILDCARD
 =================================
 v2.9.0-preview1  invalid
 
 args= x1 x2 x3 -c x1
Dumping object(CommandLine.Tests.Options)
 Compress   : [
             x1
]
 InputDirs  : [
             x2
             ,
             x3
]
 Name       : WILDCARD
*/
;