mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
ZoneCodeGenerator: Add tests for Matchers to test TokenOffset and Tag behaviour
This commit is contained in:
@ -95,5 +95,98 @@ namespace ZoneCodeGeneratorTests.Parsing.Matching.Matchers
|
||||
Assert.AreEqual(1, result.ConsumedTokenCount);
|
||||
Assert.AreEqual("const", result.NamedMatches["test_token"].ElementAtOrDefault(0));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EnsureMatcherWithMultipleLiteralTokensMatchesWhenAllAreFound()
|
||||
{
|
||||
tokens.AddRange(new List<string>
|
||||
{
|
||||
"const", "range", "of", "turtles"
|
||||
});
|
||||
|
||||
var matcher = new MatcherLiteral("const", "range");
|
||||
var result = matcher.Test(matchingContext, 0);
|
||||
|
||||
Assert.IsTrue(result.Successful);
|
||||
Assert.AreEqual(2, result.ConsumedTokenCount);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EnsureMatcherWithMultipleLiteralTokensDoesNotMatchWhenFirstTokenIsDifferent()
|
||||
{
|
||||
tokens.AddRange(new List<string>
|
||||
{
|
||||
"static", "range", "of", "turtles"
|
||||
});
|
||||
|
||||
var matcher = new MatcherLiteral("const", "range");
|
||||
var result = matcher.Test(matchingContext, 0);
|
||||
|
||||
Assert.IsFalse(result.Successful);
|
||||
Assert.AreEqual(0, result.ConsumedTokenCount);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EnsureMatcherWithMultipleLiteralTokensDoesNotMatchWhenSecondTokenIsDifferent()
|
||||
{
|
||||
tokens.AddRange(new List<string>
|
||||
{
|
||||
"const", "element", "of", "turtles"
|
||||
});
|
||||
|
||||
var matcher = new MatcherLiteral("const", "const");
|
||||
var result = matcher.Test(matchingContext, 0);
|
||||
|
||||
Assert.IsFalse(result.Successful);
|
||||
Assert.AreEqual(0, result.ConsumedTokenCount);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EnsureMakesCorrectUseOfTokenOffset()
|
||||
{
|
||||
tokens.AddRange(new List<string>
|
||||
{
|
||||
"strawberry", "cake", "is", "yummy"
|
||||
});
|
||||
|
||||
var matcher = new MatcherLiteral("cake");
|
||||
var result = matcher.Test(matchingContext, 1);
|
||||
|
||||
Assert.IsTrue(result.Successful);
|
||||
Assert.AreEqual(1, result.ConsumedTokenCount);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EnsureAddsTagWhenMatched()
|
||||
{
|
||||
tokens.AddRange(new List<string>
|
||||
{
|
||||
"strawberry"
|
||||
});
|
||||
|
||||
var matcher = new MatcherLiteral("strawberry").WithTag("strawberryMatcher");
|
||||
var result = matcher.Test(matchingContext, 0);
|
||||
|
||||
Assert.IsTrue(result.Successful);
|
||||
Assert.AreEqual(1, result.ConsumedTokenCount);
|
||||
Assert.AreEqual(1, result.MatchedTags.Count);
|
||||
Assert.AreEqual("strawberryMatcher", result.MatchedTags[0]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EnsureDoesNotAddTagWhenNotMatched()
|
||||
{
|
||||
tokens.AddRange(new List<string>
|
||||
{
|
||||
"apple"
|
||||
});
|
||||
|
||||
var matcher = new MatcherLiteral("strawberry").WithTag("strawberryMatcher");
|
||||
var result = matcher.Test(matchingContext, 0);
|
||||
|
||||
Assert.IsFalse(result.Successful);
|
||||
Assert.AreEqual(0, result.ConsumedTokenCount);
|
||||
Assert.AreEqual(0, result.MatchedTags.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user