import { describe, it, expect } from 'vitest' import { getFileName, isAllowedFile, getFileExtension } from '../fileUtils' describe('fileUtils', () => { describe('getFileName', () => { it('should extract filename from Unix path', () => { expect(getFileName('/home/user/documents/file.md')).toBe('file.md') }) it('should extract filename from Windows path', () => { expect(getFileName('C:\\Users\\test\\file.md')).toBe('file.md') }) it('should return the input if it is already a filename', () => { expect(getFileName('file.md')).toBe('file.md') }) it('should handle path with trailing slash', () => { expect(getFileName('/path/to/dir/')).toBe('dir') }) it('should handle path with trailing backslash', () => { expect(getFileName('C:\\Users\\test\\')).toBe('test') }) it('should handle mixed path separators', () => { expect(getFileName('C:\\Users/test\\file.md')).toBe('file.md') }) }) describe('getFileExtension', () => { it('should return lowercase extension', () => { expect(getFileExtension('file.MD')).toBe('.md') }) it('should return .markdown extension', () => { expect(getFileExtension('file.markdown')).toBe('.markdown') }) it('should return .txt extension', () => { expect(getFileExtension('notes.txt')).toBe('.txt') }) it('should return empty string for no extension', () => { expect(getFileExtension('Makefile')).toBe('') }) it('should return empty string for hidden files starting with dot', () => { expect(getFileExtension('.gitignore')).toBe('') }) it('should extract extension from full path', () => { expect(getFileExtension('/home/user/file.md')).toBe('.md') }) it('should extract extension from Windows path', () => { expect(getFileExtension('C:\\Users\\test\\file.MARKDOWN')).toBe('.markdown') }) it('should handle file with multiple dots', () => { expect(getFileExtension('my.file.md')).toBe('.md') }) }) describe('isAllowedFile', () => { it('should return true for .md files', () => { expect(isAllowedFile('file.md')).toBe(true) }) it('should return true for .markdown files', () => { expect(isAllowedFile('file.markdown')).toBe(true) }) it('should return true for .txt files', () => { expect(isAllowedFile('file.txt')).toBe(true) }) it('should return true for uppercase extensions', () => { expect(isAllowedFile('file.MD')).toBe(true) }) it('should return false for .js files', () => { expect(isAllowedFile('file.js')).toBe(false) }) it('should return false for .json files', () => { expect(isAllowedFile('file.json')).toBe(false) }) it('should return false for files without extension', () => { expect(isAllowedFile('Makefile')).toBe(false) }) it('should work with full paths', () => { expect(isAllowedFile('/home/user/doc.md')).toBe(true) expect(isAllowedFile('/home/user/script.py')).toBe(false) }) }) })