-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate with a CSS parser for selector parsing #1086
Changes from 1 commit
8177e26
0d4a7eb
51ff0e7
26bf200
fa80c0e
b18cfe4
5dde9c6
f20b0c4
d7abfbe
8bffb8a
10019da
5efaf08
83c6f04
8b3e008
1a73724
36e10d2
ae733ee
60b6a86
2c3227b
d0d810e
459108a
188ed1c
17f366d
aadbc4a
a79e150
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,10 +68,13 @@ describe('RSTTraversal', () => { | |
expect(nodeHasProperty(node, 'title')).to.equal(false); | ||
}); | ||
|
||
it('should parse false', () => { | ||
const node = $(<div foo={false} />); | ||
|
||
expect(nodeHasProperty(node, 'foo', false)).to.equal(true); | ||
it('should parse booleans', () => { | ||
expect(nodeHasProperty(<div foo />, 'foo', true)).to.equal(true); | ||
expect(nodeHasProperty(<div foo />, 'foo', false)).to.equal(false); | ||
expect(nodeHasProperty(<div foo />, 'foo', 'true')).to.equal(false); | ||
expect(nodeHasProperty(<div foo={false} />, 'foo', false)).to.equal(true); | ||
expect(nodeHasProperty(<div foo={false} />, 'foo', true)).to.equal(false); | ||
expect(nodeHasProperty(<div foo={false} />, 'foo', 'false')).to.equal(false); | ||
}); | ||
|
||
it('should parse numeric literals', () => { | ||
|
@@ -89,11 +92,14 @@ describe('RSTTraversal', () => { | |
expect(nodeHasProperty(<div foo={0} />, 'foo', 0)).to.equal(true); | ||
expect(nodeHasProperty(<div foo={0} />, 'foo', +0)).to.equal(true); | ||
expect(nodeHasProperty(<div foo={-0} />, 'foo', -0)).to.equal(true); | ||
expect(nodeHasProperty(<div foo={-0} />, 'foo', 0)).to.equal(false); | ||
expect(nodeHasProperty(<div foo={0} />, 'foo', -0)).to.equal(false); | ||
expect(nodeHasProperty(<div foo={1} />, 'foo', 0)).to.equal(false); | ||
expect(nodeHasProperty(<div foo={2} />, 'foo', -0)).to.equal(false); | ||
}); | ||
|
||
it('should work with empty strings', () => { | ||
expect(nodeHasProperty(<div foo="" />, 'foo', '')).to.equal(true); | ||
expect(nodeHasProperty(<div foo={''} />, 'foo', '')).to.equal(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for funsies, let's add |
||
expect(nodeHasProperty(<div foo={'bar'} />, 'foo', '')).to.equal(false); | ||
}); | ||
|
@@ -116,9 +122,13 @@ describe('RSTTraversal', () => { | |
it('should work with ±Infinity', () => { | ||
expect(nodeHasProperty(<div foo={Infinity} />, 'foo', Infinity)).to.equal(true); | ||
expect(nodeHasProperty(<div foo={Infinity} />, 'foo', +Infinity)).to.equal(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add a case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd also be good to ensure NaN and Infinity don't equate, since both are not finite |
||
expect(nodeHasProperty(<div foo={Infinity} />, 'foo', -Infinity)).to.equal(false); | ||
expect(nodeHasProperty(<div foo={Infinity} />, 'foo', 'Infinity')).to.equal(false); | ||
expect(nodeHasProperty(<div foo={0} />, 'foo', Infinity)).to.equal(false); | ||
expect(nodeHasProperty(<div foo={-Infinity} />, 'foo', -Infinity)).to.equal(true); | ||
expect(nodeHasProperty(<div foo={-Infinity} />, 'foo', Infinity)).to.equal(false); | ||
expect(nodeHasProperty(<div foo={-Infinity} />, 'foo', Infinity)).to.equal(false); | ||
expect(nodeHasProperty(<div foo={-Infinity} />, 'foo', '-Infinity')).to.equal(false); | ||
expect(nodeHasProperty(<div foo={0} />, 'foo', -Infinity)).to.equal(false); | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,8 +36,8 @@ describe('selectors', () => { | |
</div>, | ||
); | ||
|
||
expect(wrapper.find('span').length).to.equal(2); | ||
expect(wrapper.find('.top-div span').length).to.equal(1); | ||
expect(wrapper.find('span')).to.have.lengthOf(2); | ||
expect(wrapper.find('.top-div span')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('nested descendent', () => { | ||
|
@@ -55,8 +55,8 @@ describe('selectors', () => { | |
</div>, | ||
); | ||
|
||
expect(wrapper.find('h1').length).to.equal(3); | ||
expect(wrapper.find('.my-div h1').length).to.equal(2); | ||
expect(wrapper.find('h1')).to.have.lengthOf(3); | ||
expect(wrapper.find('.my-div h1')).to.have.lengthOf(2); | ||
}); | ||
|
||
it('deep descendent', () => { | ||
|
@@ -75,8 +75,8 @@ describe('selectors', () => { | |
</div>, | ||
); | ||
|
||
expect(wrapper.find('h1').length).to.equal(2); | ||
expect(wrapper.find('div .inner span .way-inner h1').length).to.equal(1); | ||
expect(wrapper.find('h1')).to.have.lengthOf(2); | ||
expect(wrapper.find('div .inner span .way-inner h1')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('direct descendent', () => { | ||
|
@@ -92,9 +92,9 @@ describe('selectors', () => { | |
</div>, | ||
); | ||
|
||
expect(wrapper.find('.to-find').length).to.equal(3); | ||
expect(wrapper.find('.to-find')).to.have.lengthOf(3); | ||
const descendent = wrapper.find('.container > .to-find'); | ||
expect(descendent.length).to.equal(1); | ||
expect(descendent).to.have.lengthOf(1); | ||
expect(descendent.text()).to.equal('Direct'); | ||
}); | ||
|
||
|
@@ -107,9 +107,9 @@ describe('selectors', () => { | |
</div>, | ||
); | ||
|
||
expect(wrapper.find('.sibling').length).to.equal(2); | ||
expect(wrapper.find('.sibling')).to.have.lengthOf(2); | ||
const toFind = wrapper.find('.to-find + .sibling'); | ||
expect(toFind.length).to.equal(1); | ||
expect(toFind).to.have.lengthOf(1); | ||
expect(toFind.text()).to.equal('Adjacent'); | ||
}); | ||
|
||
|
@@ -129,9 +129,9 @@ describe('selectors', () => { | |
</div>, | ||
); | ||
|
||
expect(wrapper.find('.to-find').length).to.equal(3); | ||
expect(wrapper.find('.to-find')).to.have.lengthOf(3); | ||
const toFind = wrapper.find('.to-find + .sibling'); | ||
expect(toFind.length).to.equal(2); | ||
expect(toFind).to.have.lengthOf(2); | ||
toFind.map(found => expect(found.text()).to.equal('Adjacent')); | ||
}); | ||
|
||
|
@@ -148,7 +148,7 @@ describe('selectors', () => { | |
</div>, | ||
); | ||
|
||
expect(wrapper.find('.to-find ~ span').length).to.equal(3); | ||
expect(wrapper.find('.to-find ~ span')).to.have.lengthOf(3); | ||
}); | ||
|
||
it('nested general siblings', () => { | ||
|
@@ -177,6 +177,7 @@ describe('selectors', () => { | |
const wrapper = renderMethod(<div className="foo" />); | ||
['is', 'filter', 'not', 'every'].forEach((method) => { | ||
expect(() => wrapper[method]('.foo + div')).to.throw( | ||
Error, | ||
'This method does not support complex CSS selectors', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly, can all these assert on both type and message? |
||
); | ||
}); | ||
|
@@ -209,7 +210,7 @@ describe('selectors', () => { | |
</div>, | ||
); | ||
|
||
expect(wrapper.find('.foo + div > span').length).to.equal(1); | ||
expect(wrapper.find('.foo + div > span')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('.foo + .foo + .foo', () => { | ||
|
@@ -220,10 +221,10 @@ describe('selectors', () => { | |
<div className="foo">foo3</div> | ||
</div>, | ||
); | ||
expect(wrapper.find('.foo + .foo').length).to.equal(2); | ||
expect(wrapper.find('.foo + .foo')).to.have.lengthOf(2); | ||
expect(wrapper.find('.foo + .foo').at(0).text()).to.equal('foo2'); | ||
expect(wrapper.find('.foo + .foo').at(1).text()).to.equal('foo3'); | ||
expect(wrapper.find('.foo + .foo + .foo').length).to.equal(1); | ||
expect(wrapper.find('.foo + .foo + .foo')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('attribute names with numbers', () => { | ||
|
@@ -235,10 +236,10 @@ describe('selectors', () => { | |
<div data-foo-2="2" /> | ||
</div>, | ||
); | ||
expect(wrapper.find('[data-foo-1=1]').length).to.equal(2); | ||
expect(wrapper.find('[data-foo-1="1"]').length).to.equal(0); | ||
expect(wrapper.find('[data-foo-2=2]').length).to.equal(1); | ||
expect(wrapper.find('[data-foo-2="2"]').length).to.equal(1); | ||
expect(wrapper.find('[data-foo-1=1]')).to.have.lengthOf(2); | ||
expect(wrapper.find('[data-foo-1="1"]')).to.have.lengthOf(0); | ||
expect(wrapper.find('[data-foo-2=2]')).to.have.lengthOf(1); | ||
expect(wrapper.find('[data-foo-2="2"]')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('hyphens', () => { | ||
|
@@ -250,13 +251,13 @@ describe('selectors', () => { | |
<span className="-foo" /> | ||
</div>, | ||
); | ||
expect(wrapper.find('.-foo').length).to.equal(3); | ||
expect(wrapper.find('.foo-').length).to.equal(1); | ||
expect(wrapper.find('[type="foo"].foo-').length).to.equal(1); | ||
expect(wrapper.find('.foo-.-bar-').length).to.equal(1); | ||
expect(wrapper.find('div.foo-').length).to.equal(1); | ||
expect(wrapper.find('div.-foo').length).to.equal(2); | ||
expect(wrapper.find('#bar.-foo').length).to.equal(1); | ||
expect(wrapper.find('.-foo')).to.have.lengthOf(3); | ||
expect(wrapper.find('.foo-')).to.have.lengthOf(1); | ||
expect(wrapper.find('[type="foo"].foo-')).to.have.lengthOf(1); | ||
expect(wrapper.find('.foo-.-bar-')).to.have.lengthOf(1); | ||
expect(wrapper.find('div.foo-')).to.have.lengthOf(1); | ||
expect(wrapper.find('div.-foo')).to.have.lengthOf(2); | ||
expect(wrapper.find('#bar.-foo')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('hyphens', () => { | ||
|
@@ -268,13 +269,13 @@ describe('selectors', () => { | |
<span className="-foo" /> | ||
</div>, | ||
); | ||
expect(wrapper.find('.-foo').length).to.equal(3); | ||
expect(wrapper.find('.foo-').length).to.equal(1); | ||
expect(wrapper.find('[type="foo"].foo-').length).to.equal(1); | ||
expect(wrapper.find('.foo-.-bar-').length).to.equal(1); | ||
expect(wrapper.find('div.foo-').length).to.equal(1); | ||
expect(wrapper.find('div.-foo').length).to.equal(2); | ||
expect(wrapper.find('#bar.-foo').length).to.equal(1); | ||
expect(wrapper.find('.-foo')).to.have.lengthOf(3); | ||
expect(wrapper.find('.foo-')).to.have.lengthOf(1); | ||
expect(wrapper.find('[type="foo"].foo-')).to.have.lengthOf(1); | ||
expect(wrapper.find('.foo-.-bar-')).to.have.lengthOf(1); | ||
expect(wrapper.find('div.foo-')).to.have.lengthOf(1); | ||
expect(wrapper.find('div.-foo')).to.have.lengthOf(2); | ||
expect(wrapper.find('#bar.-foo')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('spaces in attribute values', () => { | ||
|
@@ -285,7 +286,7 @@ describe('selectors', () => { | |
<div type="foobar" /> | ||
</div>, | ||
); | ||
expect(wrapper.find('[type="foo bar"]').length).to.equal(1); | ||
expect(wrapper.find('[type="foo bar"]')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('dots in attribute values', () => { | ||
|
@@ -296,7 +297,7 @@ describe('selectors', () => { | |
<div type="foobar" /> | ||
</div>, | ||
); | ||
expect(wrapper.find('[type="foo.bar"]').length).to.equal(1); | ||
expect(wrapper.find('[type="foo.bar"]')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('brackets in attribute values', () => { | ||
|
@@ -305,7 +306,7 @@ describe('selectors', () => { | |
<div type="foo[1]" /> | ||
</div>, | ||
); | ||
expect(wrapper.find('[type="foo[1]"]').length).to.equal(1); | ||
expect(wrapper.find('[type="foo[1]"]')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('URLs in attribute values', () => { | ||
|
@@ -315,8 +316,8 @@ describe('selectors', () => { | |
<a href="foo.com" /> | ||
</div>, | ||
); | ||
expect(wrapper.find('a[href="https://www.foo.com"]').length).to.equal(1); | ||
expect(wrapper.find('a[href="foo.com"]').length).to.equal(1); | ||
expect(wrapper.find('a[href="https://www.foo.com"]')).to.have.lengthOf(1); | ||
expect(wrapper.find('a[href="foo.com"]')).to.have.lengthOf(1); | ||
}); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add test cases that
-0
does not match0
, and0
does not match-0
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.