Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion benchmarks/loc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// Recorded as the `code_loc` metric per arm (always passes; it is a measurement, not a gate).
module.exports = (output) => {
const text = String(output || '');
const blocks = [...text.matchAll(/```[a-zA-Z0-9_+-]*\n([\s\S]*?)```/g)].map((m) => m[1]);
// \r? so CRLF fences match too; without it, CRLF output finds no block and
// the whole response (prose included) gets counted. Mirrors correctness.js.
const blocks = [...text.matchAll(/```[a-zA-Z0-9_+-]*\r?\n([\s\S]*?)```/g)].map((m) => m[1]);
// Drop /* ... */ block comments before counting; the line filter below only
// caught `*`-aligned JSDoc, so plain block comments were miscounted as code.
const code = (blocks.length ? blocks.join('\n') : text).replace(/\/\*[\s\S]*?\*\//g, '');
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/loc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const cases = [
['inline block comment keeps its code line', score('```js\nconst x = 1; /* note */\nconst y = 2;\n```'), 2],
['line comments still stripped', score('```js\n// header\nconst x = 1;\n```'), 1],
['plain code unchanged', score('```js\nconst a = 1;\nconst b = 2;\n```'), 2],
// CRLF-fenced output must still find the block, not fall back to the whole text.
['crlf fences count only the code', score('Here:\r\n```js\r\nconst a = 1;\r\nconst b = 2;\r\n```\r\nDone.'), 2],
];
for (const [name, got, want] of cases) {
assert.strictEqual(got, want, `FAILED: ${name} (got ${got}, want ${want})`);
Expand Down
Loading