-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy pathIssue847Tests.cs
56 lines (46 loc) · 1.59 KB
/
Issue847Tests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using FluentAssertions;
using System.Linq;
using Xunit;
// Issue #847
// no parsing error if additional positional argument is present
namespace CommandLine.Tests.Unit
{
public class Issue847Tests
{
[Fact]
public void IgnoreUnknownArguments_should_work_for_values()
{
var arguments = new[] { "foo", "bar", "too_much" };
var result = new Parser(with => { with.IgnoreUnknownArguments = true; })
.ParseArguments<Options>(arguments);
Assert.Empty(result.Errors);
Assert.Equal(ParserResultType.Parsed, result.Tag);
result.WithParsed(options =>
{
options.Foo.Should().Be("foo");
options.Bar.Should().Be("bar");
});
}
[Fact]
public void Additional_positional_arguments_should_raise_errors()
{
var arguments = new[] { "foo", "bar", "too_much" };
var result = new Parser(with => { with.IgnoreUnknownArguments = false; })
.ParseArguments<Options>(arguments);
Assert.NotEmpty(result.Errors);
Assert.Equal(ParserResultType.NotParsed, result.Tag);
result.WithNotParsed(errors =>
{
Assert.NotEmpty(errors);
Assert.IsType<UnknownValueError>(errors.Single());
});
}
private class Options
{
[Value(0, Required = true)]
public string Foo { get; set; }
[Value(1, Required = false)]
public string Bar { get; set; }
}
}
}