ZoneCodeGenerator: Add tests for Matchers to test TokenOffset and Tag behaviour

This commit is contained in:
Jan
2019-10-29 12:21:07 +01:00
parent d5ecaa186d
commit 117ba118af
10 changed files with 486 additions and 0 deletions

View File

@ -39,6 +39,7 @@ namespace ZoneCodeGeneratorTests.Parsing.Matching.Matchers
var matchResult = new TokenMatchingResult(true, 1);
matchResult.AddNamedMatch(LoopToken, "test");
matchResult.AppendTag("testTag");
return matchResult;
});
@ -182,5 +183,50 @@ namespace ZoneCodeGeneratorTests.Parsing.Matching.Matchers
foreach(var namedMatch in namedMatches)
Assert.AreEqual("test", namedMatch);
}
[TestMethod]
public void EnsureMakesCorrectUseOfTokenOffset()
{
testsUntilUnsuccessful = 2;
var groupLoop = new MatcherGroupLoop(MatcherGroupLoop.LoopMode.OneMultiple, tokenMatcherMock.Object);
var result = groupLoop.Test(matchingContext, 4);
tokenMatcherMock.Verify(matcher => matcher.Test(It.IsAny<MatchingContext>(), 4));
tokenMatcherMock.Verify(matcher => matcher.Test(It.IsAny<MatchingContext>(), 5));
tokenMatcherMock.Verify(matcher => matcher.Test(It.IsAny<MatchingContext>(), 6));
tokenMatcherMock.VerifyNoOtherCalls();
Assert.IsTrue(result.Successful);
}
[TestMethod]
public void EnsureAddsTagWhenMatched()
{
testsUntilUnsuccessful = 4;
var groupLoop = new MatcherGroupLoop(MatcherGroupLoop.LoopMode.OneMultiple, tokenMatcherMock.Object).WithTag("loopTag");
var result = groupLoop.Test(matchingContext, 0);
Assert.IsTrue(result.Successful);
Assert.AreEqual(5, result.MatchedTags.Count);
Assert.AreEqual("loopTag", result.MatchedTags[0]);
Assert.AreEqual("testTag", result.MatchedTags[1]);
Assert.AreEqual("testTag", result.MatchedTags[2]);
Assert.AreEqual("testTag", result.MatchedTags[3]);
Assert.AreEqual("testTag", result.MatchedTags[4]);
}
[TestMethod]
public void EnsureDoesNotAddTagWhenNotMatched()
{
testsUntilUnsuccessful = 1;
var groupLoop = new MatcherGroupLoop(MatcherGroupLoop.LoopMode.Multiple, tokenMatcherMock.Object).WithTag("loopTag");
var result = groupLoop.Test(matchingContext, 0);
Assert.IsFalse(result.Successful);
Assert.AreEqual(0, result.MatchedTags.Count);
}
}
}