forked from eslint/eslint-visitor-keys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (56 loc) · 2.53 KB
/
index.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
import assert from "assert";
import fs from "fs";
import evk from "../../lib/index.js";
const keys = JSON.parse(fs.readFileSync("lib/visitor-keys.json", "utf8"));
describe("eslint-visitor-keys", () => {
describe("KEYS", () => {
it("should be same as lib/visitor-keys.json", () => {
assert.deepStrictEqual(evk.KEYS, keys);
});
});
describe("getKeys()", () => {
it("should return keys", () => {
assert.deepStrictEqual(evk.getKeys({ a: 1, b: 2 }), ["a", "b"]);
});
it("should not include 'parent' in the result", () => {
assert.deepStrictEqual(evk.getKeys({ a: 1, b: 2, parent: 3 }), ["a", "b"]);
});
it("should not include 'leadingComments' in the result", () => {
assert.deepStrictEqual(evk.getKeys({ a: 1, b: 2, leadingComments: 3 }), ["a", "b"]);
});
it("should not include 'trailingComments' in the result", () => {
assert.deepStrictEqual(evk.getKeys({ a: 1, b: 2, trailingComments: 3 }), ["a", "b"]);
});
it("should not include '_foo' in the result", () => {
assert.deepStrictEqual(evk.getKeys({ a: 1, b: 2, _foo: 3 }), ["a", "b"]);
});
});
describe("unionWith()", () => {
const additionalKeys = { Program: ["body", "a"], AssignmentExpression: ["b"], additional: ["c"], MethodDefinition: ["a", "key", "b"] };
const unionKeys = evk.unionWith(additionalKeys);
it("should include all keys of lib/visitor-keys.json", () => {
for (const type of Object.keys(keys)) {
for (const key of keys[type]) {
assert(unionKeys[type].indexOf(key) !== -1, `'${key}' should be included in '${type}'.`);
}
}
});
it("should include all additional keys", () => {
for (const type of Object.keys(additionalKeys)) {
for (const key of additionalKeys[type]) {
assert(unionKeys[type].indexOf(key) !== -1, `'${key}' should be included in '${type}'.`);
}
}
});
it("should not have duplicate", () => {
assert(unionKeys.Program.filter(key => key === "body").length === 1);
});
it("should add additional keys, then concatenate original keys", () => {
assert.deepStrictEqual(unionKeys.MethodDefinition, ["a", "key", "b", "value"]);
});
});
});