]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/linter/config-comment-parser.js
2 * @fileoverview Tests for ConfigCommentParser object.
3 * @author Nicholas C. Zakas
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const assert
= require("chai").assert
,
13 ConfigCommentParser
= require("../../../lib/linter/config-comment-parser");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 describe("ConfigCommentParser", () => {
30 commentParser
= new ConfigCommentParser();
33 describe("parseJsonConfig", () => {
35 it("should parse JSON config with one item", () => {
36 const code
= "no-alert:0";
37 const result
= commentParser
.parseJsonConfig(code
, location
);
40 assert
.deepStrictEqual(result
, {
48 it("should parse JSON config with two items", () => {
49 const code
= "no-alert:0 semi: 2";
50 const result
= commentParser
.parseJsonConfig(code
, location
);
53 assert
.deepStrictEqual(result
, {
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
);
67 assert
.deepStrictEqual(result
, {
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
);
81 assert
.deepStrictEqual(result
, {
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
);
95 assert
.deepStrictEqual(result
, {
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
);
108 assert
.deepStrictEqual(result
, {
111 "plugin/no-alert": "off",
112 "plugin/semi": [2, "always"]
120 describe("parseStringConfig", () => {
124 it("should parse String config with one item", () => {
125 const code
= "a: true";
126 const result
= commentParser
.parseStringConfig(code
, comment
);
128 assert
.deepStrictEqual(result
, {
136 it("should parse String config with one item and no value", () => {
138 const result
= commentParser
.parseStringConfig(code
, comment
);
140 assert
.deepStrictEqual(result
, {
148 it("should parse String config with two items", () => {
149 const code
= "a: five b:three";
150 const result
= commentParser
.parseStringConfig(code
, comment
);
152 assert
.deepStrictEqual(result
, {
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
);
168 assert
.deepStrictEqual(result
, {
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
);
184 assert
.deepStrictEqual(result
, {
197 describe("parseListConfig", () => {
199 it("should parse list config with one item", () => {
201 const result
= commentParser
.parseListConfig(code
);
203 assert
.deepStrictEqual(result
, {
208 it("should parse list config with two items", () => {
210 const result
= commentParser
.parseListConfig(code
);
212 assert
.deepStrictEqual(result
, {
218 it("should parse list config with two items and exta whitespace", () => {
219 const code
= " a , b ";
220 const result
= commentParser
.parseListConfig(code
);
222 assert
.deepStrictEqual(result
, {