Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: specs #128

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions specs/font-file-name.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, test as spec } from 'bun:test';
import { FONT_FILE_NAME_REGEX } from '#src/index.ts';

describe('FONT_FILE_NAME_REGEX', () => {
const validTestCases = [
'Roboto-Bold.otf',
'OpenSans-Light.ttf',
'Montserrat-ExtraBold.woff',
'Lato-Regular.woff2',
'Roboto-BoldItalic.otf',
'OpenSans-LightVariable.ttf',
'Montserrat-ExtraBoldItalicVariable.woff',
'Lato-RegularVariable.woff2',
];

validTestCases.forEach((testCase) => {
spec(`should match valid font file name: ${testCase}`, () => {
expect(testCase).toMatch(FONT_FILE_NAME_REGEX);
});
});

const invalidTestCases = [
'Roboto-Bold',
'OpenSans-Light.pdf',
'Montserrat-ExtraBoldItalic',
'Lato-RegularVariable',
'Roboto-Bold.otf.ttf',
'OpenSans-Light.ttf.woff',
'Montserrat-ExtraBoldItalicVariable',
'Lato-RegularVariable.woff2.ttf',
'Roboto-Bold.otf ',
' OpenSans-Light.ttf',
];

invalidTestCases.forEach((testCase) => {
spec(`should not match invalid font file name: ${testCase}`, () => {
expect(testCase).not.toMatch(FONT_FILE_NAME_REGEX);
});
});
});
133 changes: 96 additions & 37 deletions specs/selectors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,136 @@
import { describe, expect, test as spec } from 'bun:test';

import { NESTED_ATTRIBUTE_REGEX, NESTED_CLASS_REGEX } from '#src/index.ts';
import {
NESTED_ATTRIBUTE_REGEX,
NESTED_CLASS_REGEX,
NESTED_MODIFIER_REGEX,
NESTED_ELEMENT_REGEX,
ATTRIBUTE_REGEX,
CLASS_REGEX,
MODIFIER_REGEX,
ELEMENT_REGEX,
SIBLING_REGEX,
CHILD_REGEX,
ATTRIBUTE_SIBLING_REGEX,
ATTRIBUTE_CHILD_REGEX,
CLASS_SIBLING_REGEX,
CLASS_CHILD_REGEX,
NESTED_ATTRIBUTE_SIBLING_REGEX,
NESTED_ATTRIBUTE_CHILD_REGEX,
NESTED_CLASS_SIBLING_REGEX,
NESTED_CLASS_CHILD_REGEX,
} from '#src/index.ts';

