public void ParserShouldCallSBlockFactoryWhenParsingStatements() { IList <StatementBase> input = new List <StatementBase>(); input.Add(StatementCreator.CreateMemberStatement("_someString")); IBlockFactory factory = Mocker.StrictMock <IBlockFactory>(); Expect.Call(factory.Create(input)).Return(new [] { new BlockBaseImpl(input) }).Repeat.Once(); StubBlockFactoryProvider provider = new StubBlockFactoryProvider(factory); CalidusBlockParser parser = new CalidusBlockParser(provider); Mocker.ReplayAll(); parser.Parse(input); Mocker.VerifyAll(); }
/// <summary> /// Starts the runner /// </summary> /// <param name="configFactory">The configuration factory</param> /// <param name="project">The project to run against</param> public void Run(ICalidusRuleConfigurationFactory configFactory, ICalidusProject project) { //raise started if (Started != null) { Started(this, new EventArgs()); } IList <RuleViolation> violations = new List <RuleViolation>(); CalidusTokenParser parser = new CalidusTokenParser(); CalidusStatementParser statementParser = new CalidusStatementParser(); CalidusBlockParser blockParser = new CalidusBlockParser(); CalidusLineParser lineParser = new CalidusLineParser(); CalidusRuleProvider ruleProvider = new CalidusRuleProvider(); IEnumerable <String> filesToCheck = project.GetSourceFilesToValidate(); int currentFile = 0; int totalFiles = filesToCheck.Count(); foreach (String aFile in filesToCheck) { currentFile++; IEnumerable <TokenBase> parsedTokens = parser.Parse(File.ReadAllText(aFile)); IEnumerable <StatementBase> parsedStatements = statementParser.Parse(parsedTokens); IEnumerable <BlockBase> parsedBlocks = blockParser.Parse(parsedStatements); IEnumerable <LineBase> parsedLines = lineParser.Parse(parsedTokens); IList <RuleViolation> currentFileViolations = new List <RuleViolation>(); foreach (StatementRuleBase aStatementRule in ruleProvider.GetStatementRules(configFactory)) { foreach (StatementBase aStatement in parsedStatements) { if (aStatementRule.Validates(aStatement)) { if (aStatementRule.IsValidFor(aStatement) == false) { currentFileViolations.Add(new RuleViolation(aFile, aStatementRule, aStatement)); } } } } foreach (BlockRuleBase aBlockRule in ruleProvider.GetBlockRules(configFactory)) { foreach (BlockBase aBlock in parsedBlocks) { if (aBlockRule.Validates(aBlock)) { if (aBlockRule.IsValidFor(aBlock) == false) { currentFileViolations.Add(new RuleViolation(aFile, aBlockRule, aBlock.Statements.ElementAt(0))); } } } } foreach (LineRuleBase aLineRule in ruleProvider.GetLineRules(configFactory)) { foreach (LineBase aLine in parsedLines) { if (aLineRule.Validates(aLine)) { if (aLineRule.IsValidFor(aLine) == false) { currentFileViolations.Add(new RuleViolation(aFile, aLineRule, aLine.Tokens)); } } } } //raise file completed FileCompletedEventArgs args = new FileCompletedEventArgs(aFile, currentFile, totalFiles, currentFileViolations); if (FileCompleted != null) { FileCompleted(this, args); } //add violations to whole list foreach (RuleViolation aViolation in currentFileViolations) { violations.Add(aViolation); } } //raise completed if (Completed != null) { Completed(this, new RuleRunnerEventArgs(violations)); } }
private void cmdParse_Click(object sender, EventArgs e) { CalidusTokenParser tokenParser = new CalidusTokenParser(); CalidusStatementParser statementParser = new CalidusStatementParser(); CalidusBlockParser blockParser = new CalidusBlockParser(); CalidusLineParser lineParser = new CalidusLineParser(); int genericToken = 0; int genericStatement = 0; IEnumerable <TokenBase> parsedTokens = null; try { parsedTokens = tokenParser.Parse(rtSource.Text); _currentTokens.Clear(); foreach (TokenBase aToken in parsedTokens) { if (aToken is GenericToken) { genericToken++; } _currentTokens.Add(new VisualiserToken(aToken)); } } catch (CalidusException ex) { MessageBox.Show("Errors occured during token parsing: " + ex.Message); lstTokenList.Enabled = false; lstTokenDetails.DataSource = null; lstTokenList.DataSource = null; } IEnumerable <StatementBase> parsedStatements = null; try { if (parsedTokens != null) { parsedStatements = statementParser.Parse(parsedTokens); _currentStatements.Clear(); foreach (StatementBase aStatement in parsedStatements) { if (aStatement is GenericStatement) { genericStatement++; } _currentStatements.Add(new VisualiserStatement(aStatement)); } } } catch (CalidusException ex) { MessageBox.Show("Errors occured during statement parsing: " + ex.Message); lstTokenList.Enabled = false; lstTokenDetails.DataSource = null; lstTokenList.DataSource = null; lstStatementList.Enabled = false; lstStatementDetails.DataSource = null; lstStatementList.DataSource = null; } try { if (parsedStatements != null) { IEnumerable <BlockBase> parsedBlocks = blockParser.Parse(parsedStatements); _currentBlocks.Clear(); foreach (BlockBase aBlock in parsedBlocks) { _currentBlocks.Add(new VisualiserBlock(aBlock)); } } } catch (CalidusException ex) { MessageBox.Show("Errors occured during block parsing: " + ex.Message); lstTokenList.Enabled = false; lstTokenDetails.DataSource = null; lstTokenList.DataSource = null; } try { if (parsedTokens != null) { IEnumerable <LineBase> parsedLines = lineParser.Parse(parsedTokens); _currentLines.Clear(); foreach (LineBase aLine in parsedLines) { _currentLines.Add(new VisualiserLine(aLine)); } } } catch (CalidusException ex) { MessageBox.Show("Errors occured during line parsing: " + ex.Message); lstLineList.Enabled = false; lstLineDetails.DataSource = null; lstLineList.DataSource = null; } lstTokenList.DataSource = _currentTokens; lstTokenList.Enabled = true; lstStatementList.DataSource = _currentStatements; lstStatementList.Enabled = true; lstBlockList.DataSource = _currentBlocks; lstBlockList.Enabled = true; lstLineList.DataSource = _currentLines; lstLineList.Enabled = true; lblGenericToken.Text = String.Format(_genericTokenCount, genericToken); lblGenericStatement.Text = String.Format(_genericStatementCount, genericStatement); tabDisplay.SelectedIndex = 0; DisplayCurrentToken(); }