示例#1
0
        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());
        }
示例#2
0
        public void NextTokenShouldNotReturnWhiteSpaceToken()
        {
            TokenBase identifier = TokenCreator.Create <IdentifierToken>("test");
            TokenBase space      = TokenCreator.Create <SpaceToken>();

            StatementBase classStatement  = StatementCreator.CreateClassStatement();
            StatementBase memberStatement = StatementCreator.CreateMemberStatement("test");

            IList <TokenBase> totalList = new List <TokenBase>();

            foreach (TokenBase aToken in classStatement.Tokens)
            {
                totalList.Add(aToken);
            }
            foreach (TokenBase aToken in memberStatement.Tokens)
            {
                totalList.Add(aToken);
            }
            totalList.Add(space);
            totalList.Add(identifier);

            IList <TokenBase> identifierList = new List <TokenBase>();

            identifierList.Add(space);
            identifierList.Add(identifier);

            _manager.Encountered(new[] { classStatement }, classStatement.Tokens.Count(), totalList);
            Assert.AreEqual(identifier, _manager.GetContext(memberStatement.Tokens).NextTokenFromCurrentStatement);
        }
示例#3
0
        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);
        }
示例#4
0
        public void MemberStatementShouldNotRequireAccessModifier()
        {
            Expect.Call(_context.Parents).Return(new[] { new StatementParent(StatementCreator.CreateClassStatement(), StatementCreator.CreateOpenBlockStatement()) }).Repeat.Once();

            IList <TokenBase> input = new List <TokenBase>();

            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();
        }
示例#5
0
        public void MemberStatementFactoryShouldNotCreateClass()
        {
            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 <ClassToken>());
            input.Add(TokenCreator.Create <SpaceToken>());
            input.Add(TokenCreator.Create <IdentifierToken>("t"));

            Mocker.ReplayAll();
            Assert.IsFalse(_factory.CanCreateStatementFrom(input, _context));
            Mocker.VerifyAll();
        }
示例#6
0
        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();
        }
示例#7
0
        public void MethodStatementFactoryShouldCreateMethodWithValueTypeReturnToken()
        {
            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 <ValueTypeToken>("bool"));
            input.Add(TokenCreator.Create <SpaceToken>());
            input.Add(TokenCreator.Create <IdentifierToken>("t"));
            input.Add(TokenCreator.Create <OpenRoundBracketToken>());
            input.Add(TokenCreator.Create <CloseRoundBracketToken>());

            Mocker.ReplayAll();
            Assert.IsTrue(_factory.CanCreateStatementFrom(input, _context));
            Mocker.VerifyAll();
        }
        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 RuleShouldBeValidForElementWithExplicitAccessModifier()
 {
     Assert.IsTrue(_rule.IsValidFor(StatementCreator.CreateClassStatement()));
 }
 public void ExplicitAccessModifierRuleShouldValidateClasses()
 {
     Assert.IsTrue(_rule.Validates(StatementCreator.CreateClassStatement()));
 }