UNPKG

apex-mutation-testing

Version:

Apex mutation testing plugin

28 lines 1.51 kB
import { BoundaryConditionMutator } from '../mutator/boundaryConditionMutator.js'; import { IncrementMutator } from '../mutator/incrementMutator.js'; import { MutationListener } from '../mutator/mutationListener.js'; import { ApexLexer, ApexParser, CaseInsensitiveInputStream, CommonTokenStream, ParseTreeWalker, } from 'apex-parser'; import { TokenStreamRewriter } from 'antlr4ts'; export class MutantGenerator { tokenStream; compute(classContent, coveredLines) { const lexer = new ApexLexer(new CaseInsensitiveInputStream('other', classContent)); this.tokenStream = new CommonTokenStream(lexer); const parser = new ApexParser(this.tokenStream); const tree = parser.compilationUnit(); const incrementListener = new IncrementMutator(); const boundaryListener = new BoundaryConditionMutator(); const listener = new MutationListener([incrementListener, boundaryListener], coveredLines); ParseTreeWalker.DEFAULT.walk(listener, tree); return listener.getMutations(); } mutate(mutation) { // Create a new token stream rewriter const rewriter = new TokenStreamRewriter(this.tokenStream); // Apply the mutation by replacing the original token with the replacement text rewriter.replace(mutation.token.symbol.tokenIndex, mutation.token.symbol.tokenIndex, mutation.replacement); // Get the mutated code return rewriter.getText(); } } //# sourceMappingURL=mutantGenerator.js.map