/**
* Test case for Windows path detection regex fix
*
* This demonstrates the bug where paths with spaces were truncated.
*/
// ============================================
// TEST DATA
// ============================================
const testCases = [
{
input: "go to C:\\Source Code\\LM Studio Plugins\\ai_toolbox",
expected: "C:\\Source Code\\LM Studio Plugins\\ai_toolbox"
},
{
input: "open D:\\My Documents\\Projects\\test-app",
expected: "D:\\My Documents\\Projects\\test-app"
},
{
input: "navigate to C:\\Program Files\\NodeJS",
expected: "C:\\Program Files\\NodeJS"
},
{
input: "check E:\\Backup 2024\\Important Files",
expected: "E:\\Backup 2024\\Important Files"
}
];
// ============================================
// REGEX PATTERNS
// ============================================
// β OLD (BROKEN) - Missing backslash in character class
const oldRegex = /[A-Za-z]:\\[\w\-_. ]+/;
// β
NEW (FIXED) - Backslash included in character class
const newRegex = /[A-Za-z]:\\[\w\-_. \\]+/;
// ============================================
// TEST FUNCTION
// ============================================
function runTests() {
console.log("=".repeat(70));
console.log("PATH DETECTION REGEX TEST CASES");
console.log("=".repeat(70));
let passed = 0;
let failed = 0;
for (const testCase of testCases) {
const oldMatch = testCase.input.match(oldRegex);
const newMatch = testCase.input.match(newRegex);
const oldResult = oldMatch ? oldMatch[0] : null;
const newResult = newMatch ? newMatch[0] : null;
console.log(`\nπ Input: "${testCase.input}"`);
console.log(` Expected: "${testCase.expected}"`);
// Test OLD regex (should FAIL)
if (oldResult === testCase.expected) {
console.log(` β OLD regex: PASS (unexpected - should fail)`);
} else {
console.log(` β OLD regex: FAIL β "${oldResult}"`);
failed++;
}
// Test NEW regex (should PASS)
if (newResult === testCase.expected) {
console.log(` β
NEW regex: PASS β "${newResult}"`);
passed++;
} else {
console.log(` β NEW regex: FAIL β "${newResult}"`);
failed++;
}
}
// ============================================
// SUMMARY
// ============================================
console.log("\n" + "=".repeat(70));
console.log("SUMMARY");
console.log("=".repeat(70));
console.log(`β
Passed: ${passed}`);
console.log(`β Failed: ${failed}`);
console.log(`π Total: ${testCases.length * 2} tests (OLD + NEW regex)`);
if (failed === testCases.length) {
// Expected: all OLD tests fail, all NEW tests pass
console.log("\nπ RESULT: Fix verified! OLD regex fails as expected, NEW regex passes.");
} else if (failed === 0) {
console.log("\nβ οΈ WARNING: All tests passed - something unexpected happened!");
} else {
console.log(`\nβ οΈ PARTIAL: ${testCases.length} OLD tests failed (expected), but some NEW tests also failed.`);
}
}
// ============================================
// RUN TESTS
// ============================================
runTests();