forked from estools/esquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueryHas.js
More file actions
37 lines (29 loc) · 1.21 KB
/
queryHas.js
File metadata and controls
37 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
define([
"esquery",
"jstestr/assert",
"jstestr/test",
"./fixtures/conditional"
], function (esquery, assert, test, conditional) {
test.defineSuite("Parent selector query", {
"conditional": function () {
var matches = esquery(conditional, 'ExpressionStatement:has([name="foo"][type="Identifier"])');
assert.isEqual(1, matches.length);
},
"one of": function () {
var matches = esquery(conditional, 'IfStatement:has(LogicalExpression [name="foo"], LogicalExpression [name="x"])');
assert.isEqual(1, matches.length);
},
"chaining": function () {
var matches = esquery(conditional, 'BinaryExpression:has(Identifier[name="x"]):has(Literal[value="test"])');
assert.isEqual(1, matches.length);
},
"nesting": function () {
var matches = esquery(conditional, 'Program:has(IfStatement:has(Literal[value=true], Literal[value=false]))');
assert.isEqual(1, matches.length);
},
"non-matching": function () {
var matches = esquery(conditional, ':has([value="impossible"])');
assert.isEqual(0, matches.length);
}
});
});