]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/linter/config-comment-parser.js
first commit
[pve-eslint.git] / eslint / tests / lib / linter / config-comment-parser.js
1 /**
2 * @fileoverview Tests for ConfigCommentParser object.
3 * @author Nicholas C. Zakas
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const assert = require("chai").assert,
13 ConfigCommentParser = require("../../../lib/linter/config-comment-parser");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 describe("ConfigCommentParser", () => {
20
21 let commentParser;
22 const location = {
23 start: {
24 line: 1,
25 column: 0
26 }
27 };
28
29 beforeEach(() => {
30 commentParser = new ConfigCommentParser();
31 });
32
33 describe("parseJsonConfig", () => {
34
35 it("should parse JSON config with one item", () => {
36 const code = "no-alert:0";
37 const result = commentParser.parseJsonConfig(code, location);
38
39
40 assert.deepStrictEqual(result, {
41 success: true,
42 config: {
43 "no-alert": 0
44 }
45 });
46 });
47
48 it("should parse JSON config with two items", () => {
49 const code = "no-alert:0 semi: 2";
50 const result = commentParser.parseJsonConfig(code, location);
51
52
53 assert.deepStrictEqual(result, {
54 success: true,
55 config: {
56 "no-alert": 0,
57 semi: 2
58 }
59 });
60 });
61
62 it("should parse JSON config with two comma-separated items", () => {
63 const code = "no-alert:0,semi: 2";
64 const result = commentParser.parseJsonConfig(code, location);
65
66
67 assert.deepStrictEqual(result, {
68 success: true,
69 config: {
70 "no-alert": 0,
71 semi: 2
72 }
73 });
74 });
75
76 it("should parse JSON config with two items and a string severity", () => {
77 const code = "no-alert:off,semi: 2";
78 const result = commentParser.parseJsonConfig(code, location);
79
80
81 assert.deepStrictEqual(result, {
82 success: true,
83 config: {
84 "no-alert": "off",
85 semi: 2
86 }
87 });
88 });
89
90 it("should parse JSON config with two items and options", () => {
91 const code = "no-alert:off, semi: [2, always]";
92 const result = commentParser.parseJsonConfig(code, location);
93
94
95 assert.deepStrictEqual(result, {
96 success: true,
97 config: {
98 "no-alert": "off",
99 semi: [2, "always"]
100 }
101 });
102 });
103
104 it("should parse JSON config with two items and options from plugins", () => {
105 const code = "plugin/no-alert:off, plugin/semi: [2, always]";
106 const result = commentParser.parseJsonConfig(code, location);
107
108 assert.deepStrictEqual(result, {
109 success: true,
110 config: {
111 "plugin/no-alert": "off",
112 "plugin/semi": [2, "always"]
113 }
114 });
115 });
116
117
118 });
119
120 describe("parseStringConfig", () => {
121
122 const comment = {};
123
124 it("should parse String config with one item", () => {
125 const code = "a: true";
126 const result = commentParser.parseStringConfig(code, comment);
127
128 assert.deepStrictEqual(result, {
129 a: {
130 value: "true",
131 comment
132 }
133 });
134 });
135
136 it("should parse String config with one item and no value", () => {
137 const code = "a";
138 const result = commentParser.parseStringConfig(code, comment);
139
140 assert.deepStrictEqual(result, {
141 a: {
142 value: null,
143 comment
144 }
145 });
146 });
147
148 it("should parse String config with two items", () => {
149 const code = "a: five b:three";
150 const result = commentParser.parseStringConfig(code, comment);
151
152 assert.deepStrictEqual(result, {
153 a: {
154 value: "five",
155 comment
156 },
157 b: {
158 value: "three",
159 comment
160 }
161 });
162 });
163
164 it("should parse String config with two comma-separated items", () => {
165 const code = "a: seventy, b:ELEVENTEEN";
166 const result = commentParser.parseStringConfig(code, comment);
167
168 assert.deepStrictEqual(result, {
169 a: {
170 value: "seventy",
171 comment
172 },
173 b: {
174 value: "ELEVENTEEN",
175 comment
176 }
177 });
178 });
179
180 it("should parse String config with two comma-separated items and no values", () => {
181 const code = "a , b";
182 const result = commentParser.parseStringConfig(code, comment);
183
184 assert.deepStrictEqual(result, {
185 a: {
186 value: null,
187 comment
188 },
189 b: {
190 value: null,
191 comment
192 }
193 });
194 });
195 });
196
197 describe("parseListConfig", () => {
198
199 it("should parse list config with one item", () => {
200 const code = "a";
201 const result = commentParser.parseListConfig(code);
202
203 assert.deepStrictEqual(result, {
204 a: true
205 });
206 });
207
208 it("should parse list config with two items", () => {
209 const code = "a, b";
210 const result = commentParser.parseListConfig(code);
211
212 assert.deepStrictEqual(result, {
213 a: true,
214 b: true
215 });
216 });
217
218 it("should parse list config with two items and exta whitespace", () => {
219 const code = " a , b ";
220 const result = commentParser.parseListConfig(code);
221
222 assert.deepStrictEqual(result, {
223 a: true,
224 b: true
225 });
226 });
227 });
228
229 });