Skip to content

Commit

Permalink
Chore: improve test coverage for node-event-generator (#8287)
Browse files Browse the repository at this point in the history
Previonsly, there were insufficient tests for alphabetical selector sorting in the case where selectors had equal specificity. There were also no tests for emitting a selector whose type could not be inferred while exiting the AST.
  • Loading branch information
not-an-aardvark committed Mar 18, 2017
1 parent 602e9c2 commit f8176b3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/lib/util/node-event-generator.js
Expand Up @@ -260,6 +260,7 @@ describe("NodeEventGenerator", () => {
"FooStatement",
"[name = 'foo']",
"[name='foo']",
"[name ='foo']",
"Identifier[name='foo']",
"[name='foo'][name.length=3]",
":not(Program, ExpressionStatement)",
Expand All @@ -277,13 +278,32 @@ describe("NodeEventGenerator", () => {
["ExpressionStatement > Identifier", ast.body[0].expression], // 0 pseudoclasses, 2 identifiers
["Identifier, ReturnStatement", ast.body[0].expression], // 0 pseudoclasses, 2 identifiers
["[name = 'foo']", ast.body[0].expression], // 1 pseudoclass, 0 identifiers
["[name ='foo']", ast.body[0].expression], // 1 pseudoclass, 0 identifiers
["[name='foo']", ast.body[0].expression], // 1 pseudoclass, 0 identifiers
["ExpressionStatement > [name='foo']", ast.body[0].expression], // 1 attribute, 1 identifier
["Identifier[name='foo']", ast.body[0].expression], // 1 attribute, 1 identifier
[":not(Program, Identifier) > [name.length=3]", ast.body[0].expression], // 1 attribute, 2 identifiers
["[name='foo'][name.length=3]", ast.body[0].expression] // 2 attributes, 0 identifiers
]
);

assertEmissions(
"foo(); bar; baz;",
["CallExpression, [name='bar']"],
ast => [
["CallExpression, [name='bar']", ast.body[0].expression],
["CallExpression, [name='bar']", ast.body[1].expression]
]
);

assertEmissions(
"foo; bar;",
["[name.length=3]:exit"],
ast => [
["[name.length=3]:exit", ast.body[0].expression],
["[name.length=3]:exit", ast.body[1].expression]
]
);
});

describe("parsing an invalid selector", () => {
Expand Down

0 comments on commit f8176b3

Please sign in to comment.