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); }
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 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>(); }
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); }
public IndexerAssignmentStatementHandler(BlockParserContext blockParserContext) : base(blockParserContext) { }
public ArrayConstructStatementHandler(BlockParserContext blockParserContext) : base(blockParserContext) { }
public BranchStatementHandler(BlockParserContext blockParserContext) : base(blockParserContext) { }
public StringBuilderConstructStatementHandler(BlockParserContext blockParserContext) : base(blockParserContext) { }
public StatementHandlerDictionaryBuilder(BlockParserContext blockParserContext) { _blockParserContext = blockParserContext; }
public DelegateAssignmentStatementHandler(BlockParserContext blockParserContext) : base(blockParserContext) { }
protected AssignmentStatementHandlerBase(BlockParserContext blockParserContext) : base(blockParserContext) { }
protected StatementHandlerBase(BlockParserContext blockParserContext) { _blockParserContext = blockParserContext; }
public ReturnStatementHandler(BlockParserContext blockParserContext) : base(blockParserContext) { }
public ExpressionStatementHandler(BlockParserContext blockParserContext) : base(blockParserContext) { }