ZoneCodeGenerator: Extend reorder test to be able to specify first member and skip any members before to start reordering from a certain point

This commit is contained in:
Jan 2019-12-03 23:39:09 +01:00
parent ce9d0d37de
commit 799a999a66

View File

@ -14,12 +14,14 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
{ {
private const string TypeNameToken = "typeName"; private const string TypeNameToken = "typeName";
private const string ReorderMemberNameToken = "member"; private const string ReorderMemberNameToken = "member";
private const string TokenFindFirst = "findFirst";
private static readonly TokenMatcher[] matchers = private static readonly TokenMatcher[] matchers =
{ {
new MatcherLiteral("reorder"), new MatcherLiteral("reorder"),
new MatcherGroupOptional(new MatcherTypename().WithName(TypeNameToken)), new MatcherGroupOptional(new MatcherTypename().WithName(TypeNameToken)),
new MatcherLiteral(":"), new MatcherLiteral(":"),
new MatcherGroupOptional(new MatcherLiteral(".", ".", ".").WithName(TokenFindFirst)),
new MatcherGroupLoop(MatcherGroupLoop.LoopMode.OneMultiple, new MatcherGroupLoop(MatcherGroupLoop.LoopMode.OneMultiple,
new MatcherName().WithName(ReorderMemberNameToken)), new MatcherName().WithName(ReorderMemberNameToken)),
new MatcherLiteral(";") new MatcherLiteral(";")
@ -71,6 +73,23 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
// Create a list that will be the sorted list at the end. // Create a list that will be the sorted list at the end.
var sortedMembers = new List<MemberInformation>(memberPool.Count); var sortedMembers = new List<MemberInformation>(memberPool.Count);
if (HasMatcherTokens(TokenFindFirst))
{
var firstMemberName = NextMatch(ReorderMemberNameToken);
var firstMember =
memberPool.FirstOrDefault(information => information.Member.Name.Equals(firstMemberName));
if (firstMember == null)
{
throw new TestFailedException(
$"Cannot find member with name '{firstMemberName}' in type '{typeToReorder.Type.FullName}'.");
}
var firstMemberIndex = memberPool.IndexOf(firstMember);
sortedMembers.AddRange(memberPool.GetRange(0, firstMemberIndex + 1));
memberPool.RemoveRange(0, firstMemberIndex + 1);
}
string nextMemberName; string nextMemberName;
while ((nextMemberName = NextMatch(ReorderMemberNameToken)) != null) while ((nextMemberName = NextMatch(ReorderMemberNameToken)) != null)
{ {