Skip to content

Commit

Permalink
Fix isStandardSyntaxTypeSelector.test.js that use callbacks (#4990)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Nov 17, 2020
1 parent bb19b6c commit 2db70e9
Showing 1 changed file with 32 additions and 60 deletions.
92 changes: 32 additions & 60 deletions lib/utils/__tests__/isStandardSyntaxTypeSelector.test.js
Expand Up @@ -6,101 +6,73 @@ const selectorParser = require('postcss-selector-parser');

describe('isStandardSyntaxTypeSelector', () => {
it('tag', () => {
rules('a {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeTruthy();
});
expect(isStandardSyntaxTypeSelector(tag('a {}'))).toBe(true);
});
it('lowercase nth-child pseudo selector', () => {
rules('.foo:nth-child(n) {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag('.foo:nth-child(n) {}'))).toBe(false);
});
it('mixedcase nth-child pseudo selector', () => {
rules('.foo:nTh-ChIlD(n) {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag('.foo:nTh-ChIlD(n) {}'))).toBe(false);
});
it('uppercase nth-child pseudo selector', () => {
rules('.foo:NTH-CHILD(n) {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag('.foo:NTH-CHILD(n) {}'))).toBe(false);
});
it('nth-last-child pseudo selector', () => {
rules('.foo:nth-last-child(n) {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag('.foo:nth-last-child(n) {}'))).toBe(false);
});
it('nth-of-type pseudo selector', () => {
rules('.foo:nth-of-type(n) {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag('.foo:nth-of-type(n) {}'))).toBe(false);
});
it('lowercase lang pseudo selector', () => {
rules(':lang(en) {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag(':lang(en) {}'))).toBe(false);
});
it('mixedcase lang pseudo selector', () => {
rules(':lAnG(en) {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag(':lAnG(en) {}'))).toBe(false);
});
it('uppercase lang pseudo selector', () => {
rules(':LANG(en) {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag(':LANG(en) {}'))).toBe(false);
});
it('dir pseudo selector', () => {
rules(':dir(ltr) {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag(':dir(ltr) {}'))).toBe(false);
});
it('nesting selector', () => {
rules('.foo { &-bar {} }', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag('.foo { &-bar {} }'))).toBe(false);
});
it('nesting selector underscores', () => {
rules('.foo { &__bar {} }', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag('.foo { &__bar {} }'))).toBe(false);
});
it('placeholder selector', () => {
rules('%foo {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag('%foo {}'))).toBe(false);
});
it('shadow-piercing descendant combinator', () => {
rules('.foo /deep/ .bar {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
// eslint-disable-next-line jest/no-disabled-tests -- "Reference combinator" is unsupported? (see #2508)
it.skip('shadow-piercing descendant combinator', () => {
expect(isStandardSyntaxTypeSelector(tag('.foo /deep/ .bar {}'))).toBe(false);
});
it('shadow-parts ident', () => {
rules('::part(foo) {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
expect(isStandardSyntaxTypeSelector(tag('::part(foo) {}'))).toBe(false);
});
it('lowercase reference combinators', () => {
rules('.foo /for/ .bar {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
// eslint-disable-next-line jest/no-disabled-tests -- "Reference combinator" is unsupported? (see #2508)
it.skip('lowercase reference combinators', () => {
expect(isStandardSyntaxTypeSelector(tag('.foo /for/ .bar {}'))).toBe(false);
});
it('mixedcase reference combinators', () => {
rules('.foo /fOr/ .bar {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
// eslint-disable-next-line jest/no-disabled-tests -- "Reference combinator" is unsupported? (see #2508)
it.skip('mixedcase reference combinators', () => {
expect(isStandardSyntaxTypeSelector(tag('.foo /fOr/ .bar {}'))).toBe(false);
});
it('uppercase reference combinators', () => {
rules('.foo /FOR/ .bar {}', (func) => {
expect(isStandardSyntaxTypeSelector(func)).toBeFalsy();
});
// eslint-disable-next-line jest/no-disabled-tests -- "Reference combinator" is unsupported? (see #2508)
it.skip('uppercase reference combinators', () => {
expect(isStandardSyntaxTypeSelector(tag('.foo /FOR/ .bar {}'))).toBe(false);
});
});

function rules(css, cb) {
function tag(css) {
const tags = [];

postcss.parse(css).walkRules((rule) => {
selectorParser((selectorAST) => {
selectorAST.walkTags(cb);
selectorAST.walkTags((t) => tags.push(t));
}).processSync(rule.selector);
});

return tags[0];
}

0 comments on commit 2db70e9

Please sign in to comment.