コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public AssignmentStatementHandlerController(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
     _defaultAssignmentStatementHandler = new DefaultAssignmentStatementHandler(blockParserContext);
     _specificHandlers = new AssignmentStatementHandlerBase[]
     {
         new DelegateAssignmentStatementHandler(blockParserContext),
         new IndexerAssignmentStatementHandler(blockParserContext),
         new ArrayConstructStatementHandler(blockParserContext),
         new StringBuilderConstructStatementHandler(blockParserContext)
     };
 }
        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>();
        }
コード例 #6
0
ファイル: BlocksParser.cs プロジェクト: nickaynes/test789
        public async Task <IList <dynamic> > RenderAsync(BlockParserContext context, string data)
        {
            var shapes = new List <dynamic>();

            foreach (var block in JsonConvert.DeserializeObject <EditorBlocks>(data).Blocks)
            {
                if (!_parsers.ContainsKey(block.Type))
                {
                    continue;
                }

                try
                {
                    shapes.Add(await _parsers[block.Type].RenderAsync(context, block));
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Failed to render {block.Type} block.");
                }
            }

            return(shapes);
        }
コード例 #7
0
 public IndexerAssignmentStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
コード例 #8
0
 public IndexerAssignmentStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
コード例 #9
0
 public ArrayConstructStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
コード例 #10
0
 public BranchStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
 public StringBuilderConstructStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
コード例 #12
0
 public StatementHandlerDictionaryBuilder(BlockParserContext blockParserContext)
 {
     _blockParserContext = blockParserContext;
 }
コード例 #13
0
 public DelegateAssignmentStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
コード例 #14
0
 public StatementHandlerDictionaryBuilder(BlockParserContext blockParserContext)
 {
     _blockParserContext = blockParserContext;
 }
コード例 #15
0
 protected AssignmentStatementHandlerBase(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
コード例 #16
0
 protected StatementHandlerBase(BlockParserContext blockParserContext)
 {
     _blockParserContext = blockParserContext;
 }
コード例 #17
0
 public ReturnStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
コード例 #18
0
 public DelegateAssignmentStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
コード例 #19
0
 public StringBuilderConstructStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
コード例 #20
0
 public ExpressionStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }
コード例 #21
0
 public ArrayConstructStatementHandler(BlockParserContext blockParserContext)
     : base(blockParserContext)
 {
 }