File tree 2 files changed +52
-9
lines changed
2 files changed +52
-9
lines changed Original file line number Diff line number Diff line change 33
33
(defn- transform [form zf & args]
34
34
(z/root (apply zf (z/of-node form) args)))
35
35
36
- (defn- surrounding? [zloc p?]
37
- (and (p? zloc) (or (nil? (z/left* zloc))
38
- (nil? (z/skip z/right* p? zloc)))))
39
-
40
36
(defn root? [zloc]
41
37
(nil? (z/up* zloc)))
42
38
49
45
(defn- clojure-whitespace? [zloc]
50
46
(z/whitespace? zloc))
51
47
48
+ (defn- unquote? [zloc]
49
+ (and zloc (= (n/tag (z/node zloc)) :unquote )))
50
+
51
+ (defn- deref? [zloc]
52
+ (and zloc (= (n/tag (z/node zloc)) :deref )))
53
+
54
+ (defn- unquote-deref? [zloc]
55
+ (and (deref? zloc)
56
+ (unquote? (z/up* zloc))))
57
+
52
58
(defn- surrounding-whitespace? [zloc]
53
59
(and (not (top? zloc))
54
- (surrounding? zloc clojure-whitespace?)))
60
+ (clojure-whitespace? zloc)
61
+ (or (and (nil? (z/left* zloc))
62
+ ; ; don't convert ~ @ to ~@
63
+ (not (unquote-deref? (z/right* zloc))))
64
+ (nil? (z/skip z/right* clojure-whitespace? zloc)))))
55
65
56
66
(defn remove-surrounding-whitespace [form]
57
67
(transform form edit-all surrounding-whitespace? z/remove*))
Original file line number Diff line number Diff line change 692
692
[" #:clj {:a :b"
693
693
" :c :d}" ]
694
694
[" #:clj {:a :b"
695
- " :c :d}" ]))))
695
+ " :c :d}" ])))
696
+ (testing " ~ @ is not ~@"
697
+ (is (reformats-to?
698
+ [" ~ @foo" ]
699
+ [" ~ @foo" ]))
700
+ (is (reformats-to?
701
+ [" ~(deref foo)" ]
702
+ [" ~(deref foo)" ]))
703
+ (is (reformats-to?
704
+ [" ~(clojure.core/deref foo)" ]
705
+ [" ~(clojure.core/deref foo)" ]))
706
+ (is (reformats-to?
707
+ [" ~ @foo" ]
708
+ [" ~ @foo" ]))
709
+ (is (reformats-to?
710
+ [" ~ @foo" ]
711
+ [" ~ @foo" ]))
712
+ (is (reformats-to?
713
+ [" ~\n @foo" ]
714
+ [" ~"
715
+ " @foo" ]))
716
+ (is (reformats-to?
717
+ [" ~;;comment\n @foo" ]
718
+ [" ~;;comment"
719
+ " @foo" ]))
720
+ (is (reformats-to?
721
+ [" ~#_a@foo" ]
722
+ [" ~#_a @foo" ]))))
696
723
697
724
(deftest test-remove-multiple-non-indenting-spaces
698
725
(let [opts {:remove-multiple-non-indenting-spaces? true }]
1568
1595
" (~@foo"
1569
1596
" bar)"
1570
1597
" (#:foo{:bar 1}"
1571
- " baz)" ]]
1598
+ " baz)"
1599
+ " (~ @foo"
1600
+ " bar)" ]]
1572
1601
(testing " :cursive style uses 2 spaces unless starting with a collection"
1573
1602
(is (reformats-to?
1574
1603
input
1627
1656
" (~@foo"
1628
1657
" bar)"
1629
1658
" (#:foo{:bar 1}"
1630
- " baz)" ]
1659
+ " baz)"
1660
+ " (~ @foo"
1661
+ " bar)" ]
1631
1662
{:function-arguments-indentation :cursive })))
1632
1663
(testing " :zprint uses 2 spaces if starting with a symbol, keyword, or list"
1633
1664
(is (reformats-to?
1687
1718
" (~@foo"
1688
1719
" bar)"
1689
1720
" (#:foo{:bar 1}"
1690
- " baz)" ]
1721
+ " baz)"
1722
+ " (~ @foo"
1723
+ " bar)" ]
1691
1724
{:function-arguments-indentation :zprint })))))
You can’t perform that action at this time.
0 commit comments