mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-06-29 01:45:54 +08:00
48129a8908
完全移除旧 C+IUP 代码,改用 Tauri 2.x + React 19 + TypeScript + Rust 技术栈重写。 功能与 v3.1 完全等价: - React 前端:Tailwind CSS 4、Zustand 状态管理、i18next 国际化 - Rust 后端:winreg 注册表读写、Win32 API FFI 调用 - 核心逻辑:StringList、UndoRedoManager、PathManager、Import/Export - 深色模式、中英文切换、键盘快捷键、合并预览 - 66 个 Vitest 单元测试 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
101 lines
3.0 KiB
TypeScript
101 lines
3.0 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import {
|
|
pathRemoveAt,
|
|
pathMoveUp,
|
|
pathMoveDown,
|
|
pathClean,
|
|
batchRemoveAt,
|
|
} from '../../src/core/path-manager';
|
|
import { StringList } from '../../src/core/string-list';
|
|
|
|
// 模拟验证函数:所有路径都"有效"
|
|
const alwaysValid = () => true;
|
|
|
|
// 模拟验证函数:C:\\Invalid 无效
|
|
const validateFn = (path: string) => !path.includes('Invalid');
|
|
|
|
describe('pathRemoveAt', () => {
|
|
it('删除指定索引', () => {
|
|
const list = StringList.fromArray(['a', 'b', 'c']);
|
|
pathRemoveAt(list, 1);
|
|
expect(list.toArray()).toEqual(['a', 'c']);
|
|
});
|
|
});
|
|
|
|
describe('pathMoveUp', () => {
|
|
it('上移元素', () => {
|
|
const list = StringList.fromArray(['a', 'b', 'c']);
|
|
pathMoveUp(list, 1);
|
|
expect(list.toArray()).toEqual(['b', 'a', 'c']);
|
|
});
|
|
|
|
it('第一个元素不能上移', () => {
|
|
const list = StringList.fromArray(['a', 'b']);
|
|
expect(pathMoveUp(list, 0)).toBe(false);
|
|
expect(list.toArray()).toEqual(['a', 'b']);
|
|
});
|
|
|
|
it('无效索引不能上移', () => {
|
|
const list = StringList.fromArray(['a']);
|
|
expect(pathMoveUp(list, -1)).toBe(false);
|
|
expect(pathMoveUp(list, 5)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('pathMoveDown', () => {
|
|
it('下移元素', () => {
|
|
const list = StringList.fromArray(['a', 'b', 'c']);
|
|
pathMoveDown(list, 0);
|
|
expect(list.toArray()).toEqual(['b', 'a', 'c']);
|
|
});
|
|
|
|
it('最后一个元素不能下移', () => {
|
|
const list = StringList.fromArray(['a', 'b']);
|
|
expect(pathMoveDown(list, 1)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('batchRemoveAt', () => {
|
|
it('批量删除(按从大到小排序)', () => {
|
|
const list = StringList.fromArray(['a', 'b', 'c', 'd', 'e']);
|
|
batchRemoveAt(list, [0, 2, 4]);
|
|
expect(list.toArray()).toEqual(['b', 'd']);
|
|
});
|
|
|
|
it('删除乱序索引', () => {
|
|
const list = StringList.fromArray(['a', 'b', 'c', 'd']);
|
|
batchRemoveAt(list, [3, 0]);
|
|
expect(list.toArray()).toEqual(['b', 'c']);
|
|
});
|
|
});
|
|
|
|
describe('pathClean', () => {
|
|
it('移除无效路径', () => {
|
|
const list = StringList.fromArray(['C:\\Valid', 'C:\\Invalid', 'D:\\Valid']);
|
|
const removed = pathClean(list, validateFn);
|
|
expect(list.toArray()).toEqual(['C:\\Valid', 'D:\\Valid']);
|
|
expect(removed).toEqual(['C:\\Invalid']);
|
|
});
|
|
|
|
it('移除重复路径(保留一个)', () => {
|
|
const list = StringList.fromArray(['C:\\Valid', 'C:\\Valid', 'D:\\Valid']);
|
|
const removed = pathClean(list, alwaysValid);
|
|
expect(list.length).toBe(2);
|
|
expect(removed.length).toBeGreaterThanOrEqual(1);
|
|
});
|
|
|
|
it('全部有效无变化', () => {
|
|
const list = StringList.fromArray(['C:\\a', 'D:\\b']);
|
|
const removed = pathClean(list, alwaysValid);
|
|
expect(list.toArray()).toEqual(['C:\\a', 'D:\\b']);
|
|
expect(removed.length).toBe(0);
|
|
});
|
|
|
|
it('全部无效全部移除', () => {
|
|
const list = StringList.fromArray(['C:\\Invalid1', 'C:\\Invalid2']);
|
|
const removed = pathClean(list, validateFn);
|
|
expect(list.length).toBe(0);
|
|
expect(removed.length).toBe(2);
|
|
});
|
|
});
|