describe('Nested Selectors Regex', async () => {
spec('should &[attribute]', async () => {
spec('should match &[attribute]', async () => {
expect('&[attribute]').toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
});

spec('should &[attribute] {}', async () => {
expect('&[attribute] {}').toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
});

spec('should &[attribute=value]', async () => {
spec('should match &[attribute=value]', async () => {
expect('&[attribute=value]').toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
});

spec('should &[attribute*=value]', async () => {
spec('should match &[attribute*=value]', async () => {
expect('&[attribute*=value]').toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
});

spec('should &[attribute=value] {}', async () => {
expect('&[attribute=value] {}').toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
spec('should match &[attribute="value"]', async () => {
expect('&[attribute="value"]').toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
});

spec('should &[attribute*=value] {}', async () => {
expect('&[attribute*=value] {}').toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
spec('should match &[attribute*="value"]', async () => {
expect('&[attribute*="value"]').toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
});

spec("&[attribute='value']", async () => {
spec("should match &[attribute='value']", async () => {
expect("&[attribute='value']").toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
});

spec('should &[attribute*="value"]', async () => {
expect('&[attribute*="value"]').toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
spec("should match &[attribute*='value']", async () => {
expect("&[attribute*='value']").toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
});

spec('should &[attribute="value"] {}', async () => {
expect("&[attribute='value'] {}").toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
spec('should match &.class', async () => {
expect('&.class').toMatch(new RegExp(NESTED_CLASS_REGEX));
});

spec('should &[attribute*="value"] {}', async () => {
expect("&[attribute*='value'] {}").toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
spec('should match &--modifier', async () => {
expect('&--modifier').toMatch(new RegExp(NESTED_MODIFIER_REGEX));
});

spec("&[attribute='value']", async () => {
expect("&[attribute='value']").toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
spec('should match &__element', async () => {
expect('&__element').toMatch(new RegExp(NESTED_ELEMENT_REGEX));
});

spec("&[attribute*='value']", async () => {
expect("&[attribute*='value']").toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
spec('should match [attribute]', async () => {
expect('[attribute]').toMatch(new RegExp(ATTRIBUTE_REGEX));
});

spec("&[attribute='value'] {}", async () => {
expect("&[attribute='value'] {}").toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
spec('should match [attribute=value]', async () => {
expect('[attribute=value]').toMatch(new RegExp(ATTRIBUTE_REGEX));
});

spec("&[attribute*='value'] {}", async () => {
expect("&[attribute*='value'] {}").toMatch(new RegExp(NESTED_ATTRIBUTE_REGEX));
spec('should match [attribute*=value]', async () => {
expect('[attribute*=value]').toMatch(new RegExp(ATTRIBUTE_REGEX));
});

spec('should &.class', async () => {
expect('&.class').toMatch(new RegExp(NESTED_CLASS_REGEX));
spec('should match .class', async () => {
expect('.class').toMatch(new RegExp(CLASS_REGEX));
});

spec('should &.class {}', async () => {
expect('&.class {}').toMatch(new RegExp(NESTED_CLASS_REGEX));
spec('should match --modifier', async () => {
expect('--modifier').toMatch(new RegExp(MODIFIER_REGEX));
});

// spec('should &--modifier', async () => {
// expect('&--modifier').toMatch(new RegExp(MODIFIER_REGEX));
// });
spec('should match __element', async () => {
expect('__element').toMatch(new RegExp(ELEMENT_REGEX));
});

spec('should match sibling selector', async () => {
expect('+ p').toMatch(new RegExp(SIBLING_REGEX));
});

spec('should match child selector', async () => {
expect('> p').toMatch(new RegExp(CHILD_REGEX));
});

spec('should match sibling selector', async () => {
expect('div + p').toMatch(new RegExp(SIBLING_REGEX));
});

// spec('should &--modifier {}', async () => {
// expect('&--modifier {}').toMatch(new RegExp(MODIFIER_REGEX));
// });
spec('should match child selector', async () => {
expect('div > p').toMatch(new RegExp(CHILD_REGEX));
});

spec('should match attribute sibling selector', async () => {
expect('[attribute] + p').toMatch(new RegExp(ATTRIBUTE_SIBLING_REGEX));
});

spec('should match attribute child selector', async () => {
expect('[attribute] > p').toMatch(new RegExp(ATTRIBUTE_CHILD_REGEX));
});

spec('should match class sibling selector', async () => {
expect('.class + p').toMatch(new RegExp(CLASS_SIBLING_REGEX));
});

spec('should match class child selector', async () => {
expect('.class > p').toMatch(new RegExp(CLASS_CHILD_REGEX));
});

spec('should match nested attribute sibling selector', async () => {
expect('&[attribute] + p').toMatch(new RegExp(NESTED_ATTRIBUTE_SIBLING_REGEX));
});

spec('should match nested attribute child selector', async () => {
expect('&[attribute] > p').toMatch(new RegExp(NESTED_ATTRIBUTE_CHILD_REGEX));
});

spec('should match nested class sibling selector', async () => {
expect('&.class + p').toMatch(new RegExp(NESTED_CLASS_SIBLING_REGEX));
});

spec('should match nested class child selector', async () => {
expect('&.class > p').toMatch(new RegExp(NESTED_CLASS_CHILD_REGEX));
});
});
4 changes: 2 additions & 2 deletions src/validators/font-file-name.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ITALIC_REGEX } from './italic.ts';
import { VARIABLE_REGEX } from './variable.ts';
import { ITALIC_REGEX } from './helpers/italic.ts';
import { VARIABLE_REGEX } from './helpers/variable.ts';

const LETTERS_REGEX = '[A-Z][a-z]';
const FONT_FAMILY_REGEX = `^${LETTERS_REGEX}+(${LETTERS_REGEX}+)?`;
Expand Down
File renamed without changes.
File renamed without changes.
Loading