Skip to content

Commit

Permalink
fixes selector deduction code to handle invalid selectors #2
Browse files Browse the repository at this point in the history
  • Loading branch information
GGAlanSmithee committed Oct 20, 2015
1 parent 6940a73 commit 0827f46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/core/selector-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const Regex = {
None : '',
Invalid : '',
Universal : /\*/,
Type : /^[A-Za-z]/,
TypeCategory : /^[A-Za-z]+/,
Type : /^[A-Za-z]+$/,
TypeClass : /^[A-Za-z]+\.[A-Za-z]+$/,
TypeId : /^[A-Za-z]+\#[A-Za-z]+$/,
Class : /^\.[A-Za-z]+$/,
Expand All @@ -48,16 +49,15 @@ const Regex = {
* @return {SelectorType} type
*/
export default function getType(selector) {
console.log(selector, /^.[A-Za-z]+$/.test(selector));

if (selector === '*') {
return SelectorType.Universal;
}

if (Regex.Type.test(selector)) {
if (Regex.TypeCategory.test(selector)) {
return Regex.TypeClass.test(selector) ? SelectorType.TypeClass :
Regex.TypeId.test(selector) ? SelectorType.TypeId :
SelectorType.Type;
Regex.Type.test(selector) ? SelectorType.Type :
SelectorType.Invalid;
}

return Regex.Class.test(selector) ? SelectorType.Class :
Expand Down
4 changes: 4 additions & 0 deletions test/get-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import getType, { SelectorType } from '../src/core/selector-type';

describe('getType(selector)', function() {
describe('Selectors', () => {
it('Invalid selector (E E)', () => {
expect(getType('e e')).to.equal(SelectorType.Invalid);
});

it('Type selector (E)', () => {
expect(getType('div')).to.equal(SelectorType.Type);
});
Expand Down

0 comments on commit 0827f46

Please sign in to comment.