Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
CI / CI OK (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
// pathUtils.test.ts
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import { toPosixPath } from '../path';
|
|
|
|
describe('toPosixPath', () => {
|
|
// 测试 Windows 风格路径到 POSIX 风格路径的转换
|
|
it('converts Windows-style paths to POSIX paths', () => {
|
|
const windowsPath = String.raw`C:\Users\Example\file.txt`;
|
|
const expectedPosixPath = 'C:/Users/Example/file.txt';
|
|
expect(toPosixPath(windowsPath)).toBe(expectedPosixPath);
|
|
});
|
|
|
|
// 确认 POSIX 风格路径不会被改变
|
|
it('leaves POSIX-style paths unchanged', () => {
|
|
const posixPath = '/home/user/file.txt';
|
|
expect(toPosixPath(posixPath)).toBe(posixPath);
|
|
});
|
|
|
|
// 测试带有多个分隔符的路径
|
|
it('converts paths with mixed separators', () => {
|
|
const mixedPath = String.raw`C:/Users\Example\file.txt`;
|
|
const expectedPosixPath = 'C:/Users/Example/file.txt';
|
|
expect(toPosixPath(mixedPath)).toBe(expectedPosixPath);
|
|
});
|
|
|
|
// 测试空字符串
|
|
it('handles empty strings', () => {
|
|
const emptyPath = '';
|
|
expect(toPosixPath(emptyPath)).toBe('');
|
|
});
|
|
|
|
// 测试仅包含分隔符的路径
|
|
it('handles path with only separators', () => {
|
|
const separatorsPath = '\\\\\\';
|
|
const expectedPosixPath = '///';
|
|
expect(toPosixPath(separatorsPath)).toBe(expectedPosixPath);
|
|
});
|
|
|
|
// 测试不包含任何分隔符的路径
|
|
it('handles path without separators', () => {
|
|
const noSeparatorPath = 'file.txt';
|
|
expect(toPosixPath(noSeparatorPath)).toBe('file.txt');
|
|
});
|
|
|
|
// 测试以分隔符结尾的路径
|
|
it('handles path ending with a separator', () => {
|
|
const endingSeparatorPath = 'C:\\Users\\Example\\';
|
|
const expectedPosixPath = 'C:/Users/Example/';
|
|
expect(toPosixPath(endingSeparatorPath)).toBe(expectedPosixPath);
|
|
});
|
|
|
|
// 测试以分隔符开头的路径
|
|
it('handles path starting with a separator', () => {
|
|
const startingSeparatorPath = String.raw`\Users\Example`;
|
|
const expectedPosixPath = '/Users/Example';
|
|
expect(toPosixPath(startingSeparatorPath)).toBe(expectedPosixPath);
|
|
});
|
|
|
|
// 测试包含非法字符的路径
|
|
it('handles path with invalid characters', () => {
|
|
const invalidCharsPath = String.raw`C:\Us*?ers\Ex<ample>|file.txt`;
|
|
const expectedPosixPath = 'C:/Us*?ers/Ex<ample>|file.txt';
|
|
expect(toPosixPath(invalidCharsPath)).toBe(expectedPosixPath);
|
|
});
|
|
});
|