Skip to content

Commit 6ecd3b5

Browse files
authored
Merge pull request #137 from clojure-emacs/improve-indentation-test-coverage
Improve indentation test coverage
2 parents 9e7c54a + 6c6bf27 commit 6ecd3b5

1 file changed

Lines changed: 287 additions & 0 deletions

File tree

test/clojure-ts-mode-indentation-test.el

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,293 @@ DESCRIPTION is a string with the description of the spec."
297297
[this]
298298
(is properly indented)))")
299299

300+
;; Additional per-form tests for commonly used forms
301+
302+
(when-indenting-it "should support block-0 forms"
303+
"
304+
(comment
305+
(+ 1 2)
306+
(println \"hello\"))"
307+
308+
"
309+
(cond
310+
(even? x) \"even\"
311+
(odd? x) \"odd\")"
312+
313+
"
314+
(delay
315+
(expensive-computation))"
316+
317+
"
318+
(go
319+
(<! ch)
320+
(>! ch val))"
321+
322+
"
323+
(thread
324+
(do-something)
325+
(do-more))"
326+
327+
"
328+
(finally
329+
(cleanup))"
330+
331+
"
332+
(with-out-str
333+
(println \"hello\"))"
334+
335+
"
336+
(alt!
337+
ch1 ([v] (handle v))
338+
ch2 ([v] (other v)))"
339+
340+
"
341+
(alt!!
342+
ch1 ([v] (handle v))
343+
ch2 ([v] (other v)))")
344+
345+
(when-indenting-it "should support block-1 forms"
346+
"
347+
(let [a 1
348+
b 2]
349+
(+ a b))"
350+
351+
"
352+
(if (pos? x)
353+
(inc x)
354+
(dec x))"
355+
356+
"
357+
(when (pos? x)
358+
(println x)
359+
(inc x))"
360+
361+
"
362+
(when-not (nil? x)
363+
(println x))"
364+
365+
"
366+
(if-let [x (foo)]
367+
(bar x)
368+
(baz))"
369+
370+
"
371+
(when-let [x (foo)]
372+
(bar x))"
373+
374+
"
375+
(if-some [x (foo)]
376+
(bar x)
377+
nil)"
378+
379+
"
380+
(when-some [x (foo)]
381+
(bar x))"
382+
383+
"
384+
(when-first [x coll]
385+
(println x))"
386+
387+
"
388+
(binding [*out* writer]
389+
(println \"hello\"))"
390+
391+
"
392+
(loop [i 0]
393+
(when (< i 10)
394+
(recur (inc i))))"
395+
396+
"
397+
(for [x (range 10)
398+
y (range 10)]
399+
(* x y))"
400+
401+
"
402+
(doseq [x (range 10)]
403+
(println x))"
404+
405+
"
406+
(dotimes [i 10]
407+
(println i))"
408+
409+
"
410+
(doto (java.util.HashMap.)
411+
(.put \"a\" 1)
412+
(.put \"b\" 2))"
413+
414+
"
415+
(while (.hasNext iter)
416+
(.next iter))"
417+
418+
"
419+
(with-open [r (io/reader f)]
420+
(slurp r))"
421+
422+
"
423+
(with-redefs [foo bar]
424+
(test-something))"
425+
426+
"
427+
(locking lock
428+
(swap! state inc))"
429+
430+
"
431+
(ns my.namespace
432+
(:require
433+
[clojure.string :as str]))"
434+
435+
"
436+
(if-not (empty? coll)
437+
(first coll)
438+
nil)"
439+
440+
"
441+
(cond->> x
442+
(pos? x) inc
443+
(even? x) (* 2))"
444+
445+
"
446+
(go-loop [i 0]
447+
(when (< i 10)
448+
(recur (inc i))))"
449+
450+
"
451+
(with-local-vars [x 1]
452+
(var-set x 2))"
453+
454+
"
455+
(match x
456+
[1 2] \"pair\"
457+
:else \"other\")")
458+
459+
(when-indenting-it "should support block-2 forms"
460+
"
461+
(condp = x
462+
1 \"one\"
463+
2 \"two\"
464+
\"other\")"
465+
466+
"
467+
(catch Exception e
468+
(handle-error e))"
469+
470+
"
471+
(proxy [ActionListener] []
472+
(actionPerformed [e]
473+
(println e)))"
474+
475+
"
476+
(deftype MyType [field]
477+
SomeProtocol
478+
(some-method [this]
479+
field))")
480+
481+
(when-indenting-it "should support inner-0 forms"
482+
"
483+
(defn foo
484+
[x]
485+
(+ x 1))"
486+
487+
"
488+
(defn- private-fn
489+
[x]
490+
(* x 2))"
491+
492+
"
493+
(def my-var
494+
42)"
495+
496+
"
497+
(defonce state
498+
(atom {}))"
499+
500+
"
501+
(defmacro my-macro
502+
[& body]
503+
`(do ~@body))"
504+
505+
"
506+
(defmulti area
507+
:shape)"
508+
509+
"
510+
(deftest my-test
511+
(is (= 1 1)))"
512+
513+
"
514+
(use-fixtures :once
515+
my-fixture)"
516+
517+
"
518+
(fdef ::my-fn
519+
:args (s/cat :x int?)
520+
:ret int?)")
521+
522+
(when-indenting-it "should support inner-1 forms (method nesting)"
523+
"
524+
(defprotocol MyProto
525+
(method-a [this])
526+
(method-b [this x]
527+
\"docstring\"))"
528+
529+
"
530+
(definterface MyInterface
531+
(^void doSomething [])
532+
(^String getName []))"
533+
534+
"
535+
(extend-type String
536+
MyProto
537+
(method-a [this]
538+
(str this)))"
539+
540+
"
541+
(extend-protocol MyProto
542+
String
543+
(method-a [this]
544+
(str this)))"
545+
546+
"
547+
(defrecord MyRecord [a b]
548+
MyProto
549+
(method-a [this]
550+
(:a this)))"
551+
552+
"
553+
(deftype MyImpl [state]
554+
MyProto
555+
(method-a [this]
556+
@state))"
557+
558+
"
559+
(reify MyProto
560+
(method-a [this]
561+
42))"
562+
563+
"
564+
(proxy [Thread] []
565+
(run []
566+
(println \"running\")))")
567+
568+
(when-indenting-it "should support inner-2 forms (letfn)"
569+
"
570+
(letfn [(add [x y]
571+
(+ x y))
572+
(mul [x y]
573+
(* x y))]
574+
(add (mul 2 3) 4))")
575+
576+
(when-indenting-it "should support threading macros"
577+
"
578+
(-> x
579+
(assoc :foo 1)
580+
(update :bar inc))"
581+
582+
"
583+
(->> (range 10)
584+
(filter even?)
585+
(map inc))")
586+
300587
(it "should prioritize custom semantic indentation rules"
301588
(with-clojure-ts-buffer "
302589
(are [x y]

0 commit comments

Comments
 (0)