File tree Expand file tree Collapse file tree 2 files changed +33
-13
lines changed Expand file tree Collapse file tree 2 files changed +33
-13
lines changed Original file line number Diff line number Diff line change 686
686
zloc)))
687
687
688
688
(defn split
689
- " Split current s-sexpression in two at given node `zloc`
690
-
691
- - `[1 2 |3 4 5] => [1 2 3] [4 5]`"
689
+ " Return `zloc` with parent sequence split into to two sequences at current node.
690
+ Location is retained. If split would result in empty seq, returns `zloc` unchanged.
691
+
692
+ - `[1 2 |3 4 5] => [1 2 |3] [4 5]`
693
+ - `{|:a 1 :b 2} => {|:a} {:1 :b 2}`
694
+ - `#{:a |:b :c} => #{:a |:b} #{:c}`
695
+ - `(foo |bar baz boo) => (foo |:bar) (baz boop)`
696
+ - `[1 2 3 4 |5] => [1 2 3 4 |5]` unchanged"
692
697
[zloc]
693
698
(let [parent-loc (z/up zloc)]
694
699
(if-not parent-loc
695
700
zloc
696
701
(let [t (z/tag parent-loc)
697
- lefts (reverse (remove-first-if-ws (rest (nodes-by-dir (z/right zloc) z/left*))))
698
- rights (remove-first-if-ws (nodes-by-dir (z/right zloc) z/right*))]
699
-
702
+ lefts (-> zloc
703
+ z/right
704
+ (nodes-by-dir z/left*)
705
+ rest
706
+ remove-first-if-ws
707
+ reverse)
708
+ rights (-> zloc
709
+ z/right
710
+ (nodes-by-dir z/right*)
711
+ remove-first-if-ws)]
700
712
(if-not (and (seq lefts) (seq rights))
701
713
zloc
702
714
(-> parent-loc
703
715
(z/insert-left (create-seq-node t lefts))
704
716
(z/insert-left (create-seq-node t rights))
705
- z/remove
706
- (#(or (global-find-by-node % (z/node zloc))
707
- (global-find-by-node % (last lefts))))))))))
717
+ rz/remove-and-move-left
718
+ z/left
719
+ z/down
720
+ z/rightmost))))))
708
721
709
722
(defn- split-string [zloc pos]
710
723
(let [bounds (-> zloc z/node meta)
Original file line number Diff line number Diff line change 413
413
(testing (zipper-opts-desc opts)
414
414
(doseq [[s expected]
415
415
[[" [⊚1 2]" " [⊚1] [2]" ]
416
+ [" [1 2 ⊚3 4 5]" " [1 2 ⊚3] [4 5]" ]
416
417
[" [1 ⊚2 3 4]" " [1 ⊚2] [3 4]" ]
417
418
[" [1 2⊚ 3 4]" " [1 ⊚2] [3 4]" ]
418
- [" [⊚1]" " [⊚1]" ] ; ; no-op
419
+ [" [⊚1 2 3 4 5]" " [⊚1] [2 3 4 5]" ]
420
+ [" [⊚1]" " [⊚1]" ] ; ; no-op
421
+ [" [1 2 3 4 ⊚5]" " [1 2 3 4 ⊚5]" ] ; ; no-op
422
+ [" {⊚:a 1 :b 2}" " {⊚:a} {1 :b 2}" ]
423
+ [" (foo ⊚bar baz boop)" " (foo ⊚bar) (baz boop)" ]
424
+ [" #{:a ⊚:b :c}" " #{:a ⊚:b} #{:c}" ]
419
425
[" [⊚1 ;dill\n ]" " [⊚1 ;dill\n ]" ] ; ; no-op
420
426
[" \n [1 ;dill\n ⊚2 ;dall\n 3 ;jalla\n ]" " \n [1 ;dill\n ⊚2 ;dall\n ] [3 ;jalla\n ]" ]]]
421
- (let [zloc (th/of-locmarked-string s opts)]
422
- (is (= s (th/root-locmarked-string zloc)) " (sanity) string before" )
423
- (is (= expected (-> zloc pe/split th/root-locmarked-string)) " string after" ))))))
427
+ (testing s
428
+ (let [zloc (th/of-locmarked-string s opts)]
429
+ (is (= s (th/root-locmarked-string zloc)) " (sanity) string before" )
430
+ (is (= expected (-> zloc pe/split th/root-locmarked-string)) " string after" )))))))
424
431
425
432
(deftest split-at-pos-test
426
433
; ; for this pos fn test, ⊚ in `s` represents character row/col the the `pos`
You can’t perform that action at this time.
0 commit comments