public void Not_Throw_If_Not_Given_Enough_Args_But_Return_Them_In_The_Result() { // arrange var list = new List <string[]>(); var sw = new ValuesSwitch(new Parser("a"), 'v', "values", (o, strings) => list.Add(strings)) { MinRequired = 5 }; var info = new IterationInfo("-v v0 v1 v2 v3 -s".Split(' '), 0); var request = new ConsumptionRequest(info, 3); ConsumptionResult res = null; Action mightThrow = () => res = sw.Consume(new object(), request); // act // assert mightThrow.Should().NotThrow(); res.ParseExceptions.Should().HaveCount(1).And.Subject.Single().Should().BeOfType <MissingValueException>(); }
/// <summary> /// Creates a request based off the results of potential consumption /// </summary> /// <param name="consumerResult">The consumer result.</param> /// <param name="selected">The selected.</param> /// <returns>The request</returns> public ConsumptionRequest Create(PotentialConsumerResult consumerResult, ConsumptionResult selected) { for (var i = 1; i < selected.NumConsumed; i++) { foreach (var parser in consumerResult.Chain) { var info = consumerResult.Info.Consume(i); var res = parser.CanConsume(selected, info); if (res.Info > info && res.ConsumingParameter != null && res.ConsumingParameter is Switch) { return(new ConsumptionRequest(consumerResult.Info, i)); } } } return(new ConsumptionRequest(consumerResult.Info, selected.NumConsumed)); }
/// <summary> /// Selects the specified result. /// </summary> /// <param name="result">The result.</param> /// <returns>ConsumptionResult.</returns> /// <exception cref="ForwardProgressException"></exception> public virtual ConsumptionResult Select(PotentialConsumerResult result) { ConsumptionResult foundResult = null; var switchResults = result.ConsumptionResults.Where(r => r.ConsumingParameter is Switch).ToList(); if (switchResults.Any()) { foundResult = switchResults.FirstOrDefault(r => result.Chain.Contains(r.ConsumingParameter.Parser)); } if (foundResult == null) { foundResult = result.ConsumptionResults.FirstOrDefault(r => result.Chain.Contains(r.ConsumingParameter .Parser)); } if (foundResult == null) { throw new ForwardProgressException(result.Info); } return(foundResult); }