Skip to content

Commit

Permalink
adds test for attribute selector #2
Browse files Browse the repository at this point in the history
  • Loading branch information
GGAlanSmithee committed Oct 20, 2015
1 parent 7ccad38 commit e5f1735
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/core/selector-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ export const SelectorType = {
Typeid : 4,
Class : 5,
Id : 6,
DescendantCombinator : 7,
ChildCombinator : 8,
AdjacentSiblingCombinator : 9,
GeneralSiblingCombinator : 10
Attribute : 7,
DescendantCombinator : 8,
ChildCombinator : 9,
AdjacentSiblingCombinator : 10,
GeneralSiblingCombinator : 11
};

/**
Expand All @@ -44,7 +45,7 @@ const SelectorTypeRegex = {
TypeId : /^[A-Za-z]+\#[A-Za-z]+$/,
Class : /^\.[A-Za-z]+$/,
Id : /^\#[A-Za-z]+$/,

Attribute : /^\#[A-Za-z]+\[[A-Za-z]\]$/
};

/**
Expand All @@ -71,7 +72,8 @@ export default function getType(selector) {
}

if (SelectorCategoryRegex.Attribute.test(selector)) {
return SelectorType.Invalid;
return SelectorTypeRegex.Attribute.test(selector) ? SelectorType.Attribute :
SelectorType.Invalid;
}

return SelectorTypeRegex.Class.test(selector) ? SelectorType.Class :
Expand Down
8 changes: 6 additions & 2 deletions test/get-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ describe('getType(selector)', function() {
it('Invalid selector (E E)', () => {
expect(getType('e e')).to.equal(SelectorType.Invalid);
});

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

it('Attribute selector (E[foo])', () => {
expect(getType('div[test]')).to.equal(SelectorType.Attribute);
});

it('Class selector (.class)', () => {
expect(getType('.class')).to.equal(SelectorType.Class);
});
Expand All @@ -24,7 +28,7 @@ describe('getType(selector)', function() {
expect(getType('#id')).to.equal(SelectorType.Id);
});

it('Element.Id selector (E#id)', () => {
it('Element#Id selector (E#id)', () => {
expect(getType('E#div')).to.equal(SelectorType.TypeId);
});
});
Expand Down

0 comments on commit e5f1735

Please sign in to comment.