ton-assembly
Version:
TON assembler and disassembler
46 lines • 2.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateTextReport = void 0;
const html_1 = require("./html");
const generateTextReport = (lines, summary) => {
const maxLineNumberWidth = lines.length.toString().length;
const annotatedLines = lines
.map((line, index) => {
const { gasInfo, hitsInfo, status } = lineInfo(line);
const lineNumber = index + 1;
const lineNumberPres = lineNumber.toString().padStart(maxLineNumberWidth);
return `${lineNumberPres} ${status}| ${line.line.padEnd(40)} |${gasInfo.padEnd(10)} |${hitsInfo}`;
})
.join("\n");
const summaryText = [
"Coverage Summary:",
`Lines: ${summary.coveredLines}/${summary.totalLines} (${summary.coveragePercentage.toFixed(2)}%)`,
`Total Gas: ${summary.totalGas}`,
`Total Hits: ${summary.totalHits}`,
"",
"Instruction Stats:",
...instructionsStats(summary),
].join("\n");
return `${summaryText}\n\nAnnotated Code:\n${annotatedLines}`;
};
exports.generateTextReport = generateTextReport;
const lineInfo = (line) => {
if (line.info.$ === "Covered") {
const totalGas = (0, html_1.calculateTotalGas)(line.info.gasCosts);
const gasInfo = ` gas:${totalGas}`;
const hitInfo = ` hits:${line.info.hits}`;
return { gasInfo, hitsInfo: hitInfo, status: "✓ " };
}
if (line.info.$ === "Uncovered") {
return { gasInfo: "", hitsInfo: "", status: "✗ " };
}
return { gasInfo: "", hitsInfo: "", status: " " };
};
const instructionsStats = (summary) => summary.instructionStats.map(stat => formatInstructionStat(stat, summary.totalGas));
const formatInstructionStat = (stat, totalGas) => {
const name = stat.name.padEnd(15);
const totalGasStr = stat.totalGas.toString().padEnd(3, "");
const percent = ((stat.totalGas / totalGas) * 100).toFixed(2);
return ` ${name} | ${totalGasStr} gas | ${stat.totalHits} hits | ${stat.avgGas} avg gas | ${percent}%`;
};
//# sourceMappingURL=text.js.map