public void RequiredArgumentsWork() { var strategy = new Parser(); strategy.AddDescription(new NamedArgumentDescription<string>("required") { IsRequired = true }); var actual = strategy.Parse("--notrequired=mmmm"); Assert.That(actual.IsValid, Is.False); var actual2 = strategy.Parse("--required=aaa"); Assert.That(actual2.IsValid); }
public void PatternMatchingWorks() { var strategy = new Parser(); strategy.AddDescription(new NamedArgumentDescription<string>("numbers") { MatchPattern = "^\\d+$" }); var actual = strategy.Parse("--numbers=ab112d"); Assert.That(actual.IsValid, Is.False); var actual2 = strategy.Parse("--numbers=12345"); Assert.That(actual2.IsValid); }
public void PositionedArgumentValidation() { var strategy = new Parser(); strategy.AddDescription(new PositionedArgumentDescription<string>(0) { MatchPattern = "^\\d+$" }); var actual = strategy.Parse("ab112d", "111333442"); Assert.That(actual.IsValid, Is.False); var actual2 = strategy.Parse("111333442", "ab112d"); Assert.That(actual2.IsValid); }
public void TypeConversion() { var parser = new Parser(); parser.AddDescription(new NamedArgumentDescription<int>("number")); parser.AddDescription(new PositionedArgumentDescription<DateTime>(0)); var actual = parser.Parse("2010-01-01", "--number=123", "--othern=123"); Assert.That(actual.IsValid); var positionedDate = actual.Arguments.OfType<PositionedArgument<DateTime>>().SingleOrDefault(); Assert.That(positionedDate, Is.Not.Null); Assert.That(positionedDate.Position, Is.EqualTo(0)); Assert.That(positionedDate.Value, Is.EqualTo(new DateTime(2010, 1, 1))); var namedInt = actual.Arguments.OfType<NamedArgument<int>>().SingleOrDefault(); Assert.That(namedInt, Is.Not.Null); Assert.That(namedInt.Name, Is.EqualTo("number")); Assert.That(namedInt.Value, Is.EqualTo(123)); var strings = actual.Arguments.OfType<NamedArgument<string>>(); Assert.That(strings.Count(), Is.EqualTo(1)); Assert.That(strings.Single().Name, Is.EqualTo("othern")); }