@@ -63,20 +63,14 @@ function foo(): int {
6363 }
6464}
6565" ))
66- (with-temp-buffer
67- (hack-mode)
68- (insert src)
69-
66+ (with-hack-buffer src
7067 (indent-region (point-min ) (point-max ))
7168 (should (string= (buffer-string ) src)))))
7269
7370(ert-deftest hack-indent-repeated-parens ()
7471 " Repeated parens on the same line should not increase the indent"
7572 (let ((src " foo(foo(\n \" baz\"\n ));" ))
76- (with-temp-buffer
77- (hack-mode)
78- (insert src)
79-
73+ (with-hack-buffer src
8074 (indent-region (point-min ) (point-max ))
8175 (should (string= (buffer-string ) src)))))
8276
@@ -89,10 +83,7 @@ function foo(): int {
8983 echo \"\" ;
9084 echo \"\" ;
9185}" ))
92- (with-temp-buffer
93- (hack-mode)
94- (insert src)
95-
86+ (with-hack-buffer src
9687 (indent-region (point-min ) (point-max ))
9788 (should (string= (buffer-string ) src)))))
9889
@@ -102,10 +93,7 @@ function foo(): int {
10293 1,
10394 2,
10495];" ))
105- (with-temp-buffer
106- (hack-mode)
107- (insert src)
108-
96+ (with-hack-buffer src
10997 (indent-region (point-min ) (point-max ))
11098 (should (string= (buffer-string ) src)))))
11199
@@ -116,10 +104,7 @@ function foo(): int {
116104$foo =
117105 bar();
118106" ))
119- (with-temp-buffer
120- (hack-mode)
121- (insert src)
122-
107+ (with-hack-buffer src
123108 (indent-region (point-min ) (point-max ))
124109 (should (string= (buffer-string ) src)))))
125110
@@ -130,10 +115,7 @@ $foo =
130115function f(int $n): bool {
131116 return $n <= 0;
132117}" ))
133- (with-temp-buffer
134- (hack-mode)
135- (insert src)
136-
118+ (with-hack-buffer src
137119 (indent-region (point-min ) (point-max ))
138120 (should (string= (buffer-string ) src)))))
139121
@@ -144,10 +126,7 @@ function f(int $n): bool {
144126$foo = bar()
145127 ->baz();
146128" ))
147- (with-temp-buffer
148- (hack-mode)
149- (insert src)
150-
129+ (with-hack-buffer src
151130 (indent-region (point-min ) (point-max ))
152131 (should (string= (buffer-string ) src)))))
153132
160139 baz
161140EOT;
162141" ))
163- (with-temp-buffer
164- (hack-mode)
165- (insert src)
166-
142+ (with-hack-buffer src
167143 (indent-region (point-min ) (point-max ))
168144 (should (string= (buffer-string ) src)))))
169145
@@ -179,10 +155,7 @@ class MyClass {
179155 }
180156}
181157" ))
182- (with-temp-buffer
183- (hack-mode)
184- (insert src)
185-
158+ (with-hack-buffer src
186159 (indent-region (point-min ) (point-max ))
187160 (should (string= (buffer-string ) src)))))
188161(ert-deftest hack-indent-left-shift ()
@@ -191,10 +164,7 @@ class MyClass {
191164$foo = 1 << 2;
192165bar();
193166" ))
194- (with-temp-buffer
195- (hack-mode)
196- (insert src)
197-
167+ (with-hack-buffer src
198168 (indent-region (point-min ) (point-max ))
199169 (should (string= (buffer-string ) src)))))
200170
@@ -204,10 +174,7 @@ bar();
204174$foo = bar()
205175 ?->baz;
206176" ))
207- (with-temp-buffer
208- (hack-mode)
209- (insert src)
210-
177+ (with-hack-buffer src
211178 (indent-region (point-min ) (point-max ))
212179 (should (string= (buffer-string ) src)))))
213180
@@ -217,10 +184,7 @@ $foo = bar()
217184$foo
218185 |> baz($$);
219186" ))
220- (with-temp-buffer
221- (hack-mode)
222- (insert src)
223-
187+ (with-hack-buffer src
224188 (indent-region (point-min ) (point-max ))
225189 (should (string= (buffer-string ) src)))))
226190
@@ -232,21 +196,15 @@ $foo
232196 default:
233197 bar();
234198}" ))
235- (with-temp-buffer
236- (hack-mode)
237- (insert src)
238-
199+ (with-hack-buffer src
239200 (indent-region (point-min ) (point-max ))
240201 (should (string= (buffer-string ) src)))))
241202
242203(ert-deftest hack-indent-trailing-comment ()
243204 (let ((src " function foo(): void { // stuff
244205 bar();
245206}" ))
246- (with-temp-buffer
247- (hack-mode)
248- (insert src)
249-
207+ (with-hack-buffer src
250208 (indent-region (point-min ) (point-max ))
251209 (should (string= (buffer-string ) src)))))
252210
@@ -258,10 +216,7 @@ $x = <div>
258216 <p>hello world</p>
259217</div>;
260218" ))
261- (with-temp-buffer
262- (hack-mode)
263- (insert src)
264-
219+ (with-hack-buffer src
265220 (indent-region (point-min ) (point-max ))
266221 (should (string= (buffer-string ) src)))))
267222
@@ -272,20 +227,14 @@ $x = <div>
272227function stuff(): int {
273228 $x = <p>hello</p>;
274229}" ))
275- (with-temp-buffer
276- (hack-mode)
277- (insert src)
278-
230+ (with-hack-buffer src
279231 (indent-region (point-min ) (point-max ))
280232 (should (string= (buffer-string ) src)))))
281233
282234(ert-deftest hack-indent-xhp-in-comment ()
283235 " XHP expressions in comments should not affect indentation."
284236 (let ((src " function foo(): void {\n $x = 123;\n // return <p>H'el'lo</p>;\n 1;\n }" ))
285- (with-temp-buffer
286- (hack-mode)
287- (insert src)
288-
237+ (with-hack-buffer src
289238 (indent-region (point-min ) (point-max ))
290239 (should (string= (buffer-string ) src)))))
291240
0 commit comments