public void DefinitionWithInitialiaizer() { var source = "for(i = 0; i < 10; i++) {}"; var semanticModel = _CreateSemanticModel(source); var forStatement = _GetForStatement(semanticModel); Assert.IsFalse(LoopDeclarationVerifier.IsNormalized(forStatement, semanticModel)); }
public void DefinitionWithMultipleIncrementers() { var source = "int x = 0; for(var i = 0; i < 10; i++, x++) {}"; var semanticModel = _CreateSemanticModel(source); var forStatement = _GetForStatement(semanticModel); Assert.IsFalse(LoopDeclarationVerifier.IsNormalized(forStatement, semanticModel)); }
public void NormalizedDefinitionWithAssignment() { var source = "for(var i = 0; i < 10; i = i + 1) {}"; var semanticModel = _CreateSemanticModel(source); var forStatement = _GetForStatement(semanticModel); Assert.IsTrue(LoopDeclarationVerifier.IsNormalized(forStatement, semanticModel)); }
public void DefinitionWithConditionWithoutLoopIndex() { var source = "int x = 0; for(var i = 0; x < 10; i++) {}"; var semanticModel = _CreateSemanticModel(source); var forStatement = _GetForStatement(semanticModel); Assert.IsFalse(LoopDeclarationVerifier.IsNormalized(forStatement, semanticModel)); }
public void DefinitionWithoutCompoundCondition() { var source = @"for(var i = 0; i < 10 && i > -1; i++) {}"; var semanticModel = _CreateSemanticModel(source); var forStatement = _GetForStatement(semanticModel); Assert.IsFalse(LoopDeclarationVerifier.IsNormalized(forStatement, semanticModel)); }
public void DefinitionWithArrayLengthAsUpperBound() { var source = @" var array = new int[10]; for(i = 0; i < array.Length; i++) {}"; var semanticModel = _CreateSemanticModel(source); var forStatement = _GetForStatement(semanticModel); Assert.IsFalse(LoopDeclarationVerifier.IsNormalized(forStatement, semanticModel)); }
protected override IEnumerable <(ForStatementSyntax loopStatement, SyntaxNode body, string loopIndex, Location location)> GetLoopsToAnalyze(IEnumerable <SyntaxNode> nodes, SemanticModel semanticModel) { return(nodes.OfType <ForStatementSyntax>() .Where(forStatement => LoopDeclarationVerifier.IsNormalized(forStatement, semanticModel)) .Select(forStatement => ( forStatement, (SyntaxNode)forStatement.Statement, forStatement.Declaration.Variables.Single().Identifier.Text, // The location span of the for-loop includes the loop's body. Therefore, a custom location is created. Location.Create(forStatement.SyntaxTree, TextSpan.FromBounds(forStatement.SpanStart, forStatement.CloseParenToken.Span.End)) ))); }
public void DefinitionWithConditionAccessingLocalVariable() { var source = @" class Test { public void Run() { var local = 10; for(var i = 0; i < local; i++) {} } }"; var semanticModel = DocumentFactory.Create().CreateSemanticModel(source); var forStatement = _GetForStatement(semanticModel); Assert.IsTrue(LoopDeclarationVerifier.IsNormalized(forStatement, semanticModel)); }
public void DefinitionWithConditionAccessingMethod() { var source = @" class Test { public int Method() { return 0; } public void Run() { for(var i = 0; i < Method(); i++) {} } }"; var semanticModel = DocumentFactory.Create().CreateSemanticModel(source); var forStatement = _GetForStatement(semanticModel); Assert.IsFalse(LoopDeclarationVerifier.IsNormalized(forStatement, semanticModel)); }
public void DefinitionWithConditionAccessingVirtualAutoProperty() { var source = @" class Test { public virtual int Property { get; } public void Run() { for(var i = 0; i < Property; i++) {} } }"; var semanticModel = DocumentFactory.Create().CreateSemanticModel(source); var forStatement = _GetForStatement(semanticModel); Assert.IsFalse(LoopDeclarationVerifier.IsNormalized(forStatement, semanticModel)); }