public void Build_ReturnsAllStatementHandlersNeededByBlockParser()
        {
            MockRepository mocks = new MockRepository();
              IBlacklistManager blacklistManager = mocks.Stub<IBlacklistManager>();
              IProblemPipe problemPipe = mocks.Stub<IProblemPipe>();
              BlockParserContext blockParserContext = new BlockParserContext (
              problemPipe,
              Fragment.CreateNamed ("returnFragmentType"),
              new List<ReturnCondition>(),
              blacklistManager,
              delegate { });
              StatementHandlerDictionaryBuilder builder = new StatementHandlerDictionaryBuilder (blockParserContext);

              Dictionary<Type, IStatementHandler> handlers = builder.Build();
              bool assignmentStatementSupported = handlers.ContainsKey (typeof (AssignmentStatement));
              bool branchSupported = handlers.ContainsKey (typeof (Branch));
              bool expressionStatementSupported = handlers.ContainsKey (typeof (ExpressionStatement));
              bool returnNodeSupported = handlers.ContainsKey (typeof (ReturnNode));
              bool switchInstructionSupported = handlers.ContainsKey (typeof (SwitchInstruction));

              bool necessaryHandlersSupported = assignmentStatementSupported
                                        && branchSupported
                                        && expressionStatementSupported
                                        && returnNodeSupported
                                        && switchInstructionSupported;

              bool correctHandlerCount = handlers.Keys.Count == 5;

              Assert.That (necessaryHandlersSupported && correctHandlerCount, Is.True);
        }
        public void ArrayConstructIsParsed()
        {
            MockRepository mocks = new MockRepository();
              IBlacklistManager blacklistManager = mocks.Stub<IBlacklistManager>();
              Dictionary<string, bool> locallyInitializedArrays = new Dictionary<string, bool>();
              BlockParserContext blockParserContext = new BlockParserContext (
              new ProblemPipeStub(),
              Fragment.CreateNamed ("returnFragmentType"),
              new List<ReturnCondition>(),
              blacklistManager,
              delegate { });
              ArrayConstructStatementHandler handler = new ArrayConstructStatementHandler (blockParserContext);

              Method sampleMethod = IntrospectionUtility.MethodFactory<ArrayConstructStatementHandlerSample> ("LocallyInitializedArray");
              Block sampleBlock = (Block) sampleMethod.Body.Statements[0];
              Statement sample = sampleBlock.Statements[1];

              ISymbolTable symbolTable = mocks.Stub<ISymbolTable>();
              HandleContext context = new HandleContext (
              sample,
              symbolTable,
              new List<IPreCondition>(),
              new List<string>(),
              new List<BlockAssignment>(),
              new List<int>(),
              locallyInitializedArrays,
              new Dictionary<string, bool>());
              handler.Handle (context);

              bool locallyInitializedArrayAdded = locallyInitializedArrays.ContainsKey ("local$2") && locallyInitializedArrays["local$2"] == false;
              Assert.That (locallyInitializedArrayAdded, Is.True);
        }
        public void Handle_WrongStatementType_ThrowsException()
        {
            MockRepository mocks = new MockRepository();
              IBlacklistManager blacklistManager = mocks.Stub<IBlacklistManager>();
              BlockParserContext blockParserContext = new BlockParserContext (
              new ProblemPipeStub(),
              Fragment.CreateNamed ("returnFragmentType"),
              new List<ReturnCondition>(),
              blacklistManager,
              delegate { });

              StatementHandlerBase<AssignmentStatement> handler = new AssignmentStatementHandlerController (blockParserContext);
              Method sampleMethod = IntrospectionUtility.MethodFactory<StatementHandlerBaseSample> ("ContainsReturnStatement");
              Block sampleBlock = (Block) sampleMethod.Body.Statements[1];
              Statement sample = sampleBlock.Statements[0];

              ISymbolTable symbolTable = mocks.Stub<ISymbolTable>();
              HandleContext context = new HandleContext (
              sample,
              symbolTable,
              new List<IPreCondition>(),
              new List<string>(),
              new List<BlockAssignment>(),
              new List<int>(),
              new Dictionary<string, bool>(),
              new Dictionary<string, bool>());
              handler.Handle (context);
        }
Esempio n. 4
0
 public BlockParser(
 IBlacklistManager blacklistManager, IProblemPipe problemPipe, Fragment returnFragmentType, List<ReturnCondition> returnConditions)
 {
     _blacklistManager = ArgumentUtility.CheckNotNull ("blacklistManager", blacklistManager);
       _problemPipe = ArgumentUtility.CheckNotNull ("typeParser", problemPipe);
       _returnFragmentType = returnFragmentType;
       _returnConditions = returnConditions;
       BlockParserContext blockParserContext = new BlockParserContext (
       _problemPipe, _returnFragmentType, _returnConditions, _blacklistManager, Inspect
       );
       StatementHandlerDictionaryBuilder handlerBuilder = new StatementHandlerDictionaryBuilder (blockParserContext);
       _statementHandlers = handlerBuilder.Build();
       _methodCallAnalyzer = new MethodCallAnalyzer (_problemPipe);
 }
Esempio n. 5
0
        public BlockParser(
            IBlacklistManager blacklistManager, IProblemPipe problemPipe, Fragment returnFragmentType, List <ReturnCondition> returnConditions)
        {
            _blacklistManager   = ArgumentUtility.CheckNotNull("blacklistManager", blacklistManager);
            _problemPipe        = ArgumentUtility.CheckNotNull("typeParser", problemPipe);
            _returnFragmentType = returnFragmentType;
            _returnConditions   = returnConditions;
            BlockParserContext blockParserContext = new BlockParserContext(
                _problemPipe, _returnFragmentType, _returnConditions, _blacklistManager, Inspect
                );
            StatementHandlerDictionaryBuilder handlerBuilder = new StatementHandlerDictionaryBuilder(blockParserContext);

            _statementHandlers  = handlerBuilder.Build();
            _methodCallAnalyzer = new MethodCallAnalyzer(_problemPipe);
        }
        public void SetUp()
        {
            MockRepository mocks = new MockRepository();
              IBlacklistManager blacklistManager = mocks.Stub<IBlacklistManager>();
              BlockParserContext blockParserContext = new BlockParserContext (
              new ProblemPipeStub(),
              Fragment.CreateNamed ("returnFragmentType"),
              new List<ReturnCondition>(),
              blacklistManager,
              delegate { });

              _handler = new StringBuilderConstructStatementHandler (blockParserContext);
              _symbolTable = new SymbolTable (blacklistManager);
              _stringBuilderFragmentTypesDefined = new Dictionary<string, bool>();
        }