mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-10 02:24:35 +08:00
- Implemented final verification tests for contentPattern to validate behavior with empty strings, dangerous patterns, and normal patterns. - Created glob pattern matching tests to verify regex conversion and matching functionality. - Developed infinite loop risk tests using Worker threads to isolate potential blocking operations. - Introduced optimized contentPattern tests to validate improvements in the findMatches function. - Added verification tests to assess the effectiveness of contentPattern optimizations. - Conducted safety tests for contentPattern to identify edge cases and potential vulnerabilities. - Implemented unrestricted loop tests to analyze infinite loop risks without match limits. - Developed tests for zero-width pattern detection logic to ensure proper handling of dangerous regex patterns.
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
/**
|
|
* Glob 模式匹配测试
|
|
*/
|
|
|
|
function globToRegex(pattern) {
|
|
const escaped = pattern
|
|
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
.replace(/\*/g, '.*')
|
|
.replace(/\?/g, '.');
|
|
return new RegExp(`^${escaped}$`, 'i');
|
|
}
|
|
|
|
const tests = [
|
|
['*.ts', 'app.ts'],
|
|
['*.ts', 'app.tsx'],
|
|
['test_*.js', 'test_main.js'],
|
|
['test_*.js', 'main_test.js'],
|
|
['*.json', 'package.json'],
|
|
['c*.ts', 'config.ts'],
|
|
['data?.json', 'data1.json'],
|
|
['data?.json', 'data12.json'],
|
|
['*.{js,ts}', 'app.js'], // 不支持大括号语法
|
|
['src/**/*.ts', 'src/app.ts'], // 不支持双星语法
|
|
];
|
|
|
|
console.log('Glob 模式匹配测试:');
|
|
console.log('─'.repeat(60));
|
|
tests.forEach(([pattern, filename]) => {
|
|
const regex = globToRegex(pattern);
|
|
const matches = regex.test(filename);
|
|
console.log(`${pattern.padEnd(20)} → ${filename.padEnd(20)} ${matches ? '✅ 匹配' : '❌ 不匹配'}`);
|
|
if (pattern.includes('{') || pattern.includes('**')) {
|
|
console.log(` ⚠️ 注意: 当前实现不支持 ${pattern.includes('{') ? '{}' : '**'} 语法`);
|
|
}
|
|
});
|