mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
# 🚀 Sync Gemini CLI v0.2.1 - Major Feature Update (#483)
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { escapePath, unescapePath } from './paths.js';
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import { escapePath, unescapePath, isSubpath } from './paths.js';
|
||||
|
||||
describe('escapePath', () => {
|
||||
it('should escape spaces', () => {
|
||||
@@ -212,3 +212,105 @@ describe('unescapePath', () => {
|
||||
expect(unescapePath('file\\\\\\(test\\).txt')).toBe('file\\\\(test).txt');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSubpath', () => {
|
||||
it('should return true for a direct subpath', () => {
|
||||
expect(isSubpath('/a/b', '/a/b/c')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for the same path', () => {
|
||||
expect(isSubpath('/a/b', '/a/b')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for a parent path', () => {
|
||||
expect(isSubpath('/a/b/c', '/a/b')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for a completely different path', () => {
|
||||
expect(isSubpath('/a/b', '/x/y')).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle relative paths', () => {
|
||||
expect(isSubpath('a/b', 'a/b/c')).toBe(true);
|
||||
expect(isSubpath('a/b', 'a/c')).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle paths with ..', () => {
|
||||
expect(isSubpath('/a/b', '/a/b/../b/c')).toBe(true);
|
||||
expect(isSubpath('/a/b', '/a/c/../b')).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle root paths', () => {
|
||||
expect(isSubpath('/', '/a')).toBe(true);
|
||||
expect(isSubpath('/a', '/')).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle trailing slashes', () => {
|
||||
expect(isSubpath('/a/b/', '/a/b/c')).toBe(true);
|
||||
expect(isSubpath('/a/b', '/a/b/c/')).toBe(true);
|
||||
expect(isSubpath('/a/b/', '/a/b/c/')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSubpath on Windows', () => {
|
||||
const originalPlatform = process.platform;
|
||||
|
||||
beforeAll(() => {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: 'win32',
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true for a direct subpath on Windows', () => {
|
||||
expect(isSubpath('C:\\Users\\Test', 'C:\\Users\\Test\\file.txt')).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return true for the same path on Windows', () => {
|
||||
expect(isSubpath('C:\\Users\\Test', 'C:\\Users\\Test')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for a parent path on Windows', () => {
|
||||
expect(isSubpath('C:\\Users\\Test\\file.txt', 'C:\\Users\\Test')).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('should return false for a different drive on Windows', () => {
|
||||
expect(isSubpath('C:\\Users\\Test', 'D:\\Users\\Test')).toBe(false);
|
||||
});
|
||||
|
||||
it('should be case-insensitive for drive letters on Windows', () => {
|
||||
expect(isSubpath('c:\\Users\\Test', 'C:\\Users\\Test\\file.txt')).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('should be case-insensitive for path components on Windows', () => {
|
||||
expect(isSubpath('C:\\Users\\Test', 'c:\\users\\test\\file.txt')).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle mixed slashes on Windows', () => {
|
||||
expect(isSubpath('C:/Users/Test', 'C:\\Users\\Test\\file.txt')).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle trailing slashes on Windows', () => {
|
||||
expect(isSubpath('C:\\Users\\Test\\', 'C:\\Users\\Test\\file.txt')).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle relative paths correctly on Windows', () => {
|
||||
expect(isSubpath('Users\\Test', 'Users\\Test\\file.txt')).toBe(true);
|
||||
expect(isSubpath('Users\\Test\\file.txt', 'Users\\Test')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user