@@ -25,44 +25,44 @@ export function main() {
2525 it ( 'should select by element name case insensitive' , ( ) => {
2626 matcher . addSelectable ( s1 = CssSelector . parse ( 'someTag' ) , 1 ) ;
2727
28- matcher . match ( CssSelector . parse ( 'SOMEOTHERTAG' ) , selectableCollector ) ;
28+ expect ( matcher . match ( CssSelector . parse ( 'SOMEOTHERTAG' ) , selectableCollector ) ) . toEqual ( false ) ;
2929 expect ( matched ) . toEqual ( [ ] ) ;
3030
31- matcher . match ( CssSelector . parse ( 'SOMETAG' ) , selectableCollector ) ;
31+ expect ( matcher . match ( CssSelector . parse ( 'SOMETAG' ) , selectableCollector ) ) . toEqual ( true ) ;
3232 expect ( matched ) . toEqual ( [ s1 , 1 ] ) ;
3333 } ) ;
3434
3535 it ( 'should select by class name case insensitive' , ( ) => {
3636 matcher . addSelectable ( s1 = CssSelector . parse ( '.someClass' ) , 1 ) ;
3737 matcher . addSelectable ( s2 = CssSelector . parse ( '.someClass.class2' ) , 2 ) ;
3838
39- matcher . match ( CssSelector . parse ( '.SOMEOTHERCLASS' ) , selectableCollector ) ;
39+ expect ( matcher . match ( CssSelector . parse ( '.SOMEOTHERCLASS' ) , selectableCollector ) ) . toEqual ( false ) ;
4040 expect ( matched ) . toEqual ( [ ] ) ;
4141
42- matcher . match ( CssSelector . parse ( '.SOMECLASS' ) , selectableCollector ) ;
42+ expect ( matcher . match ( CssSelector . parse ( '.SOMECLASS' ) , selectableCollector ) ) . toEqual ( true ) ;
4343 expect ( matched ) . toEqual ( [ s1 , 1 ] ) ;
4444
4545 reset ( ) ;
46- matcher . match ( CssSelector . parse ( '.someClass.class2' ) , selectableCollector ) ;
46+ expect ( matcher . match ( CssSelector . parse ( '.someClass.class2' ) , selectableCollector ) ) . toEqual ( true ) ;
4747 expect ( matched ) . toEqual ( [ s1 , 1 , s2 , 2 ] ) ;
4848 } ) ;
4949
5050 it ( 'should select by attr name case insensitive independent of the value' , ( ) => {
5151 matcher . addSelectable ( s1 = CssSelector . parse ( '[someAttr]' ) , 1 ) ;
5252 matcher . addSelectable ( s2 = CssSelector . parse ( '[someAttr][someAttr2]' ) , 2 ) ;
5353
54- matcher . match ( CssSelector . parse ( '[SOMEOTHERATTR]' ) , selectableCollector ) ;
54+ expect ( matcher . match ( CssSelector . parse ( '[SOMEOTHERATTR]' ) , selectableCollector ) ) . toEqual ( false ) ;
5555 expect ( matched ) . toEqual ( [ ] ) ;
5656
57- matcher . match ( CssSelector . parse ( '[SOMEATTR]' ) , selectableCollector ) ;
57+ expect ( matcher . match ( CssSelector . parse ( '[SOMEATTR]' ) , selectableCollector ) ) . toEqual ( true ) ;
5858 expect ( matched ) . toEqual ( [ s1 , 1 ] ) ;
5959
6060 reset ( ) ;
61- matcher . match ( CssSelector . parse ( '[SOMEATTR=someValue]' ) , selectableCollector ) ;
61+ expect ( matcher . match ( CssSelector . parse ( '[SOMEATTR=someValue]' ) , selectableCollector ) ) . toEqual ( true ) ;
6262 expect ( matched ) . toEqual ( [ s1 , 1 ] ) ;
6363
6464 reset ( ) ;
65- matcher . match ( CssSelector . parse ( '[someAttr][someAttr2]' ) , selectableCollector ) ;
65+ expect ( matcher . match ( CssSelector . parse ( '[someAttr][someAttr2]' ) , selectableCollector ) ) . toEqual ( true ) ;
6666 expect ( matched ) . toEqual ( [ s1 , 1 , s2 , 2 ] ) ;
6767 } ) ;
6868
@@ -80,29 +80,29 @@ export function main() {
8080 it ( 'should select by attr name and value case insensitive' , ( ) => {
8181 matcher . addSelectable ( s1 = CssSelector . parse ( '[someAttr=someValue]' ) , 1 ) ;
8282
83- matcher . match ( CssSelector . parse ( '[SOMEATTR=SOMEOTHERATTR]' ) , selectableCollector ) ;
83+ expect ( matcher . match ( CssSelector . parse ( '[SOMEATTR=SOMEOTHERATTR]' ) , selectableCollector ) ) . toEqual ( false ) ;
8484 expect ( matched ) . toEqual ( [ ] ) ;
8585
86- matcher . match ( CssSelector . parse ( '[SOMEATTR=SOMEVALUE]' ) , selectableCollector ) ;
86+ expect ( matcher . match ( CssSelector . parse ( '[SOMEATTR=SOMEVALUE]' ) , selectableCollector ) ) . toEqual ( true ) ;
8787 expect ( matched ) . toEqual ( [ s1 , 1 ] ) ;
8888 } ) ;
8989
9090 it ( 'should select by element name, class name and attribute name with value' , ( ) => {
9191 matcher . addSelectable ( s1 = CssSelector . parse ( 'someTag.someClass[someAttr=someValue]' ) , 1 ) ;
9292
93- matcher . match ( CssSelector . parse ( 'someOtherTag.someOtherClass[someOtherAttr]' ) , selectableCollector ) ;
93+ expect ( matcher . match ( CssSelector . parse ( 'someOtherTag.someOtherClass[someOtherAttr]' ) , selectableCollector ) ) . toEqual ( false ) ;
9494 expect ( matched ) . toEqual ( [ ] ) ;
9595
96- matcher . match ( CssSelector . parse ( 'someTag.someOtherClass[someOtherAttr]' ) , selectableCollector ) ;
96+ expect ( matcher . match ( CssSelector . parse ( 'someTag.someOtherClass[someOtherAttr]' ) , selectableCollector ) ) . toEqual ( false ) ;
9797 expect ( matched ) . toEqual ( [ ] ) ;
9898
99- matcher . match ( CssSelector . parse ( 'someTag.someClass[someOtherAttr]' ) , selectableCollector ) ;
99+ expect ( matcher . match ( CssSelector . parse ( 'someTag.someClass[someOtherAttr]' ) , selectableCollector ) ) . toEqual ( false ) ;
100100 expect ( matched ) . toEqual ( [ ] ) ;
101101
102- matcher . match ( CssSelector . parse ( 'someTag.someClass[someAttr]' ) , selectableCollector ) ;
102+ expect ( matcher . match ( CssSelector . parse ( 'someTag.someClass[someAttr]' ) , selectableCollector ) ) . toEqual ( false ) ;
103103 expect ( matched ) . toEqual ( [ ] ) ;
104104
105- matcher . match ( CssSelector . parse ( 'someTag.someClass[someAttr=someValue]' ) , selectableCollector ) ;
105+ expect ( matcher . match ( CssSelector . parse ( 'someTag.someClass[someAttr=someValue]' ) , selectableCollector ) ) . toEqual ( true ) ;
106106 expect ( matched ) . toEqual ( [ s1 , 1 ] ) ;
107107 } ) ;
108108
@@ -112,21 +112,42 @@ export function main() {
112112 matcher . addSelectable ( s3 = CssSelector . parse ( '.class1.class2' ) , 3 ) ;
113113 matcher . addSelectable ( s4 = CssSelector . parse ( '.class2.class1' ) , 4 ) ;
114114
115- matcher . match ( CssSelector . parse ( '[someAttr].someClass' ) , selectableCollector ) ;
115+ expect ( matcher . match ( CssSelector . parse ( '[someAttr].someClass' ) , selectableCollector ) ) . toEqual ( true ) ;
116116 expect ( matched ) . toEqual ( [ s1 , 1 , s2 , 2 ] ) ;
117117
118118 reset ( ) ;
119- matcher . match ( CssSelector . parse ( '.someClass[someAttr]' ) , selectableCollector ) ;
119+ expect ( matcher . match ( CssSelector . parse ( '.someClass[someAttr]' ) , selectableCollector ) ) . toEqual ( true ) ;
120120 expect ( matched ) . toEqual ( [ s1 , 1 , s2 , 2 ] ) ;
121121
122122 reset ( ) ;
123- matcher . match ( CssSelector . parse ( '.class1.class2' ) , selectableCollector ) ;
123+ expect ( matcher . match ( CssSelector . parse ( '.class1.class2' ) , selectableCollector ) ) . toEqual ( true ) ;
124124 expect ( matched ) . toEqual ( [ s3 , 3 , s4 , 4 ] ) ;
125125
126126 reset ( ) ;
127- matcher . match ( CssSelector . parse ( '.class2.class1' ) , selectableCollector ) ;
127+ expect ( matcher . match ( CssSelector . parse ( '.class2.class1' ) , selectableCollector ) ) . toEqual ( true ) ;
128128 expect ( matched ) . toEqual ( [ s4 , 4 , s3 , 3 ] ) ;
129129 } ) ;
130+
131+ it ( 'should not select with a matching :not selector' , ( ) => {
132+ matcher . addSelectable ( CssSelector . parse ( 'p:not(.someClass)' ) , 1 ) ;
133+ matcher . addSelectable ( CssSelector . parse ( 'p:not([someAttr])' ) , 2 ) ;
134+ matcher . addSelectable ( CssSelector . parse ( ':not(.someClass)' ) , 3 ) ;
135+ matcher . addSelectable ( CssSelector . parse ( ':not(p)' ) , 4 ) ;
136+ matcher . addSelectable ( CssSelector . parse ( ':not(p[someAttr])' ) , 5 ) ;
137+
138+ expect ( matcher . match ( CssSelector . parse ( 'p.someClass[someAttr]' ) , selectableCollector ) ) . toEqual ( false ) ;
139+ expect ( matched ) . toEqual ( [ ] ) ;
140+ } ) ;
141+
142+ it ( 'should select with a non matching :not selector' , ( ) => {
143+ matcher . addSelectable ( s1 = CssSelector . parse ( 'p:not(.someClass)' ) , 1 ) ;
144+ matcher . addSelectable ( s2 = CssSelector . parse ( 'p:not(.someOtherClass[someAttr])' ) , 2 ) ;
145+ matcher . addSelectable ( s3 = CssSelector . parse ( ':not(.someClass)' ) , 3 ) ;
146+ matcher . addSelectable ( s4 = CssSelector . parse ( ':not(.someOtherClass[someAttr])' ) , 4 ) ;
147+
148+ expect ( matcher . match ( CssSelector . parse ( 'p[someOtherAttr].someOtherClass' ) , selectableCollector ) ) . toEqual ( true ) ;
149+ expect ( matched ) . toEqual ( [ s1 , 1 , s2 , 2 , s3 , 3 , s4 , 4 ] ) ;
150+ } ) ;
130151 } ) ;
131152
132153 describe ( 'CssSelector.parse' , ( ) => {
@@ -164,5 +185,36 @@ export function main() {
164185
165186 expect ( cssSelector . toString ( ) ) . toEqual ( 'sometag.someclass[attrname=attrvalue]' ) ;
166187 } ) ;
188+
189+ it ( 'should detect :not' , ( ) => {
190+ var cssSelector = CssSelector . parse ( 'sometag:not([attrname=attrvalue].someclass)' ) ;
191+ expect ( cssSelector . element ) . toEqual ( 'sometag' ) ;
192+ expect ( cssSelector . attrs . length ) . toEqual ( 0 ) ;
193+ expect ( cssSelector . classNames . length ) . toEqual ( 0 ) ;
194+
195+ var notSelector = cssSelector . notSelector ;
196+ expect ( notSelector . element ) . toEqual ( null ) ;
197+ expect ( notSelector . attrs ) . toEqual ( [ 'attrname' , 'attrvalue' ] ) ;
198+ expect ( notSelector . classNames ) . toEqual ( [ 'someclass' ] ) ;
199+
200+ expect ( cssSelector . toString ( ) ) . toEqual ( 'sometag:not(.someclass[attrname=attrvalue])' ) ;
201+ } ) ;
202+
203+ it ( 'should detect :not without truthy' , ( ) => {
204+ var cssSelector = CssSelector . parse ( ':not([attrname=attrvalue].someclass)' ) ;
205+ expect ( cssSelector . element ) . toEqual ( "*" ) ;
206+
207+ var notSelector = cssSelector . notSelector ;
208+ expect ( notSelector . attrs ) . toEqual ( [ 'attrname' , 'attrvalue' ] ) ;
209+ expect ( notSelector . classNames ) . toEqual ( [ 'someclass' ] ) ;
210+
211+ expect ( cssSelector . toString ( ) ) . toEqual ( '*:not(.someclass[attrname=attrvalue])' ) ;
212+ } ) ;
213+
214+ it ( 'should throw when nested :not' , ( ) => {
215+ expect ( ( ) => {
216+ CssSelector . parse ( 'sometag:not(:not([attrname=attrvalue].someclass))' )
217+ } ) . toThrowError ( 'Nesting :not is not allowed in a selector' ) ;
218+ } ) ;
167219 } ) ;
168220}
0 commit comments