import { describe, expect, it } from 'vitest'; import { excludeDynamicNamePattern, excludeFileExtension, excludeRelativePath, getFileNameFromPath, getRoutePath, } from './path'; describe('excludeFileExtension', () => { it('"./index.ts" 는 "./index" 로 변경됩니다.', () => { expect(excludeFileExtension('./index.ts')).toEqual('./index'); }); it('"./index.js" 는 "./index" 로 변경됩니다.', () => { expect(excludeFileExtension('./index.js')).toEqual('./index'); }); it('"./list/detail.tsx" 는 "./list/detail" 로 변경됩니다.', () => { expect(excludeFileExtension('./list/detail.tsx')).toEqual('./list/detail'); }); it('"./list/detail.jsx" 는 "./list/detail" 로 변경됩니다.', () => { expect(excludeFileExtension('./list/detail.jsx')).toEqual('./list/detail'); }); it('"./detail.foo" 는 "./detail.foo" 로 유지됩니다.', () => { expect(excludeFileExtension('./detail.foo')).toEqual('./detail.foo'); }); }); describe('excludeRelativePath', () => { it('"./index.tsx" 는 "index.tsx" 로 변경됩니다.', () => { expect(excludeRelativePath('./index.tsx')).toEqual('index.tsx'); }); it('"./../index.tsx" 는 "index.tsx" 로 변경됩니다.', () => { expect(excludeRelativePath('./../index.tsx')).toEqual('index.tsx'); }); it('"../../index.tsx" 는 "index.tsx" 로 변경됩니다.', () => { expect(excludeRelativePath('../../index.tsx')).toEqual('index.tsx'); }); }); describe('excludeDynamicNamePattern', () => { it('"[id]" 는 "id" 로 변경됩니다.', () => { expect(excludeDynamicNamePattern('[id]')).toEqual('id'); }); it('"[id]/[name]" 는 "id/name" 로 변경됩니다.', () => { expect(excludeDynamicNamePattern('[id]/[name]')).toEqual('id/name'); }); }); describe('getRoutePath', () => { describe('posix', () => { it('"/index.tsx" 는 "/" 로 변환됩니다.', () => { expect(getRoutePath('/index.tsx')).toEqual('/'); }); it('"/index.ts" 는 "/" 로 변환됩니다.', () => { expect(getRoutePath('/index.tsx')).toEqual('/'); }); it('"/list/index.tsx" 는 "/list" 로 변환됩니다.', () => { expect(getRoutePath('/list/index.tsx')).toEqual('/list'); }); it('"/list/detail.tsx" 는 "/list" 로 변환됩니다.', () => { expect(getRoutePath('/list/detail.tsx')).toEqual('/list/detail'); }); it('"/list/[id].tsx" 는 "/:id" 로 변환됩니다.', () => { expect(getRoutePath('/list/[id].tsx')).toEqual('/list/:id'); }); it('"/list/[id].js" 는 "/:id" 로 변환됩니다.', () => { expect(getRoutePath('/list/[id].js')).toEqual('/list/:id'); }); }); describe('window', () => { it('"\\index.tsx" 는 "/" 로 변환됩니다.', () => { expect(getRoutePath('\\index.tsx')).toEqual('/'); }); it('"\\index.ts" 는 "/" 로 변환됩니다.', () => { expect(getRoutePath('\\index.tsx')).toEqual('/'); }); it('"\\list\\index.tsx" 는 "/list" 로 변환됩니다.', () => { expect(getRoutePath('\\list\\index.tsx')).toEqual('/list'); }); it('"\\list\\detail.tsx" 는 "/list" 로 변환됩니다.', () => { expect(getRoutePath('\\list\\detail.tsx')).toEqual('/list/detail'); }); it('"\\list\\[id].tsx" 는 "/:id" 로 변환됩니다.', () => { expect(getRoutePath('\\list\\[id].tsx')).toEqual('/list/:id'); }); it('"\\list\\[id].js" 는 "/:id" 로 변환됩니다.', () => { expect(getRoutePath('\\list\\[id].js')).toEqual('/list/:id'); }); }); }); describe('getFileNameFromPath', () => { it('extracts filename from file path', () => { const result = getFileNameFromPath('/path/to/file.txt'); expect(result).toBe('file.txt'); }); it('returns the filename when path is just a filename', () => { const result = getFileNameFromPath('file.txt'); expect(result).toBe('file.txt'); }); it('returns empty string when path is empty', () => { const result = getFileNameFromPath(''); expect(result).toBe(''); }); it('returns empty string when path ends with slash', () => { const result = getFileNameFromPath('/path/to/directory/'); expect(result).toBe(''); }); it('extracts filename without extension using withExtension option', () => { const result = getFileNameFromPath('/path/to/file.txt', { withExtension: false }); expect(result).toBe('file'); }); });