Back

seq-zip (clj)

(source)

function

(seq-zip root)
Returns a zipper for nested sequences, given a root sequence

Examples

clojure

(ns clojure.test-clojure.clojure-zip
  (:use clojure.test)
  (:require [clojure.zip :as zip]))


; zipper
;
; seq-zip
; vector-zip
; xml-zip
;
; node
; branch?
; children
; make-node
; path
; lefts
; rights
; down
; up
; root
; right
; rightmost
; left
; leftmost
;
; insert-left
; insert-right
; replace
; edit
; insert-child
; append-child
; next
; prev
; end?
; remove
clojure/clojure

(ns clojure.test-clojure.clojure-zip
  (:use clojure.test)
  (:require [clojure.zip :as zip]))


; zipper
;
; seq-zip
; vector-zip
; xml-zip
;
; node
; branch?
; children
; make-node
; path
; lefts
; rights
; down
; up
; root
; right
; rightmost
; left
; leftmost
;
; insert-left
; insert-right
; replace
; edit
; insert-child
; append-child
; next
; prev
; end?
; remove
babashka/babashka
(ns babashka.impl.clojure.zip
  {:no-doc true}
  (:require [clojure.zip :as zip]
            [sci.core :as sci :refer [copy-var]]))

(def zip-namespace
  {'zipper       (copy-var zip/zipper zip-ns)
   'seq-zip      (copy-var zip/seq-zip zip-ns)
   'vector-zip   (copy-var zip/vector-zip zip-ns)
   'xml-zip      (copy-var zip/xml-zip zip-ns)
   'node         (copy-var zip/node zip-ns)
   'branch?      (copy-var zip/branch? zip-ns)
   'children     (copy-var zip/children zip-ns)
   'make-node    (copy-var zip/make-node zip-ns)
   'path         (copy-var zip/path zip-ns)
   'lefts        (copy-var zip/lefts zip-ns)
   'rights       (copy-var zip/rights zip-ns)
   'down         (copy-var zip/down zip-ns)
   'up           (copy-var zip/up zip-ns)
   'root         (copy-var zip/root zip-ns)
   'right        (copy-var zip/right zip-ns)
   'rightmost    (copy-var zip/rightmost zip-ns)
   'left         (copy-var zip/left zip-ns)
   'leftmost     (copy-var zip/leftmost zip-ns)
   'insert-left  (copy-var zip/insert-left zip-ns)
   'insert-right (copy-var zip/insert-right zip-ns)
   'replace      (copy-var zip/replace zip-ns)
   'edit         (copy-var zip/edit zip-ns)
   'insert-child (copy-var zip/insert-child zip-ns)
   'append-child (copy-var zip/append-child zip-ns)
   'next         (copy-var zip/next zip-ns)
   'prev         (copy-var zip/prev zip-ns)
   'end?         (copy-var zip/end? zip-ns)
   'remove       (copy-var zip/remove zip-ns)})
marick/Midje
(ns midje.parsing.1-to-explicit-form.t-prerequisites
  (:require [midje.parsing.1-to-explicit-form.prerequisites :as prereqs :refer :all]
            [midje.sweet :refer :all]
            [midje.test-util :refer :all]
            [midje.parsing.2-to-lexical-maps.fakes :refer [fake]]
            [midje.parsing.2-to-lexical-maps.data-fakes :refer [data-fake]]
            [clojure.zip :as zip]
            [midje.parsing.util.recognizing :as recognize]))

(fact "can convert prerequisites into fake calls"
  (let [original `( provided       (f 1) => 3  (f 2) => (+ 1 1))
        translated `(        (fake (f 1) => 3) (fake (f 2) => (+ 1 1)))
        z (zip/seq-zip original)
        loc (zip/down z)]
    (#'prereqs/expand-prerequisites-into-fake-calls loc) => translated)
  "including metaconstant prerequisites"
  (let [original `( provided            ...m... =contains=> {:a 'a})
        translated `(        (data-fake ...m... =contains=> {:a 'a}) )
        z (zip/seq-zip original)
        loc (zip/down z)]
    (#'prereqs/expand-prerequisites-into-fake-calls loc) => translated))

(fact "prerequisite containers are deleted so their contents can be inserted elsewhere"
  (let [original '( (expect (f x) => (+ 1 2)) (provided ...) "next")
        edited   '( (expect (f x) => (+ 1 2))                "next")
        z (zip/seq-zip original)
        original-loc (-> z zip/down zip/right zip/down)
        resulting-loc
         (delete_prerequisite_form__then__at-previous-full-expect-form original-loc)]
marick/Midje
(ns implementation.parsing.util.fim_recognizing
  (:require [midje.sweet :refer :all]
            [midje.test-util :refer :all]
            [midje.parsing.2-to-lexical-maps.expects :refer [expect]]
            [midje.parsing.util.recognizing :refer :all]
            [clojure.zip :as zip]))

(tabular
 (fact "an embedded expect form can be recognized"
   (expect? (zip/seq-zip ?form)) => ?expected)


(fact "can ask if at first element of X =?> Y :possible :keywords"
  (let [possible (fn [nested-form] (zip/down (zip/seq-zip nested-form)))]
              "a string" =not=> start-of-checking-arrow-sequence?
              '(foo) =not=> start-of-checking-arrow-sequence?

(fact "can ask whether at the beginning of a form that provides prerequisites"
  (let [values (zip/seq-zip '(provided midje.sweet/provided fluke))]
    (-> values zip/down) => provided?
    (-> values zip/down zip/right) => provided?
    (-> values zip/down zip/right zip/right) =not=> provided?))
marick/Midje
(ns midje.parsing.1-to-explicit-form.t-facts
  (:require [midje.parsing.1-to-explicit-form.facts :as facts :refer :all]
            [midje.sweet :refer :all]
            [midje.test-util :refer :all]
            [midje.parsing.2-to-lexical-maps.expects :refer [expect]]
            [midje.parsing.2-to-lexical-maps.fakes :refer [fake]]
            [midje.parsing.2-to-lexical-maps.data-fakes :refer [data-fake]]
            [pointer.core :refer [line-number-known]]
            [clojure.zip :as zip]
            [midje.config :as config]))

(fact "can identify the head of a form that's already been expanded"
  (doseq [head `(expect fake data-fake)]
    (let [z (zip/seq-zip `(111 (~head 1 2 '(3)) "next"))
          skippable (-> z zip/down zip/next zip/down)]
      skippable => already-expanded?)))


(fact "one can add a line number to an arrow sequence"
  (let [original `( (f n) => 2  )
        expected `( (f n) => 2 :position (line-number-known 10))
        z            (zip/seq-zip original)
        original-loc (-> z zip/down zip/right)
        new-loc      (#'facts/at-arrow__add-line-number-to-end__no-movement
                       10 original-loc)]
    (name (zip/node new-loc)) => "=>"
    (zip/root new-loc) => expected))