antler
Version:
Directory structure linter
44 lines (35 loc) • 1.2 kB
text/typescript
import { RegexRule } from '../../src/regex-rule';
import { FileName } from '../../src/rules/file-name';
import { Node } from '../../src/types';
describe('FileName', () => {
const directoryNode: Node = {
fullPath: 'root/parent/child',
path: 'parent/child',
name: 'child',
parentName: 'parent',
siblingNamesIncludingSelf: ['child'],
childNames: [],
isDirectory: true,
};
const fileNode = {
...directoryNode,
isDirectory: false,
};
it('should extend RegexRule', () => {
const instance = new FileName({ level: 'error', options: { allow: '' } });
expect(instance instanceof RegexRule).toBe(true);
});
describe('shouldRun', () => {
it('should run only for files', () => {
const instance = new FileName({ level: 'error', options: { allow: '' } });
expect(instance['shouldRun'](fileNode)).toBe(true);
expect(instance['shouldRun'](directoryNode)).toBe(false);
});
});
describe('getPart', () => {
it('should return the file / directory name', () => {
const instance = new FileName({ level: 'error', options: { allow: '' } });
expect(instance['getPart'](directoryNode)).toBe('child');
});
});
});