test: add 3 tests for replaceInFile deletion, parseSessionMetadata null fields, countInFile zero matches (Round 88)

- replaceInFile with empty replacement string verifies text deletion works
- parseSessionMetadata asserts date/started/lastUpdated are null when fields absent
- countInFile with valid file but non-matching pattern returns 0

Total: 824 tests
This commit is contained in:
Affaan Mustafa
2026-02-13 12:49:53 -08:00
parent 9b286ab3f8
commit e70d4d2237
2 changed files with 53 additions and 0 deletions

View File

@@ -1385,6 +1385,22 @@ src/main.ts
}
})) passed++; else failed++;
// ── Round 88: parseSessionMetadata null date/started/lastUpdated fields ──
console.log('\nRound 88: parseSessionMetadata content lacking Date/Started/Updated fields:');
if (test('parseSessionMetadata returns null for date, started, lastUpdated when fields absent', () => {
const content = '# Title Only\n\n### Notes for Next Session\nSome notes\n';
const meta = sessionManager.parseSessionMetadata(content);
assert.strictEqual(meta.date, null,
'date should be null when **Date:** field is absent');
assert.strictEqual(meta.started, null,
'started should be null when **Started:** field is absent');
assert.strictEqual(meta.lastUpdated, null,
'lastUpdated should be null when **Last Updated:** field is absent');
// Confirm other fields still parse correctly
assert.strictEqual(meta.title, 'Title Only');
assert.strictEqual(meta.notes, 'Some notes');
})) passed++; else failed++;
// Summary
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);

View File

@@ -1194,6 +1194,43 @@ function runTests() {
`At CWD=/ with no session ID, should use the fallback parameter. Got: "${result.stdout}"`);
})) passed++; else failed++;
// ── Round 88: replaceInFile with empty replacement (deletion) ──
console.log('\nRound 88: replaceInFile with empty replacement string (deletion):');
if (test('replaceInFile with empty string replacement deletes matched text', () => {
const tmpDir = path.join(utils.getTempDir(), `ecc-r88-replace-empty-${Date.now()}`);
fs.mkdirSync(tmpDir, { recursive: true });
const tmpFile = path.join(tmpDir, 'delete-test.txt');
try {
fs.writeFileSync(tmpFile, 'hello REMOVE_ME world');
const result = utils.replaceInFile(tmpFile, 'REMOVE_ME ', '');
assert.strictEqual(result, true, 'Should return true on successful replacement');
const content = fs.readFileSync(tmpFile, 'utf8');
assert.strictEqual(content, 'hello world',
'Empty replacement should delete the matched text');
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
})) passed++; else failed++;
// ── Round 88: countInFile with valid file but zero matches ──
console.log('\nRound 88: countInFile with existing file but non-matching pattern:');
if (test('countInFile returns 0 for valid file with no pattern matches', () => {
const tmpDir = path.join(utils.getTempDir(), `ecc-r88-count-zero-${Date.now()}`);
fs.mkdirSync(tmpDir, { recursive: true });
const tmpFile = path.join(tmpDir, 'no-match.txt');
try {
fs.writeFileSync(tmpFile, 'apple banana cherry');
const count = utils.countInFile(tmpFile, 'ZZZZNOTHERE');
assert.strictEqual(count, 0,
'Should return 0 when regex matches nothing in existing file');
const countRegex = utils.countInFile(tmpFile, /ZZZZNOTHERE/g);
assert.strictEqual(countRegex, 0,
'Should return 0 for RegExp with no matches in existing file');
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
})) passed++; else failed++;
// Summary
console.log('\n=== Test Results ===');
console.log(`Passed: ${passed}`);