Files
Clipboard/test/choose-dir-path.test.js
2026-09-12 13:59:12 +08:00

63 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
// 回归测试:选择与当前相同目录的不同大小写形式,应当判为"已是当前数据位置"。
//
// 被测对象是 lib/same-dir.js —— main.jssettings:choose-dir与 config.js
// migrateLegacyData共用它。之前本测试自己内联了一份实现来测而 main.js
// 实际用的是原始 `===`Windows 大小写不一致时误判为不同目录,自己迁自己),
// 测试却一路绿灯 —— 内联副本与生产代码脱节。现在直接测共享逻辑本体。
const assert = require('node:assert');
const path = require('node:path');
const { isSameDir } = require('../lib/same-dir');
let passed = 0;
function check(name, fn) {
try { fn(); console.log(' ok -', name); passed++; }
catch (e) { console.error(' FAIL -', name, '\n', e.message); process.exitCode = 1; }
}
check('Windows 同目录不同大小写:应判为相同', () => {
if (process.platform !== 'win32') {
console.log(' (skipped on non-Windows)');
return;
}
assert.strictEqual(
isSameDir('C:\\Users\\Foo\\.clipboard-app', 'c:\\users\\foo\\.clipboard-app'),
true
);
});
check('Windows 反斜杠/正斜杠混用:应判为相同', () => {
if (process.platform !== 'win32') {
console.log(' (skipped on non-Windows)');
return;
}
// path.resolve 会统一为反斜杠
const a = path.resolve('C:/Users/Foo/.clipboard-app');
const b = path.resolve('C:\\Users\\Foo\\.clipboard-app');
assert.strictEqual(isSameDir(a, b), true);
});
check('Windows 不同盘符:应判为不同', () => {
if (process.platform !== 'win32') {
console.log(' (skipped on non-Windows)');
return;
}
assert.strictEqual(
isSameDir('C:\\foo', 'D:\\foo'),
false
);
});
check('POSIX 严格比较(不同大小写应判为不同)', () => {
if (process.platform === 'win32') {
console.log(' (skipped on Windows)');
return;
}
assert.strictEqual(
isSameDir('/home/Foo/.clipboard-app', '/home/foo/.clipboard-app'),
false
);
});
console.log(`\n${passed} checks passed`);