public void CloseBlockStatementShouldSetParentToTopParent() { ClassStatement classStatement = StatementCreator.CreateClassStatement(); _manager.Encountered(new[] { classStatement }, TokenCreator.Created().Count(), TokenCreator.Created()); OpenBlockStatement openBlock = StatementCreator.CreateOpenBlockStatement(); _manager.Encountered(new[] { openBlock }, TokenCreator.Created().Count(), TokenCreator.Created()); ClassStatement internalClassStatement = StatementCreator.CreateClassStatement(); _manager.Encountered(new[] { internalClassStatement }, TokenCreator.Created().Count(), TokenCreator.Created()); OpenBlockStatement secondOpenBlock = StatementCreator.CreateOpenBlockStatement(); _manager.Encountered(new[] { secondOpenBlock }, TokenCreator.Created().Count(), TokenCreator.Created()); CloseBlockStatement closeBlock = StatementCreator.CreateCloseBlockStatement(); CollectionAssert.AreEquivalent(new[] { new StatementParent(new[] { classStatement }, openBlock), new StatementParent(new[] { internalClassStatement }, secondOpenBlock) }, _manager.GetContext(closeBlock.Tokens).Parents); _manager.Encountered(new[] { closeBlock }, TokenCreator.Created().Count(), TokenCreator.Created()); CollectionAssert.AreEquivalent(new[] { new StatementParent(new[] { classStatement }, openBlock) }, _manager.GetContext(openBlock.Tokens).Parents); _manager.Encountered(new[] { closeBlock }, TokenCreator.Created().Count(), TokenCreator.Created()); }
public void OpenBlockStatementForClassShouldSetParentContextToClass() { ClassStatement classStatement = StatementCreator.CreateClassStatement(); _manager.Encountered(new[] { classStatement }, TokenCreator.Created().Count(), TokenCreator.Created()); Assert.AreEqual(0, _manager.GetContext(classStatement.Tokens).Parents.Count()); OpenBlockStatement openBlock = StatementCreator.CreateOpenBlockStatement(); _manager.Encountered(new[] { openBlock }, TokenCreator.Created().Count(), TokenCreator.Created()); Assert.AreEqual(new [] { new StatementParent(new[] { classStatement }, openBlock) }, _manager.GetContext(openBlock.Tokens).Parents); }
public void StatementParentsShouldBeEqual() { StatementBase alphaStatement = StatementCreator.CreateMemberStatement("test"); StatementBase alphaDelimiter = StatementCreator.CreateOpenBlockStatement(); TokenCreator.Reset(); StatementBase bravoStatement = StatementCreator.CreateMemberStatement("test"); StatementBase bravoDelimiter = StatementCreator.CreateOpenBlockStatement(); StatementParent alpha = new StatementParent(new[] { alphaStatement }, alphaDelimiter); StatementParent bravo = new StatementParent(new[] { bravoStatement }, bravoDelimiter); Assert.AreEqual(alpha, bravo); }
public void FactoryShouldCreateStatementFromThisFollowedBySquareBracketInClass() { Expect.Call(_context.Parents).Return(new[] { new StatementParent(StatementCreator.CreateClassStatement(), StatementCreator.CreateOpenBlockStatement()) }).Repeat.Once(); IList <TokenBase> input = new List <TokenBase>(); input.Add(TokenCreator.Create <PublicModifierToken>()); input.Add(TokenCreator.Create <SpaceToken>()); input.Add(TokenCreator.Create <IdentifierToken>("String")); input.Add(TokenCreator.Create <SpaceToken>()); input.Add(TokenCreator.Create <ThisToken>()); input.Add(TokenCreator.Create <OpenSquareBracketToken>()); input.Add(TokenCreator.Create <IntToken>()); input.Add(TokenCreator.Create <SpaceToken>()); input.Add(TokenCreator.Create <IdentifierToken>("index")); input.Add(TokenCreator.Create <CloseSquareBracketToken>()); Mocker.ReplayAll(); Assert.IsTrue(_factory.CanCreateStatementFrom(input, _context)); Mocker.VerifyAll(); }
public void MemberStatementFactoryShouldNotCreateFromMethod() { Expect.Call(_context.Parents).Return(new[] { new StatementParent(StatementCreator.CreateClassStatement(), StatementCreator.CreateOpenBlockStatement()) }).Repeat.Once(); IList <TokenBase> input = new List <TokenBase>(); input.Add(TokenCreator.Create <PrivateModifierToken>()); input.Add(TokenCreator.Create <SpaceToken>()); input.Add(TokenCreator.Create <IdentifierToken>("String")); input.Add(TokenCreator.Create <SpaceToken>()); input.Add(TokenCreator.Create <IdentifierToken>("t")); input.Add(TokenCreator.Create <OpenRoundBracketToken>()); input.Add(TokenCreator.Create <CloseRoundBracketToken>()); Mocker.ReplayAll(); Assert.IsFalse(_factory.CanCreateStatementFrom(input, _context)); Mocker.VerifyAll(); }
public void MemberStatementFactoryShouldCheckCreateMemberCorrectly() { Expect.Call(_context.Parents).Return(new[] { new StatementParent(StatementCreator.CreateClassStatement(), StatementCreator.CreateOpenBlockStatement()) }).Repeat.Once(); IList <TokenBase> input = new List <TokenBase>(); input.Add(TokenCreator.Create <PrivateModifierToken>()); input.Add(TokenCreator.Create <SpaceToken>()); input.Add(TokenCreator.Create <IdentifierToken>("String")); input.Add(TokenCreator.Create <SpaceToken>()); input.Add(TokenCreator.Create <IdentifierToken>("t")); input.Add(TokenCreator.Create <SemiColonToken>()); Mocker.ReplayAll(); Assert.IsTrue(_factory.CanCreateStatementFrom(input, _context)); Mocker.VerifyAll(); }
public void EventShouldNotParseAsMember() { Expect.Call(_context.Parents).Return(new[] { new StatementParent(StatementCreator.CreateClassStatement(), StatementCreator.CreateOpenBlockStatement()) }).Repeat.Once(); IList <TokenBase> input = new List <TokenBase>(); input.Add(TokenCreator.Create <EventToken>()); input.Add(TokenCreator.Create <SpaceToken>()); input.Add(TokenCreator.Create <IdentifierToken>("EventHandler")); input.Add(TokenCreator.Create <SpaceToken>()); input.Add(TokenCreator.Create <IdentifierToken>("t")); input.Add(TokenCreator.Create <SemiColonToken>()); Mocker.ReplayAll(); Assert.IsFalse(_factory.CanCreateStatementFrom(input, _context)); Mocker.VerifyAll(); }