From f2cc95ee327967233c737d938c46ed4b4e07bde3 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 10 Nov 2019 18:04:00 +0100 Subject: [PATCH] ZoneCodeGenerator: Make use of the parsed tokens in TestCount and TestCondition --- .../Domain/Evaluation/OperandDynamic.cs | 17 +++- .../MemberInformation.cs | 6 +- .../StructureInformation.cs | 2 +- .../Generating/CodeGenerator.cs | 2 +- .../Generating/RenderingContext.cs | 2 +- .../CommandFile/ICommandParserState.cs | 7 +- .../CommandFile/Impl/CommandParserState.cs | 78 ++++++++++++++++++- .../CommandFile/Tests/TestCondition.cs | 43 +++++++++- .../Parsing/CommandFile/Tests/TestCount.cs | 51 +++++++++++- .../Parsing/CommandFile/Tests/TestUse.cs | 12 ++- .../CommandFile/Tests/TestWithEvaluation.cs | 73 +++++++++++++---- .../Persistence/IReadOnlyDataRepository.cs | 2 +- .../Persistence/InMemoryDataRepository.cs | 2 +- .../CommandFile/Tests/TestAssetTest.cs | 2 +- .../Parsing/CommandFile/Tests/TestUseTest.cs | 17 ++-- 15 files changed, 275 insertions(+), 41 deletions(-) rename src/ZoneCodeGenerator/Domain/{StructureInformation => Information}/MemberInformation.cs (70%) rename src/ZoneCodeGenerator/Domain/{StructureInformation => Information}/StructureInformation.cs (96%) diff --git a/src/ZoneCodeGenerator/Domain/Evaluation/OperandDynamic.cs b/src/ZoneCodeGenerator/Domain/Evaluation/OperandDynamic.cs index e9bec194..2b2e559a 100644 --- a/src/ZoneCodeGenerator/Domain/Evaluation/OperandDynamic.cs +++ b/src/ZoneCodeGenerator/Domain/Evaluation/OperandDynamic.cs @@ -1,14 +1,25 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using ZoneCodeGenerator.Domain.Information; namespace ZoneCodeGenerator.Domain.Evaluation { class OperandDynamic : IEvaluation { + public StructureInformation Structure { get; } + public IList ReferencedMemberChain { get; } + public IList ArrayIndices { get; } + public bool IsStatic => false; + + public OperandDynamic(StructureInformation structure, IEnumerable memberChain) + { + Structure = structure; + ReferencedMemberChain = new List(memberChain); + ArrayIndices = new List(); + } + public int EvaluateNumeric() { throw new Exception("A dynamic operand cannot be evaluated."); @@ -16,7 +27,7 @@ namespace ZoneCodeGenerator.Domain.Evaluation public override string ToString() { - return "dynamic"; + return $"{Structure.Type.FullName}::{string.Join("::", ReferencedMemberChain.Select(information => information.Member.Name))}{string.Concat(ArrayIndices.Select(i => $"[{i}]"))}"; } } } diff --git a/src/ZoneCodeGenerator/Domain/StructureInformation/MemberInformation.cs b/src/ZoneCodeGenerator/Domain/Information/MemberInformation.cs similarity index 70% rename from src/ZoneCodeGenerator/Domain/StructureInformation/MemberInformation.cs rename to src/ZoneCodeGenerator/Domain/Information/MemberInformation.cs index e377b872..30444395 100644 --- a/src/ZoneCodeGenerator/Domain/StructureInformation/MemberInformation.cs +++ b/src/ZoneCodeGenerator/Domain/Information/MemberInformation.cs @@ -1,16 +1,20 @@ -namespace ZoneCodeGenerator.Domain.StructureInformation +using ZoneCodeGenerator.Domain.Evaluation; + +namespace ZoneCodeGenerator.Domain.Information { class MemberInformation { public StructureInformation StructureType { get; } public Variable Member { get; set; } public bool IsScriptString { get; set; } + public IEvaluation Condition { get; set; } public MemberInformation(Variable member, StructureInformation structureType) { Member = member; StructureType = structureType; IsScriptString = false; + Condition = null; } } } diff --git a/src/ZoneCodeGenerator/Domain/StructureInformation/StructureInformation.cs b/src/ZoneCodeGenerator/Domain/Information/StructureInformation.cs similarity index 96% rename from src/ZoneCodeGenerator/Domain/StructureInformation/StructureInformation.cs rename to src/ZoneCodeGenerator/Domain/Information/StructureInformation.cs index dd805455..bd65c692 100644 --- a/src/ZoneCodeGenerator/Domain/StructureInformation/StructureInformation.cs +++ b/src/ZoneCodeGenerator/Domain/Information/StructureInformation.cs @@ -4,7 +4,7 @@ using System.Linq; using ZoneCodeGenerator.Domain.FastFileStructure; using ZoneCodeGenerator.Persistence; -namespace ZoneCodeGenerator.Domain.StructureInformation +namespace ZoneCodeGenerator.Domain.Information { class StructureInformation { diff --git a/src/ZoneCodeGenerator/Generating/CodeGenerator.cs b/src/ZoneCodeGenerator/Generating/CodeGenerator.cs index 4e4f68c1..30534e9e 100644 --- a/src/ZoneCodeGenerator/Generating/CodeGenerator.cs +++ b/src/ZoneCodeGenerator/Generating/CodeGenerator.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.IO; -using ZoneCodeGenerator.Domain.StructureInformation; +using ZoneCodeGenerator.Domain.Information; using ZoneCodeGenerator.Interface; using ZoneCodeGenerator.Persistence; diff --git a/src/ZoneCodeGenerator/Generating/RenderingContext.cs b/src/ZoneCodeGenerator/Generating/RenderingContext.cs index 04b20426..4b9cfd05 100644 --- a/src/ZoneCodeGenerator/Generating/RenderingContext.cs +++ b/src/ZoneCodeGenerator/Generating/RenderingContext.cs @@ -3,7 +3,7 @@ using System.IO; using System.Linq; using ZoneCodeGenerator.Domain; using ZoneCodeGenerator.Domain.FastFileStructure; -using ZoneCodeGenerator.Domain.StructureInformation; +using ZoneCodeGenerator.Domain.Information; using ZoneCodeGenerator.Interface; using ZoneCodeGenerator.Persistence; diff --git a/src/ZoneCodeGenerator/Parsing/CommandFile/ICommandParserState.cs b/src/ZoneCodeGenerator/Parsing/CommandFile/ICommandParserState.cs index e4b19c61..7d00d613 100644 --- a/src/ZoneCodeGenerator/Parsing/CommandFile/ICommandParserState.cs +++ b/src/ZoneCodeGenerator/Parsing/CommandFile/ICommandParserState.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using ZoneCodeGenerator.Domain; using ZoneCodeGenerator.Domain.FastFileStructure; +using ZoneCodeGenerator.Domain.Information; using ZoneCodeGenerator.Persistence; namespace ZoneCodeGenerator.Parsing.CommandFile @@ -10,6 +11,10 @@ namespace ZoneCodeGenerator.Parsing.CommandFile string Game { get; set; } IReadOnlyDataRepository Repository { get; } List FastFileBlocks { get; } - DataTypeWithMembers DataTypeInUse { get; set; } + StructureInformation DataTypeInUse { get; set; } + + bool GetMembersFromParts(string[] parts, StructureInformation baseType, out List members); + bool GetTypenameAndMembersFromParts(string[] parts, out StructureInformation typeInformation, + out List members); } } diff --git a/src/ZoneCodeGenerator/Parsing/CommandFile/Impl/CommandParserState.cs b/src/ZoneCodeGenerator/Parsing/CommandFile/Impl/CommandParserState.cs index b0af95ab..9fb7d280 100644 --- a/src/ZoneCodeGenerator/Parsing/CommandFile/Impl/CommandParserState.cs +++ b/src/ZoneCodeGenerator/Parsing/CommandFile/Impl/CommandParserState.cs @@ -1,6 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using ZoneCodeGenerator.Domain; using ZoneCodeGenerator.Domain.FastFileStructure; +using ZoneCodeGenerator.Domain.Information; using ZoneCodeGenerator.Interface; using ZoneCodeGenerator.Parsing.CommandFile.Tests; using ZoneCodeGenerator.Parsing.Testing; @@ -25,7 +28,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Impl public string Game { get; set; } public IReadOnlyDataRepository Repository { get; } public List FastFileBlocks { get; } - public DataTypeWithMembers DataTypeInUse { get; set; } + public StructureInformation DataTypeInUse { get; set; } public CommandParserState(IReadOnlyDataRepository repository) { @@ -50,5 +53,76 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Impl return true; } + + private bool FindTypenameParts(string[] parts, out DataTypeWithMembers dataTypeWithMembers, out int typeNamePartCount) + { + typeNamePartCount = 1; + while (typeNamePartCount <= parts.Length) + { + var currentTypeName = string.Join("::", parts, 0, typeNamePartCount); + var foundDataType = Repository.GetDataTypeByName(currentTypeName); + + if (foundDataType != null) + { + if (!(foundDataType is DataTypeWithMembers foundDataTypeWithMembers)) + { + throw new TestFailedException($"Referenced type '{currentTypeName}' needs to be a data type with members to be used in an evaluation."); + } + + dataTypeWithMembers = foundDataTypeWithMembers; + return true; + } + + typeNamePartCount++; + } + + dataTypeWithMembers = null; + return false; + } + + public bool GetMembersFromParts(string[] parts, StructureInformation baseType, out List members) + { + members = new List(); + var currentStructure = baseType; + foreach (var part in parts) + { + var member = currentStructure.OrderedMembers.FirstOrDefault(information => + information.Member.Name.Equals(part)); + + if (member == null) + { + members = null; + return false; + } + + members.Add(member); + currentStructure = member.StructureType; + } + + return true; + } + + public bool GetTypenameAndMembersFromParts(string[] parts, out StructureInformation typeInformation, + out List members) + { + if (!FindTypenameParts(parts, out var type, out var typeNamePartCount)) + { + typeInformation = null; + members = null; + return false; + } + + typeInformation = Repository.GetInformationFor(type); + if (typeInformation == null) + { + members = null; + return false; + } + + var memberParts = new string[parts.Length - typeNamePartCount]; + Array.Copy(parts, typeNamePartCount, memberParts, 0, memberParts.Length); + + return GetMembersFromParts(memberParts, typeInformation, out members); + } } } diff --git a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCondition.cs b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCondition.cs index 56a87aaf..91f646a2 100644 --- a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCondition.cs +++ b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCondition.cs @@ -1,12 +1,19 @@ using System; +using System.Collections.Generic; +using System.Linq; +using ZoneCodeGenerator.Domain; using ZoneCodeGenerator.Domain.Evaluation; +using ZoneCodeGenerator.Domain.Information; using ZoneCodeGenerator.Parsing.Matching; using ZoneCodeGenerator.Parsing.Matching.Matchers; +using ZoneCodeGenerator.Parsing.Testing; namespace ZoneCodeGenerator.Parsing.CommandFile.Tests { class TestCondition : TestWithEvaluation { + private StructureInformation referencedType; + private const string TagAlways = "always"; private const string TagNever = "never"; private const string TypeNameToken = "typeName"; @@ -27,11 +34,33 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests public TestCondition() : base(matchers) { - } protected override void ProcessMatch(ICommandParserState state) { + var typeName = NextMatch(TypeNameToken); + var typeNameParts = typeName.Split(new[] {"::"}, StringSplitOptions.None); + + if (state.DataTypeInUse != null + && state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out var typeMembers)) + { + referencedType = state.DataTypeInUse; + } + else if (state.GetTypenameAndMembersFromParts(typeNameParts, out referencedType, out typeMembers)) + { + // Do nothing + } + else + { + throw new TestFailedException($"Could not find type/members '{typeName}'"); + } + + if (typeMembers == null + || !typeMembers.Any()) + { + throw new TestFailedException("Can only set conditions for members and not for types."); + } + IEvaluation evaluation; switch (NextTag()) { @@ -51,7 +80,19 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests throw new Exception("Unexpected Tag in TestCondition"); } + var referencedMember = typeMembers.Last(); + referencedMember.Condition = evaluation; + } + protected override IEnumerable GetUsedTypes(ICommandParserState state) + { + if (state.DataTypeInUse != null + && state.DataTypeInUse != referencedType) + { + return new[] {state.DataTypeInUse, referencedType}; + } + + return new[] {referencedType}; } } } \ No newline at end of file diff --git a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCount.cs b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCount.cs index dd9484b6..7dc63298 100644 --- a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCount.cs +++ b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestCount.cs @@ -1,11 +1,17 @@ using System; +using System.Collections.Generic; +using System.Linq; +using ZoneCodeGenerator.Domain; +using ZoneCodeGenerator.Domain.Information; using ZoneCodeGenerator.Parsing.Matching; using ZoneCodeGenerator.Parsing.Matching.Matchers; +using ZoneCodeGenerator.Parsing.Testing; namespace ZoneCodeGenerator.Parsing.CommandFile.Tests { class TestCount : TestWithEvaluation { + private StructureInformation referencedType; private const string TypeNameToken = "typeName"; // set count ; @@ -25,12 +31,53 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests protected override void ProcessMatch(ICommandParserState state) { - if (!NextTag().Equals(TagEvaluation)) + var typeName = NextMatch(TypeNameToken); + var typeNameParts = typeName.Split(new[] { "::" }, StringSplitOptions.None); + if (state.DataTypeInUse != null + && state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out var typeMembers)) { - throw new Exception("Expected first count tag to be a calculation statement"); + referencedType = state.DataTypeInUse; + } + else if (state.GetTypenameAndMembersFromParts(typeNameParts, out referencedType, out typeMembers)) + { + // Do nothing + } + else + { + throw new TestFailedException($"Could not find type/members '{typeName}'"); } + if (typeMembers == null + || !typeMembers.Any()) + { + throw new TestFailedException("Can only set count for members and not for types."); + } + + if (!NextTag().Equals(TagEvaluation)) + throw new Exception("Expected first count tag to be a calculation statement"); + var evaluation = ProcessEvaluation(state); + + var referencedMember = typeMembers.Last(); + var reference = referencedMember.Member.VariableType.References.OfType() + .LastOrDefault(); + + if (reference != null) + reference.Count = evaluation; + else + throw new TestFailedException( + $"Member '{referencedMember.Member.Name}' of type '{referencedMember.Member.VariableType.Type.FullName}' cannot have its count set due to it not having a pointer reference"); + } + + protected override IEnumerable GetUsedTypes(ICommandParserState state) + { + if (state.DataTypeInUse != null + && state.DataTypeInUse != referencedType) + { + return new[] { state.DataTypeInUse, referencedType }; + } + + return new[] { referencedType }; } } } \ No newline at end of file diff --git a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestUse.cs b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestUse.cs index 8752f894..a990ed0f 100644 --- a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestUse.cs +++ b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestUse.cs @@ -1,4 +1,5 @@ -using ZoneCodeGenerator.Domain; +using System; +using ZoneCodeGenerator.Domain; using ZoneCodeGenerator.Parsing.Matching; using ZoneCodeGenerator.Parsing.Matching.Matchers; using ZoneCodeGenerator.Parsing.Testing; @@ -35,7 +36,14 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests throw new TestFailedException($"To use data type '{typeName}' it must either be a struct or a union."); } - state.DataTypeInUse = dataTypeWithMembersToUse; + var dataTypeToUseInformation = state.Repository.GetInformationFor(dataTypeWithMembersToUse); + + if (dataTypeToUseInformation == null) + { + throw new Exception($"Could not find information for type '{dataTypeWithMembersToUse.FullName}'"); + } + + state.DataTypeInUse = dataTypeToUseInformation; } } } diff --git a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestWithEvaluation.cs b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestWithEvaluation.cs index 6ddd0f44..3a9c6994 100644 --- a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestWithEvaluation.cs +++ b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestWithEvaluation.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using ZoneCodeGenerator.Domain.Evaluation; +using ZoneCodeGenerator.Domain.Information; using ZoneCodeGenerator.Parsing.Matching; using ZoneCodeGenerator.Parsing.Matching.Matchers; using ZoneCodeGenerator.Parsing.Testing; @@ -72,32 +73,70 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests AddTaggedMatcher(evaluation); } + private IEvaluation ProcessOperandNumber(ICommandParserState state) + { + var numberString = NextMatch(TokenOperandNumber); + return new OperandStatic(int.Parse(numberString)); + } + + protected abstract IEnumerable GetUsedTypes(ICommandParserState state); + + private IEvaluation ProcessOperandTypename(ICommandParserState state) + { + var typenameString = NextMatch(TokenOperandTypename); + var arrayIndexStrings = new List(); + + while (PeekTag().Equals(TagOperandArray)) + { + NextTag(); + arrayIndexStrings.Add(NextMatch(TokenOperandArray)); + } + + var nameParts = typenameString.Split(new[] { "::" }, StringSplitOptions.None); + List referencedMemberChain = null; + + var referencedType = GetUsedTypes(state) + .FirstOrDefault(usedType => state.GetMembersFromParts(nameParts, usedType, out referencedMemberChain)); + + if (referencedType == null) + { + if (!state.GetTypenameAndMembersFromParts(nameParts, out referencedType, + out referencedMemberChain)) + { + throw new TestFailedException($"Could not evaluate '{typenameString}'."); + } + } + + if (!referencedMemberChain.Any()) + { + throw new TestFailedException($"Typename '{typenameString}' needs to reference a member at this place."); + } + + var operandDynamic = new OperandDynamic(referencedType, referencedMemberChain); + + foreach (var arrayIndexString in arrayIndexStrings) + { + operandDynamic.ArrayIndices.Add(int.Parse(arrayIndexString)); + } + + return operandDynamic; + } + private IEvaluation ProcessOperand(ICommandParserState state) { var operandTypeTag = NextTag(); if (operandTypeTag.Equals(TagOperandNumber)) { - var numberString = NextMatch(TokenOperandNumber); - return new OperandStatic(int.Parse(numberString)); + return ProcessOperandNumber(state); } - else if(operandTypeTag.Equals(TagOperandTypename)) + + if(operandTypeTag.Equals(TagOperandTypename)) { - var typenameString = NextMatch(TokenOperandTypename); - var arrayIndexStrings = new List(); - - while (PeekTag().Equals(TagOperandArray)) - { - NextTag(); - arrayIndexStrings.Add(NextMatch(TokenOperandArray)); - } - - return new OperandDynamic(); - } - else - { - throw new Exception("Unknown Operand Type"); + return ProcessOperandTypename(state); } + + throw new Exception("Unknown Operand Type"); } private OperationType ProcessOperationType(ICommandParserState state) diff --git a/src/ZoneCodeGenerator/Persistence/IReadOnlyDataRepository.cs b/src/ZoneCodeGenerator/Persistence/IReadOnlyDataRepository.cs index bc65ce3c..c48759ac 100644 --- a/src/ZoneCodeGenerator/Persistence/IReadOnlyDataRepository.cs +++ b/src/ZoneCodeGenerator/Persistence/IReadOnlyDataRepository.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using ZoneCodeGenerator.Domain; using ZoneCodeGenerator.Domain.FastFileStructure; -using ZoneCodeGenerator.Domain.StructureInformation; +using ZoneCodeGenerator.Domain.Information; namespace ZoneCodeGenerator.Persistence { diff --git a/src/ZoneCodeGenerator/Persistence/InMemoryDataRepository.cs b/src/ZoneCodeGenerator/Persistence/InMemoryDataRepository.cs index 9d74ef55..2b1f010f 100644 --- a/src/ZoneCodeGenerator/Persistence/InMemoryDataRepository.cs +++ b/src/ZoneCodeGenerator/Persistence/InMemoryDataRepository.cs @@ -2,7 +2,7 @@ using System.Linq; using ZoneCodeGenerator.Domain; using ZoneCodeGenerator.Domain.FastFileStructure; -using ZoneCodeGenerator.Domain.StructureInformation; +using ZoneCodeGenerator.Domain.Information; namespace ZoneCodeGenerator.Persistence { diff --git a/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Tests/TestAssetTest.cs b/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Tests/TestAssetTest.cs index f250e304..274258e1 100644 --- a/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Tests/TestAssetTest.cs +++ b/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Tests/TestAssetTest.cs @@ -4,7 +4,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using ZoneCodeGenerator; using ZoneCodeGenerator.Domain; -using ZoneCodeGenerator.Domain.StructureInformation; +using ZoneCodeGenerator.Domain.Information; using ZoneCodeGenerator.Parsing; using ZoneCodeGenerator.Parsing.CommandFile; using ZoneCodeGenerator.Parsing.CommandFile.Tests; diff --git a/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Tests/TestUseTest.cs b/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Tests/TestUseTest.cs index 04c8ac1b..a7cfbb41 100644 --- a/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Tests/TestUseTest.cs +++ b/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Tests/TestUseTest.cs @@ -4,6 +4,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using ZoneCodeGenerator.Domain; using ZoneCodeGenerator.Domain.FastFileStructure; +using ZoneCodeGenerator.Domain.Information; using ZoneCodeGenerator.Parsing; using ZoneCodeGenerator.Parsing.CommandFile; using ZoneCodeGenerator.Parsing.CommandFile.Tests; @@ -18,7 +19,7 @@ namespace ZoneCodeGeneratorTests.Parsing.CommandFile.Tests private Mock repositoryMock; private Mock parserStateMock; - private DataTypeWithMembers dataTypeWithMembers; + private StructureInformation usedType; private Mock lexerMock; private int tokenOffset; @@ -29,7 +30,7 @@ namespace ZoneCodeGeneratorTests.Parsing.CommandFile.Tests { parserStateMock = new Mock(); - dataTypeWithMembers = null; + usedType = null; tokenOffset = 0; tokens = new List(); @@ -39,6 +40,9 @@ namespace ZoneCodeGeneratorTests.Parsing.CommandFile.Tests parserStateMock.SetupGet(state => state.Repository) .Returns(() => repositoryMock.Object); + repositoryMock.Setup(repository => repository.GetInformationFor(It.IsAny())) + .Returns((DataTypeWithMembers type) => new StructureInformation(type)); + lexerMock.Setup(lexer => lexer.PeekToken(It.IsAny())) .Returns((int index) => tokens.ElementAtOrDefault(index + tokenOffset)); lexerMock.Setup(lexer => lexer.NextToken()) @@ -47,9 +51,9 @@ namespace ZoneCodeGeneratorTests.Parsing.CommandFile.Tests .Callback((int count) => tokenOffset += count); parserStateMock.SetupGet(state => state.DataTypeInUse) - .Returns(() => dataTypeWithMembers); - parserStateMock.SetupSet(state => state.DataTypeInUse = It.IsAny()) - .Callback((DataTypeWithMembers type) => dataTypeWithMembers = type); + .Returns(() => usedType); + parserStateMock.SetupSet(state => state.DataTypeInUse = It.IsAny()) + .Callback((StructureInformation type) => usedType = type); } [TestMethod] @@ -70,7 +74,8 @@ namespace ZoneCodeGeneratorTests.Parsing.CommandFile.Tests Assert.AreEqual(TokenTestResult.Match, test.PerformTest(parserStateMock.Object, lexerMock.Object)); Assert.AreEqual(6, test.ConsumedTokenCount); - Assert.AreEqual(assetTypeToUse, dataTypeWithMembers); + Assert.IsNotNull(assetTypeToUse); + Assert.AreEqual(usedType.Type, assetTypeToUse); } [TestMethod]