diff --git a/.github/workflows/mocha.yaml b/.github/workflows/mocha.yaml index b554839..e9c7948 100644 --- a/.github/workflows/mocha.yaml +++ b/.github/workflows/mocha.yaml @@ -1,11 +1,11 @@ name: Mocha on: - workflow_run: - workflows: - - ESLint - types: - - completed + # workflow_run: + # workflows: + # - ESLint + # types: + # - completed pull_request: branches: - main diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9e2b4d1..5c07ece 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,11 +1,11 @@ name: Release on: - # workflow_run: - # workflows: - # - Mocha - # types: - # - completed + workflow_run: + workflows: + - Mocha + types: + - completed push: branches: - main diff --git a/specs/creators/at-rule.spec.js b/specs/creators/at-rule.spec.js new file mode 100644 index 0000000..4a1fbea --- /dev/null +++ b/specs/creators/at-rule.spec.js @@ -0,0 +1,20 @@ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; + +import createAtRule from '../../src/creators/at-rule.js'; + +describe('Create At Rule', () => { + it('create an object with args (name: String, hasBlock: true)', () => { + const rule = createAtRule('test-rule', true); + + expect(rule).to.have.property('name', 'test-rule'); + expect(rule).to.have.property('hasBlock', true); + }); + + it('create an object with args (name: String, hasBlock: false)', () => { + const rule = createAtRule('test-rule', false); + + expect(rule).to.have.property('name', 'test-rule'); + expect(rule).to.have.property('hasBlock', false); + }); +}); diff --git a/specs/creators/logical-group.spec.js b/specs/creators/logical-group.spec.js new file mode 100644 index 0000000..1ba7126 --- /dev/null +++ b/specs/creators/logical-group.spec.js @@ -0,0 +1,14 @@ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; + +import createLogicalGroup from '../../src/creators/logical-group.js'; + +describe('Create Logical Group', () => { + it('create an object with args (groupName: String, properties: Array)', () => { + const properties = ['display', 'z-index']; + const logicalGroup = createLogicalGroup('Test Group Name', properties); + + expect(logicalGroup).to.have.property('groupName', 'Test Group Name'); + expect(logicalGroup).to.have.property('properties', properties); + }); +}); diff --git a/specs/creators/rule.spec.js b/specs/creators/rule.spec.js new file mode 100644 index 0000000..051d9ed --- /dev/null +++ b/specs/creators/rule.spec.js @@ -0,0 +1,42 @@ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; + +import createRule from '../../src/creators/rule.js'; + +describe('Create Rule', () => { + it('create an object with args (selector: String, [::pseudo-element])', () => { + const rule = createRule('::pseudo-element'); + + expect(rule).to.have.property('selector', '&::pseudo-element'); + }); + + it('create an object with args (selector: String, [:pseudo-class])', () => { + const rule = createRule(':pseudo-class'); + + expect(rule).to.have.property('selector', '&:pseudo-class'); + }); + + it('create an object with args (selector: RegExp, [\\[[^\\[\\]]+\\]])', () => { + const rule = createRule('\\[[^\\[\\]]+\\]'); + + expect(rule).to.have.property('selector', '&\\[[^\\[\\]]+\\]'); + }); + + it('create an object with args (selector: RegExp, [\\..+])', () => { + const rule = createRule('\\..+'); + + expect(rule).to.have.property('selector', '&\\..+'); + }); + + it('create an object with args (selector: RegExp, [--.+])', () => { + const rule = createRule('--.+'); + + expect(rule).to.have.property('selector', '&--.+'); + }); + + it('create an object with args (selector: RegExp, [?.* &])', () => { + const rule = createRule('?.* &'); + + expect(rule).to.have.property('selector', '&?.* &'); + }); +}); diff --git a/specs/index.spec.js b/specs/index.spec.js deleted file mode 100644 index a5fa478..0000000 --- a/specs/index.spec.js +++ /dev/null @@ -1 +0,0 @@ -console.log('Tests'); diff --git a/specs/regex/bem-pattern.spec.js b/specs/regex/bem-pattern.spec.js new file mode 100644 index 0000000..b7598da --- /dev/null +++ b/specs/regex/bem-pattern.spec.js @@ -0,0 +1,24 @@ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; + +import CSSRules from '../../src/rules/css.js'; + +describe('BEM Class Pattern', () => { + const BEMClassPattern = new RegExp(CSSRules['selector-class-pattern'][0]); + + it('block (String, [block])', () => { + expect('block').to.match(BEMClassPattern); + }); + + it('block with modifier (String, [block--modifier])', () => { + expect('block--modifier').to.match(BEMClassPattern); + }); + + it('block and element (String, [block__element])', () => { + expect('block__element').to.match(BEMClassPattern); + }); + + it('block and element with modifier (String, [block__element--modifier])', () => { + expect('block__element--modifier').to.match(BEMClassPattern); + }); +}); diff --git a/specs/regex/regex.spec.js b/specs/regex/regex.spec.js new file mode 100644 index 0000000..dc5ddf7 --- /dev/null +++ b/specs/regex/regex.spec.js @@ -0,0 +1,22 @@ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; + +import REGEXP from '../../src/utils/regexps.js'; + +describe('Nested Selectors Pattern', () => { + it('nested (String, [&[attribute]])', () => { + expect('&[attribute]').to.match(new RegExp(`&${REGEXP.NESTED.ATTRIBUTE}`)); + }); + + it('nested (String, [&.class])', () => { + expect('&.class').to.match(new RegExp(`&${REGEXP.NESTED.CLASS}`)); + }); + + it('nested (String, [&--modifier])', () => { + expect('&--modifier').to.match(new RegExp(`&${REGEXP.NESTED.MODIFIER}`)); + }); + + it('nested (String, [.class &])', () => { + expect('.class &').to.match(new RegExp(`&${REGEXP.NESTED.PARENT}`)); + }); +}); diff --git a/src/utils/create-at-rule.js b/src/creators/at-rule.js similarity index 100% rename from src/utils/create-at-rule.js rename to src/creators/at-rule.js diff --git a/src/utils/create-logical-group.js b/src/creators/logical-group.js similarity index 100% rename from src/utils/create-logical-group.js rename to src/creators/logical-group.js diff --git a/src/utils/create-rule.js b/src/creators/rule.js similarity index 100% rename from src/utils/create-rule.js rename to src/creators/rule.js diff --git a/src/properties/order.js b/src/properties/order.js index ce79b7f..23fe9f9 100644 --- a/src/properties/order.js +++ b/src/properties/order.js @@ -4,9 +4,9 @@ import nonStandard from './non-standard.js'; import REGEXP from '../utils/regexps.js'; -import createLogicalGroup from '../utils/create-logical-group.js'; -import createAtRule from '../utils/create-at-rule.js'; -import createRule from '../utils/create-rule.js'; +import createLogicalGroup from '../creators/logical-group.js'; +import createAtRule from '../creators/at-rule.js'; +import createRule from '../creators/rule.js'; const propertiesOrder = { 'order/order': [