public void TryParsePassesResult(bool innerSuccess, string innerRemaining, string result) { var inner = StringParserTestUtils.MockParser("stat", innerSuccess, innerRemaining, result).Object; var sut = new ValidatingParser <string>(inner); var(_, _, actual) = sut.Parse("stat"); Assert.AreEqual(result, actual); }
public string TryParseReturnsCorrectRemaining(string innerRemaining) { var inner = StringParserTestUtils.MockParser("stat", true, innerRemaining, "").Object; var sut = new ValidatingParser <string>(inner); var(_, actual, _) = sut.Parse("stat"); return(actual); }
public void TryParseReturnsCorrectUnchangedRemaining(string remaining) { var inner = StringParserTestUtils.MockParser("stat", true, remaining, "").Object; var sut = new ValidatingParser <string>(inner); var(_, actual, _) = sut.Parse("stat"); Assert.AreEqual(remaining, actual); }
public void TryParseReturnsSuccessIfRemainingIsOnlyWhiteSpaceAndEndsWithHidden() { const string remaining = " \n\t\r" + ItemConstants.HiddenStatSuffix; var inner = StringParserTestUtils.MockParser("stat", true, remaining, "").Object; var sut = new ValidatingParser <string>(inner); var(actual, _, _) = sut.Parse("stat"); Assert.True(actual); }
public void TryParseReturnsFailureIfRemainingStartsWithHidden() { const string remaining = ItemConstants.HiddenStatSuffix + " "; var inner = StringParserTestUtils.MockParser("stat", true, remaining, "").Object; var sut = new ValidatingParser <string>(inner); var(actual, _, _) = sut.Parse("stat"); Assert.False(actual); }
public void TryParseReturnsFailureIfRemainingContainsNonWhiteSpace() { const string remaining = " r "; var inner = StringParserTestUtils.MockParser("stat", true, remaining, "").Object; var sut = new ValidatingParser <string>(inner); var(actual, _, _) = sut.Parse("stat"); Assert.False(actual); }
public void TryParseReturnsFailureIfInnerReturnsFailure() { const string remaining = " "; var inner = StringParserTestUtils.MockParser("stat", false, remaining, "").Object; var sut = new ValidatingParser <string>(inner); var(actual, _, _) = sut.Parse("stat"); Assert.False(actual); }
public void TryParseCleansIfInnerReturnsFalse() { const string innerRemaining = " \ntest\t\r " + ItemConstants.HiddenStatSuffix; var inner = StringParserTestUtils.MockParser("stat", true, innerRemaining, "").Object; var sut = new ValidatingParser <string>(inner); var(_, actual, _) = sut.Parse("stat"); Assert.AreEqual("test", actual); }
public void TryParseHiddenTestIsCaseInsensitive() { var remaining = ItemConstants.HiddenStatSuffix.ToLowerInvariant(); var inner = StringParserTestUtils.MockParser("stat", true, remaining, "").Object; var sut = new ValidatingParser <string>(inner); var(actual, _, _) = sut.Parse("stat"); Assert.True(actual); }
public void TryParsePassesResult(bool innerSuccess, string innerRemaining, string result) { var inner = Mock.Of <IParser <string> >(p => p.Parse("stat") == new ParseResult <string>(innerSuccess, innerRemaining, result)); var sut = new ValidatingParser <string>(inner); var(_, _, actual) = sut.Parse("stat"); Assert.AreEqual(result, actual); }
public string TryParseReturnsCorrectRemaining(string innerRemaining) { var inner = Mock.Of <IParser <string> >(p => p.Parse("stat") == new ParseResult <string>(true, innerRemaining, default)); var sut = new ValidatingParser <string>(inner); var(_, actual, _) = sut.Parse("stat"); return(actual); }
public void TryParseReturnsCorrectUnchangedRemaining(string remaining) { var inner = Mock.Of <IParser <string> >(p => p.Parse("stat") == new ParseResult <string>(true, remaining, default)); var sut = new ValidatingParser <string>(inner); var(_, actual, _) = sut.Parse("stat"); Assert.AreEqual(remaining, actual); }
public void TryParseReturnsFailureIfRemainingStartsWithHidden() { const string remaining = ItemConstants.HiddenStatSuffix + " "; var inner = Mock.Of <IParser <string> >(p => p.Parse("stat") == new ParseResult <string>(true, remaining, default)); var sut = new ValidatingParser <string>(inner); var(actual, _, _) = sut.Parse("stat"); Assert.False(actual); }
public void TryParseReturnsFailureIfRemainingContainsNonWhiteSpace() { const string remaining = " r "; var inner = Mock.Of <IParser <string> >(p => p.Parse("stat") == new ParseResult <string>(true, remaining, default)); var sut = new ValidatingParser <string>(inner); var(actual, _, _) = sut.Parse("stat"); Assert.False(actual); }
public void TryParseReturnsFailureIfInnerReturnsFailure() { const string remaining = " "; var inner = Mock.Of <IParser <string> >(p => p.Parse("stat") == new ParseResult <string>(false, remaining, default)); var sut = new ValidatingParser <string>(inner); var(actual, _, _) = sut.Parse("stat"); Assert.False(actual); }
public void TryParseCleansIfInnerReturnsFalse() { const string innerRemaining = " \ntest\t\r " + ItemConstants.HiddenStatSuffix; var inner = Mock.Of <IParser <string> >(p => p.Parse("stat") == new ParseResult <string>(true, innerRemaining, default)); var sut = new ValidatingParser <string>(inner); var(_, actual, _) = sut.Parse("stat"); Assert.AreEqual("test", actual); }
public void TryParseReturnsSuccessIfRemainingIsOnlyWhiteSpaceAndEndsWithHidden() { const string remaining = " \n\t\r" + ItemConstants.HiddenStatSuffix; var inner = Mock.Of <IParser <string> >(p => p.Parse("stat") == new ParseResult <string>(true, remaining, default)); var sut = new ValidatingParser <string>(inner); var(actual, _, _) = sut.Parse("stat"); Assert.True(actual); }
public void TryParseHiddenTestIsCaseInsensitive() { var remaining = ItemConstants.HiddenStatSuffix.ToLowerInvariant(); var inner = Mock.Of <IParser <string> >(p => p.Parse("stat") == new ParseResult <string>(true, remaining, default)); var sut = new ValidatingParser <string>(inner); var(actual, _, _) = sut.Parse("stat"); Assert.True(actual); }
private Parser CreateParser() { var referenceService = new ReferenceService(_parsingData.ReferencedMatchers, _parsingData.StatMatchers); var regexGroupService = new RegexGroupService(_builderFactories.ValueBuilders); // The parsing pipeline using one IStatMatchers instance to parse a part of the stat. IStringParser <IIntermediateModifier> CreateInnerParser(IStatMatchers statMatchers) => new CachingStringParser <IIntermediateModifier>( new StatNormalizingParser <IIntermediateModifier>( new ResolvingParser( MatcherDataParser.Create( statMatchers.Data, new StatMatcherRegexExpander( referenceService, regexGroupService, statMatchers.MatchesWholeLineOnly).Expand), referenceService, new IntermediateModifierResolver(ModifierBuilder.Empty), regexGroupService ) ) ); Parallel.ForEach(_parsingData.StatMatchers, s => { _ = s.Data; }); var innerParserCache = _parsingData.StatMatchers.ToDictionary(Funcs.Identity, CreateInnerParser); // The steps define the order in which the inner parsers, and by extent the IStatMatchers, are executed. IStringParser <IIntermediateModifier> StepToParser(TStep step) => innerParserCache[_parsingData.SelectStatMatcher(step)]; // The full parsing pipeline. IStringParser <IReadOnlyList <IReadOnlyList <IIntermediateModifier> > > parser = new ValidatingParser <IReadOnlyList <IReadOnlyList <IIntermediateModifier> > >( new StatNormalizingParser <IReadOnlyList <IReadOnlyList <IIntermediateModifier> > >( new StatReplacingParser <IReadOnlyList <IIntermediateModifier> >( new CompositeParser <IIntermediateModifier, TStep>(_parsingData.Stepper, StepToParser), _parsingData.StatReplacers ) ) ); return(ps => AggregateAndBuild(ps, parser.Parse(ps.ModifierLine))); }