]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/template-tag-spacing.js
first commit
[pve-eslint.git] / eslint / tests / lib / rules / template-tag-spacing.js
1 /**
2 * @fileoverview Tests for template-tag-spacing rule.
3 * @author Jonathan Wilsson
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/template-tag-spacing"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
20 const unexpectedError = { messageId: "unexpected" };
21 const missingError = { messageId: "missing" };
22
23 ruleTester.run("template-tag-spacing", rule, {
24 valid: [
25 "tag`name`",
26 { code: "tag`name`", options: ["never"] },
27 { code: "tag `name`", options: ["always"] },
28 "tag`hello ${name}`",
29 { code: "tag`hello ${name}`", options: ["never"] },
30 { code: "tag `hello ${name}`", options: ["always"] },
31 "tag/*here's a comment*/`Hello world`",
32 { code: "tag/*here's a comment*/`Hello world`", options: ["never"] },
33 { code: "tag /*here's a comment*/`Hello world`", options: ["always"] },
34 { code: "tag/*here's a comment*/ `Hello world`", options: ["always"] },
35 "new tag`name`",
36 { code: "new tag`name`", options: ["never"] },
37 { code: "new tag `name`", options: ["always"] },
38 "new tag`hello ${name}`",
39 { code: "new tag`hello ${name}`", options: ["never"] },
40 { code: "new tag `hello ${name}`", options: ["always"] },
41 "(tag)`name`",
42 { code: "(tag)`name`", options: ["never"] },
43 { code: "(tag) `name`", options: ["always"] },
44 "(tag)`hello ${name}`",
45 { code: "(tag)`hello ${name}`", options: ["never"] },
46 { code: "(tag) `hello ${name}`", options: ["always"] },
47 "new (tag)`name`",
48 { code: "new (tag)`name`", options: ["never"] },
49 { code: "new (tag) `name`", options: ["always"] },
50 "new (tag)`hello ${name}`",
51 { code: "new (tag)`hello ${name}`", options: ["never"] },
52 { code: "new (tag) `hello ${name}`", options: ["always"] }
53 ],
54 invalid: [
55 {
56 code: "tag `name`",
57 output: "tag`name`",
58 errors: [unexpectedError]
59 },
60 {
61 code: "tag `name`",
62 output: "tag`name`",
63 options: ["never"],
64 errors: [unexpectedError]
65 },
66 {
67 code: "tag`name`",
68 output: "tag `name`",
69 options: ["always"],
70 errors: [missingError]
71 },
72 {
73 code: "tag /*here's a comment*/`Hello world`",
74 output: "tag/*here's a comment*/`Hello world`",
75 options: ["never"],
76 errors: [unexpectedError]
77 },
78 {
79 code: "tag/*here's a comment*/ `Hello world`",
80 output: "tag/*here's a comment*/`Hello world`",
81 options: ["never"],
82 errors: [unexpectedError]
83 },
84 {
85 code: "tag/*here's a comment*/`Hello world`",
86 output: "tag /*here's a comment*/`Hello world`",
87 options: ["always"],
88 errors: [missingError]
89 },
90 {
91 code: "tag // here's a comment \n`bar`",
92 output: null,
93 errors: [unexpectedError]
94 },
95 {
96 code: "tag // here's a comment \n`bar`",
97 output: null,
98 options: ["never"],
99 errors: [unexpectedError]
100 },
101 {
102 code: "tag `hello ${name}`",
103 output: "tag`hello ${name}`",
104 errors: [unexpectedError]
105 },
106 {
107 code: "tag `hello ${name}`",
108 output: "tag`hello ${name}`",
109 options: ["never"],
110 errors: [unexpectedError]
111 },
112 {
113 code: "tag`hello ${name}`",
114 output: "tag `hello ${name}`",
115 options: ["always"],
116 errors: [missingError]
117 },
118 {
119 code: "new tag `name`",
120 output: "new tag`name`",
121 errors: [unexpectedError]
122 },
123 {
124 code: "new tag `name`",
125 output: "new tag`name`",
126 options: ["never"],
127 errors: [unexpectedError]
128 },
129 {
130 code: "new tag`name`",
131 output: "new tag `name`",
132 options: ["always"],
133 errors: [missingError]
134 },
135 {
136 code: "new tag `hello ${name}`",
137 output: "new tag`hello ${name}`",
138 errors: [unexpectedError]
139 },
140 {
141 code: "new tag `hello ${name}`",
142 output: "new tag`hello ${name}`",
143 options: ["never"],
144 errors: [unexpectedError]
145 },
146 {
147 code: "new tag`hello ${name}`",
148 output: "new tag `hello ${name}`",
149 options: ["always"],
150 errors: [missingError]
151 },
152 {
153 code: "(tag) `name`",
154 output: "(tag)`name`",
155 errors: [unexpectedError]
156 },
157 {
158 code: "(tag) `name`",
159 output: "(tag)`name`",
160 options: ["never"],
161 errors: [unexpectedError]
162 },
163 {
164 code: "(tag)`name`",
165 output: "(tag) `name`",
166 options: ["always"],
167 errors: [missingError]
168 },
169 {
170 code: "(tag) `hello ${name}`",
171 output: "(tag)`hello ${name}`",
172 errors: [unexpectedError]
173 },
174 {
175 code: "(tag) `hello ${name}`",
176 output: "(tag)`hello ${name}`",
177 options: ["never"],
178 errors: [unexpectedError]
179 },
180 {
181 code: "(tag)`hello ${name}`",
182 output: "(tag) `hello ${name}`",
183 options: ["always"],
184 errors: [missingError]
185 },
186 {
187 code: "new (tag) `name`",
188 output: "new (tag)`name`",
189 errors: [unexpectedError]
190 },
191 {
192 code: "new (tag) `name`",
193 output: "new (tag)`name`",
194 options: ["never"],
195 errors: [unexpectedError]
196 },
197 {
198 code: "new (tag)`name`",
199 output: "new (tag) `name`",
200 options: ["always"],
201 errors: [missingError]
202 },
203 {
204 code: "new (tag) `hello ${name}`",
205 output: "new (tag)`hello ${name}`",
206 errors: [unexpectedError]
207 },
208 {
209 code: "new (tag) `hello ${name}`",
210 output: "new (tag)`hello ${name}`",
211 options: ["never"],
212 errors: [unexpectedError]
213 },
214 {
215 code: "new (tag)`hello ${name}`",
216 output: "new (tag) `hello ${name}`",
217 options: ["always"],
218 errors: [missingError]
219 }
220 ]
221 });