-
-
Notifications
You must be signed in to change notification settings - Fork 927
/
normalizeRuleSettings.test.js
160 lines (125 loc) · 4.24 KB
/
normalizeRuleSettings.test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"use strict";
const normalizeRuleSettings = require("../normalizeRuleSettings");
describe("rules whose primary option IS NOT an array", () => {
it("solo null returns null", () => {
expect(normalizeRuleSettings(null, "foo")).toBeNull();
});
it("arrayed null returns null", () => {
expect(normalizeRuleSettings([null], "foo")).toBeNull();
});
it("solo number returns arrayed number", () => {
const actual = normalizeRuleSettings(2, "foo");
const expected = [2];
expect(actual).toEqual(expected);
});
it("arrayed number returns arrayed number if rule is not special", () => {
const actual = normalizeRuleSettings([2], "foo");
const expected = [2];
expect(actual).toEqual(expected);
});
it("arrayed number with secondary options returns same", () => {
const actual = normalizeRuleSettings(
[2, { severity: "warning" }],
"block-no-empty"
);
const expected = [2, { severity: "warning" }];
expect(actual).toEqual(expected);
});
it("solo string returns arrayed string", () => {
const actual = normalizeRuleSettings("always", "foo");
const expected = ["always"];
expect(actual).toEqual(expected);
});
it("arrayed string returns arrayed string", () => {
const actual = normalizeRuleSettings(["always"], "foo");
const expected = ["always"];
expect(actual).toEqual(expected);
});
it("arrayed string with secondary options returns same", () => {
const actual = normalizeRuleSettings(
["always", { severity: "warning" }],
"foo"
);
const expected = ["always", { severity: "warning" }];
expect(actual).toEqual(expected);
});
it("solo boolean returns arrayed boolean", () => {
const actual = normalizeRuleSettings(true, "foo");
const expected = [true];
expect(actual).toEqual(expected);
});
it("arrayed boolean returns arrayed boolean if rule is not special", () => {
const actual = normalizeRuleSettings([false], "foo");
const expected = [false];
expect(actual).toEqual(expected);
});
it("arrayed boolean with secondary options returns same", () => {
const actual = normalizeRuleSettings(
[true, { severity: "warning" }],
"block-no-empty"
);
const expected = [true, { severity: "warning" }];
expect(actual).toEqual(expected);
});
});
describe("rules whose primary option CAN BE an array", () => {
it("solo null returns null", () => {
expect(normalizeRuleSettings(null, "foo")).toBeNull();
});
it("arrayed null returns null", () => {
expect(normalizeRuleSettings([null], "foo")).toBeNull();
});
it("solo primary option array is nested within an array", () => {
const actual = normalizeRuleSettings(
["calc", "rgba"],
"function-whitelist",
true
);
const expected = [["calc", "rgba"]];
expect(actual).toEqual(expected);
});
it("primary option array in an array", () => {
const actual = normalizeRuleSettings(
[["calc", "rgba"]],
"function-whitelist",
true
);
const expected = [["calc", "rgba"]];
expect(actual).toEqual(expected);
});
it("nested primary option array returns same", () => {
const actual = normalizeRuleSettings(
[["calc", "rgba"], { severity: "warning" }],
"function-whitelist",
true
);
const expected = [["calc", "rgba"], { severity: "warning" }];
expect(actual).toEqual(expected);
});
it("string as first primary option returns same", () => {
const actual = normalizeRuleSettings(
["alphabetical", { severity: "warning" }],
"rulename-bar"
);
const expected = ["alphabetical", { severity: "warning" }];
expect(actual).toEqual(expected);
});
it("primary option array with length of 2", () => {
const actual = normalizeRuleSettings(
[{ foo: 1 }, { foo: 2 }],
"rulename-bar",
true
);
const expected = [[{ foo: 1 }, { foo: 2 }]];
expect(actual).toEqual(expected);
});
it("primary option array with length of 2 and secondary options", () => {
const actual = normalizeRuleSettings(
[[{ foo: 1 }, { foo: 2 }], { severity: "warning" }],
"rulename-bar",
true
);
const expected = [[{ foo: 1 }, { foo: 2 }], { severity: "warning" }];
expect(actual).toEqual(expected);
});
});