]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | /** |
2 | * @fileoverview Tests for rule fixer. | |
3 | * @author Nicholas C. Zakas | |
4 | */ | |
5 | "use strict"; | |
6 | ||
7 | //------------------------------------------------------------------------------ | |
8 | // Requirements | |
9 | //------------------------------------------------------------------------------ | |
10 | ||
11 | const assert = require("chai").assert, | |
12 | ruleFixer = require("../../../lib/linter/rule-fixer"); | |
13 | ||
14 | //------------------------------------------------------------------------------ | |
15 | // Tests | |
16 | //------------------------------------------------------------------------------ | |
17 | ||
18 | describe("RuleFixer", () => { | |
19 | ||
20 | describe("insertTextBefore", () => { | |
21 | ||
22 | it("should return an object with the correct information when called", () => { | |
23 | ||
24 | const result = ruleFixer.insertTextBefore({ range: [0, 1] }, "Hi"); | |
25 | ||
26 | assert.deepStrictEqual(result, { | |
27 | range: [0, 0], | |
28 | text: "Hi" | |
29 | }); | |
30 | ||
31 | }); | |
32 | ||
609c276f TL |
33 | it("should allow inserting empty text", () => { |
34 | ||
35 | const result = ruleFixer.insertTextBefore({ range: [10, 20] }, ""); | |
36 | ||
37 | assert.deepStrictEqual(result, { | |
38 | range: [10, 10], | |
39 | text: "" | |
40 | }); | |
41 | ||
42 | }); | |
43 | ||
eb39fafa DC |
44 | }); |
45 | ||
46 | describe("insertTextBeforeRange", () => { | |
47 | ||
48 | it("should return an object with the correct information when called", () => { | |
49 | ||
50 | const result = ruleFixer.insertTextBeforeRange([0, 1], "Hi"); | |
51 | ||
52 | assert.deepStrictEqual(result, { | |
53 | range: [0, 0], | |
54 | text: "Hi" | |
55 | }); | |
56 | ||
57 | }); | |
58 | ||
609c276f TL |
59 | it("should allow inserting empty text", () => { |
60 | ||
61 | const result = ruleFixer.insertTextBeforeRange([10, 20], ""); | |
62 | ||
63 | assert.deepStrictEqual(result, { | |
64 | range: [10, 10], | |
65 | text: "" | |
66 | }); | |
67 | ||
68 | }); | |
69 | ||
eb39fafa DC |
70 | }); |
71 | ||
72 | describe("insertTextAfter", () => { | |
73 | ||
74 | it("should return an object with the correct information when called", () => { | |
75 | ||
76 | const result = ruleFixer.insertTextAfter({ range: [0, 1] }, "Hi"); | |
77 | ||
78 | assert.deepStrictEqual(result, { | |
79 | range: [1, 1], | |
80 | text: "Hi" | |
81 | }); | |
82 | ||
83 | }); | |
84 | ||
609c276f TL |
85 | it("should allow inserting empty text", () => { |
86 | ||
87 | const result = ruleFixer.insertTextAfter({ range: [10, 20] }, ""); | |
88 | ||
89 | assert.deepStrictEqual(result, { | |
90 | range: [20, 20], | |
91 | text: "" | |
92 | }); | |
93 | ||
94 | }); | |
95 | ||
eb39fafa DC |
96 | }); |
97 | ||
98 | describe("insertTextAfterRange", () => { | |
99 | ||
100 | it("should return an object with the correct information when called", () => { | |
101 | ||
102 | const result = ruleFixer.insertTextAfterRange([0, 1], "Hi"); | |
103 | ||
104 | assert.deepStrictEqual(result, { | |
105 | range: [1, 1], | |
106 | text: "Hi" | |
107 | }); | |
108 | ||
109 | }); | |
110 | ||
609c276f TL |
111 | it("should allow inserting empty text", () => { |
112 | ||
113 | const result = ruleFixer.insertTextAfterRange([10, 20], ""); | |
114 | ||
115 | assert.deepStrictEqual(result, { | |
116 | range: [20, 20], | |
117 | text: "" | |
118 | }); | |
119 | ||
120 | }); | |
121 | ||
eb39fafa DC |
122 | }); |
123 | ||
124 | describe("removeAfter", () => { | |
125 | ||
126 | it("should return an object with the correct information when called", () => { | |
127 | ||
128 | const result = ruleFixer.remove({ range: [0, 1] }); | |
129 | ||
130 | assert.deepStrictEqual(result, { | |
131 | range: [0, 1], | |
132 | text: "" | |
133 | }); | |
134 | ||
135 | }); | |
136 | ||
137 | }); | |
138 | ||
139 | describe("removeAfterRange", () => { | |
140 | ||
141 | it("should return an object with the correct information when called", () => { | |
142 | ||
143 | const result = ruleFixer.removeRange([0, 1]); | |
144 | ||
145 | assert.deepStrictEqual(result, { | |
146 | range: [0, 1], | |
147 | text: "" | |
148 | }); | |
149 | ||
150 | }); | |
151 | ||
152 | }); | |
153 | ||
154 | ||
155 | describe("replaceText", () => { | |
156 | ||
157 | it("should return an object with the correct information when called", () => { | |
158 | ||
159 | const result = ruleFixer.replaceText({ range: [0, 1] }, "Hi"); | |
160 | ||
161 | assert.deepStrictEqual(result, { | |
162 | range: [0, 1], | |
163 | text: "Hi" | |
164 | }); | |
165 | ||
166 | }); | |
167 | ||
168 | }); | |
169 | ||
170 | describe("replaceTextRange", () => { | |
171 | ||
172 | it("should return an object with the correct information when called", () => { | |
173 | ||
174 | const result = ruleFixer.replaceTextRange([0, 1], "Hi"); | |
175 | ||
176 | assert.deepStrictEqual(result, { | |
177 | range: [0, 1], | |
178 | text: "Hi" | |
179 | }); | |
180 | ||
181 | }); | |
182 | ||
183 | }); | |
184 | ||
185 | }); |