 (s/fdef operation/take'
   :args (s/and (s/cat :n pos-int? :operation ::delta/operation)
                #(not (= :embed (some-> % :operation ::delta/insert key)))
-               #(<= (:n %) (-> % :operation unconform-operation operation/length)))
+               #(<= (:n %) (-> % :operation conformed-operation-length)))
   :ret ::delta/operation
   :fn (s/and operation-type-preserved?
              attributes-preserved?
-             length-clipped-to-n?
+             operation-shortenend-to-n?
              #(text-preserved? string/starts-with? %)))
 
 (s/fdef operation/take

(s/fdef operation/drop
  :args (s/cat :n int? :operation ::delta/operation)
  :ret (s/nilable ::delta/operation)
  :fn (s/or :nil (s/and #(>= (-> % :args :n) (-> % :args :operation unconform-operation operation/length))
                        #(-> % :ret nil?))
            :non-nil (s/and #(< (-> % :args :n) (-> % :args :operation unconform-operation operation/length))
                            operation-type-preserved?
                            attributes-preserved?
                            length-shortened-by-n?
                            #(text-preserved? string/ends-with? %))))

(s/fdef operation/delete
  :args (s/cat :n int?)
  :ret (s/nilable (s/and ::delta/operation
                         #(::delta/delete %)))
  :fn (s/or :nil (s/and #(-> % :args :n pos? not)
                        #(-> % :ret nil?))
            :non-nil (s/and #(-> % :args :n pos?)
                            #(= (-> % :args :n)
                                (-> % :ret operation/length)))))

(defn- operation-contents-preserved?
  ""
  [{:keys [args ret]}]
  (let [type (operation/type ret)]
    (= (type ret)
       (-> args :operation type))))

(defn- attributes-set?
  ""
  [{:keys [args ret]}]
  (let [arg-attrs (-> args :attributes)
        ret-attrs (-> ret ::delta/attributes)]

  :ret #{::delta/insert ::delta/delete ::delta/retain})

(defn- operation-type-preserved?
  "True if the instrumented function returned an operation with the
  same type as its `operation` argument.
  "
  [{:keys [args ret]}]
  (= (-> ret operation/type)
     (-> args :operation operation/type)))

(defn- attributes-preserved?
  "True if the instrumented function returned an operation with the
  same attributes as its `operation` argument.
  "
  [{:keys [args ret]}]
  (= (-> ret ::delta/attributes)
     (-> args :operation ::delta/attributes)))

(defn- operation-shortenend-to-n?
  "True if the instrumented function shortened its `operation` argument
  to `n` characters (`n` is also an argument).
  "
  [{:keys [args ret]}]
  (= (-> ret conformed-operation-length)
     (min (:n args) (-> args :operation conformed-operation-length))))

(defn- text-preserved?
  "True the text of the result operation of the instrumented function
  stands in `relation` to the text of its `operation` argument.
  "
  [relation {:keys [args ret]}]
  (let [insert-text (some->> args :operation ::delta/insert (apply hash-map) :text)]
    (or (nil? insert-text)
