Example #1
0
        private SyntaxNode MutateForStatement(ForStatementSyntax forStatement, MutationContext context)
        {
            // for needs special treatments for its incrementors
            StatementSyntax forWithMutantIncrementors = forStatement.TrackNodes(forStatement);

            foreach (var incrementor in forStatement.Incrementors)
            {
                forWithMutantIncrementors = MutateSubExpressionWithIfStatements(forStatement, forWithMutantIncrementors, incrementor, context);
            }

            var originalFor = forWithMutantIncrementors.GetCurrentNode(forStatement);

            // mutate condition, if any
            ForStatementSyntax mutatedFor;
            StatementSyntax    statementPart;

            if (forStatement.Condition == null)
            {
                mutatedFor    = forStatement;
                statementPart = forStatement.Statement;
            }
            else
            {
                mutatedFor = forStatement.TrackNodes(forStatement.Condition, forStatement.Statement);
                mutatedFor = mutatedFor.ReplaceNode(mutatedFor.GetCurrentNode(forStatement.Condition),
                                                    Mutate(forStatement.Condition, context));
                statementPart = mutatedFor.GetCurrentNode(forStatement.Statement);
            }

            // mutate the statement/block
            mutatedFor = mutatedFor.ReplaceNode(statementPart, Mutate(forStatement.Statement, context));
            // and now we replace it
            return(forWithMutantIncrementors.ReplaceNode(originalFor, mutatedFor));
        }
        private SyntaxNode MutateForStatement(ForStatementSyntax forStatement)
        {
            // for needs special treatments for its incrementors
            StatementSyntax forWithMutantIncrementors = forStatement.TrackNodes(forStatement);

            foreach (var incrementor in forStatement.Incrementors)
            {
                forWithMutantIncrementors = MutateSubExpressionWithIfStatements(forStatement, forWithMutantIncrementors, incrementor);
            }

            var originalFor = forWithMutantIncrementors.GetCurrentNode(forStatement);
            // now we generate a mutant for the remainder of the for statement

            ForStatementSyntax mutatedFor;
            StatementSyntax    statementPart;

            if (forStatement.Condition == null)
            {
                mutatedFor    = forStatement;
                statementPart = forStatement.Statement;
            }
            else
            {
                mutatedFor = forStatement.TrackNodes(forStatement.Condition, forStatement.Statement);
                mutatedFor = mutatedFor.ReplaceNode(mutatedFor.GetCurrentNode(forStatement.Condition),
                                                    Mutate(forStatement.Condition));
                statementPart = mutatedFor.GetCurrentNode(forStatement.Statement);
            }

            mutatedFor = mutatedFor.ReplaceNode(statementPart,
                                                Mutate(forStatement.Statement));
            // and now we replace it
            return(forWithMutantIncrementors.ReplaceNode(originalFor, mutatedFor));
        }