From 615c19bb079151624cda87c336477472b7caca9d Mon Sep 17 00:00:00 2001 From: Alan Smithee Date: Fri, 23 Oct 2015 12:01:44 +0000 Subject: [PATCH] adds implementation and test for attribute contains selector #2 --- src/core/selector-type.js | 27 ++++++++++++++------------- test/get-type.js | 4 ++++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/core/selector-type.js b/src/core/selector-type.js index b1f3dd3..c24e58d 100644 --- a/src/core/selector-type.js +++ b/src/core/selector-type.js @@ -45,19 +45,19 @@ const SelectorCategoryRegex = { const SelectorTypeRegex = { None : '', Invalid : '', - Universal : /\*/, // * - Type : /^[A-Za-z]+$/, // E - TypeClass : /^[A-Za-z]+\.[A-Za-z]+$/, // E.Class - TypeId : /^[A-Za-z]+\#[A-Za-z]+$/, // E#Id - Class : /^\.[A-Za-z]+$/, // .Class - Id : /^\#[A-Za-z]+$/, // #Id - Attribute : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr] - AttributeExact : /^[A-Za-z]+\[[A-Za-z]+\=\"[A-Za-z]+\"\]$/, // E[attr=value] - AttributeExactHyphen : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr|=value] - AttributeList : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr~=value] - AttributePrefix : /^[A-Za-z]+\[[A-Za-z]+\^\=\"[A-Za-z]+\"\]$/, // E[attr^=value] - AttributeSuffix : /^[A-Za-z]+\[[A-Za-z]+\$\=\"[A-Za-z]+\"\]$/, // E[attr$=value] - AttributeContains : /^[A-Za-z]+\[[A-Za-z]+\]$/ // E[attr*=value] + Universal : /\*/, // * + Type : /^[A-Za-z]+$/, // E + TypeClass : /^[A-Za-z]+\.[A-Za-z]+$/, // E.Class + TypeId : /^[A-Za-z]+\#[A-Za-z]+$/, // E#Id + Class : /^\.[A-Za-z]+$/, // .Class + Id : /^\#[A-Za-z]+$/, // #Id + Attribute : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr] + AttributeExact : /^[A-Za-z]+\[[A-Za-z]+\=\"[A-Za-z]+\"\]$/, // E[attr=value] + AttributeExactHyphen : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr|=value] + AttributeList : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr~=value] + AttributePrefix : /^[A-Za-z]+\[[A-Za-z]+\^\=\"[A-Za-z]+\"\]$/, // E[attr^=value] + AttributeSuffix : /^[A-Za-z]+\[[A-Za-z]+\$\=\"[A-Za-z]+\"\]$/, // E[attr$=value] + AttributeContains : /^[A-Za-z]+\[[A-Za-z]+\*\=\"[A-Za-z]+\"\]$/ // E[attr*=value] }; /** @@ -79,6 +79,7 @@ export default function getType(selector) { if (SelectorCategoryRegex.Attribute.test(selector)) { return SelectorTypeRegex.AttributePrefix.test(selector) ? SelectorType.AttributePrefix : SelectorTypeRegex.AttributeSuffix.test(selector) ? SelectorType.AttributeSuffix : + SelectorTypeRegex.AttributeContains.test(selector) ? SelectorType.AttributeContains : SelectorTypeRegex.AttributeExact.test(selector) ? SelectorType.AttributeExact : SelectorTypeRegex.Attribute.test(selector) ? SelectorType.Attribute : SelectorType.Invalid; diff --git a/test/get-type.js b/test/get-type.js index be54011..3056f73 100644 --- a/test/get-type.js +++ b/test/get-type.js @@ -28,6 +28,10 @@ describe('getType(selector)', function() { expect(getType('a[href$="a"]')).to.equal(SelectorType.AttributeSuffix); }); + it('Attribute contains selector (E[foo*="bar"])', () => { + expect(getType('a[href*="a"]')).to.equal(SelectorType.AttributeContains); + }); + it('Class selector (.class)', () => { expect(getType('.class')).to.equal(SelectorType.Class); });