mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-01 06:33:27 +08:00
test: add Round 91 tests for empty action pattern, whitespace PM, and mixed separators
- Test getCommandPattern('') produces valid regex for empty action string
- Test detectFromPackageJson returns null for whitespace-only packageManager
- Test getSessionStats treats mixed Windows path separators as file path
Total tests: 833
This commit is contained in:
@@ -1363,6 +1363,39 @@ function runTests() {
|
||||
cleanupTestDir(testDir);
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 91: getCommandPattern with empty action string ──
|
||||
console.log('\nRound 91: getCommandPattern (empty action):');
|
||||
|
||||
if (test('getCommandPattern with empty string returns valid regex pattern', () => {
|
||||
// package-manager.js line 401-409: Empty action falls to the else branch.
|
||||
// escapeRegex('') returns '', producing patterns like 'npm run ', 'yarn '.
|
||||
// The resulting combined regex should be compilable (not throw).
|
||||
const pattern = pm.getCommandPattern('');
|
||||
assert.ok(typeof pattern === 'string', 'Should return a string');
|
||||
assert.ok(pattern.length > 0, 'Should return non-empty pattern');
|
||||
// Verify the pattern compiles without error
|
||||
const regex = new RegExp(pattern);
|
||||
assert.ok(regex instanceof RegExp, 'Pattern should compile to valid RegExp');
|
||||
// The pattern should match package manager commands with trailing space
|
||||
assert.ok(regex.test('npm run '), 'Should match "npm run " with trailing space');
|
||||
assert.ok(regex.test('yarn '), 'Should match "yarn " with trailing space');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 91: detectFromPackageJson with whitespace-only packageManager ──
|
||||
console.log('\nRound 91: detectFromPackageJson (whitespace-only packageManager):');
|
||||
|
||||
if (test('detectFromPackageJson returns null for whitespace-only packageManager field', () => {
|
||||
// package-manager.js line 114-119: " " is truthy, so enters the if block.
|
||||
// " ".split('@')[0] = " " which doesn't match any PACKAGE_MANAGERS key.
|
||||
const testDir = createTestDir();
|
||||
fs.writeFileSync(
|
||||
path.join(testDir, 'package.json'),
|
||||
JSON.stringify({ packageManager: ' ' }));
|
||||
const result = pm.detectFromPackageJson(testDir);
|
||||
assert.strictEqual(result, null, 'Whitespace-only packageManager should return null');
|
||||
cleanupTestDir(testDir);
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Summary
|
||||
console.log('\n=== Test Results ===');
|
||||
console.log(`Passed: ${passed}`);
|
||||
|
||||
@@ -1448,6 +1448,19 @@ src/main.ts
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 91: getSessionStats with mixed Windows path separators ──
|
||||
console.log('\nRound 91: getSessionStats (mixed Windows path separators):');
|
||||
|
||||
if (test('getSessionStats treats mixed Windows separators as a file path', () => {
|
||||
// session-manager.js line 166: regex /^[A-Za-z]:[/\\]/ checks only the
|
||||
// character right after the colon. Mixed separators like C:\Users/Mixed\session.tmp
|
||||
// should still match because the first separator (\) satisfies the regex.
|
||||
const stats = sessionManager.getSessionStats('C:\\Users/Mixed\\session.tmp');
|
||||
assert.strictEqual(stats.lineCount, 0,
|
||||
'Mixed separators should be treated as path (file does not exist → lineCount 0)');
|
||||
assert.strictEqual(stats.totalItems, 0, 'Non-existent path should have 0 items');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Summary
|
||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user