ソースを参照

chore: remove fns made unused by OG removal

Found unused ones in deps/common, from unused frontend.db aliases
and from fns that only existed for their corresponding tests
Gabriel Horner 5 日 前
コミット
7d6782e706

+ 0 - 4
.carve/ignore

@@ -13,8 +13,6 @@ frontend.debug/print
 frontend.extensions.code/editor
 ;; Referenced in commented TODO
 frontend.extensions.pdf.utils/get-page-bounding
-;; For repl
-logseq.graph-parser.mldoc/ast-export-markdown
 ;; Protocol fn wrapper that could be used
 frontend.fs/readdir
 ;; Referenced in TODO
@@ -49,8 +47,6 @@ frontend.util.pool/terminate-pool!
 ;; Test runners used by shadow
 frontend.test.node-test-runner/main
 frontend.test.frontend-node-test-runner/main
-;; Test runner for nbb
-logseq.graph-parser.nbb-test-runner/run-tests
 ;; For debugging
 frontend.fs.sync/debug-print-sync-events-loop
 frontend.fs.sync/stop-debug-print-sync-events-loop

+ 0 - 69
deps/common/src/logseq/common/path.cljs

@@ -51,17 +51,6 @@
   [path]
   (second (split-ext path)))
 
-(defn safe-filename?
-  "Safe filename on all platforms"
-  [fname]
-  (and (not (string/blank? fname))
-       (< (count fname) 255)
-       (not (or (re-find #"[\/?<>\\:*|\"]" fname)
-                (re-find #"^\.+$" fname)
-                (re-find #"[\. ]$" fname)
-                (re-find #"(?i)^(COM[0-9]|CON|LPT[0-9]|NUL|PRN|AUX|com[0-9]|con|lpt[0-9]|nul|prn|aux)\..+" fname)
-                (re-find #"[\u0000-\u001f\u0080-\u009f]" fname)))))
-
 (defn- path-join-internal
   "Joins the given path segments into a single path, handling relative paths,
   '..' and '.' normalization."
@@ -253,31 +242,6 @@
         (js/console.error "unhandled trim-base" base-path sub-path)
         nil))))
 
-(defn relative-path
-  "Get relative path from base path.
-   Works for both path and URL."
-  [base-path sub-path]
-  (let [base-path (path-normalize base-path)
-        sub-path (path-normalize sub-path)
-        is-url? (is-file-url? base-path)]
-    (if (string/starts-with? sub-path base-path)
-      (if is-url?
-        (safe-decode-uri-component (string/replace (subs sub-path (count base-path)) #"^/+", ""))
-        (string/replace (subs sub-path (count base-path)) #"^/+", ""))
-      ;; append as many ..
-      ;; NOTE: This is a buggy impl, relative-path is different when base-path is a file or a dir
-      (let [base-segs (string/split base-path #"/" -1)
-            path-segs (string/split sub-path #"/" -1)
-            common-segs (take-while #(= (first %) (second %)) (map vector base-segs path-segs))
-            base-segs (drop (count common-segs) base-segs)
-            remain-segs (drop (count common-segs) path-segs)
-            base-prefix (apply str (repeat (max 0 (dec (count base-segs))) "../"))]
-        (js/console.error (js/Error. "buggy relative-path") base-path sub-path)
-        #_{:clj-kondo/ignore [:path-invalid-construct/string-join]}
-        (if is-url?
-          (safe-decode-uri-component (str base-prefix (string/join "/" remain-segs)))
-          (str base-prefix (string/join "/" remain-segs)))))))
-
 (defn parent
   "Parent, containing directory"
   [path]
@@ -286,45 +250,12 @@
     (path-normalize (str path "/.."))
     nil))
 
-(defn resolve-relative-path
-  "Assume current-path is a file"
-  [current-path rel-path]
-  (if-let [base-dir (parent current-path)]
-    (path-join base-dir rel-path)
-    rel-path))
-
-(defn get-relative-path
-  "Assume current-path is a file, and target-path is a file or directory.
-   Return relative path from current-path to target-path.
-   Works for both path and URL. Also works for relative path.
-   The opposite operation is `resolve-relative-path`"
-  [current-path target-path]
-  (let [base-path (parent current-path)
-        sub-path (path-normalize target-path)
-        is-url? (is-file-url? base-path)
-        base-segs (if base-path
-                    (string/split base-path #"/" -1)
-                    [])
-        path-segs (string/split sub-path #"/" -1)
-        common-segs (take-while #(= (first %) (second %)) (map vector base-segs path-segs))
-        base-segs (drop (count common-segs) base-segs)
-        remain-segs (drop (count common-segs) path-segs)
-        base-prefix (apply str (repeat (max 0 (count base-segs)) "../"))]
-    #_{:clj-kondo/ignore [:path-invalid-construct/string-join]}
-    (if is-url?
-      (safe-decode-uri-component (str base-prefix (string/join "/" remain-segs)))
-      (str base-prefix (string/join "/" remain-segs)))))
-
 ;; compat
 (defn basename
   [path]
   (let [path (string/replace path #"/+$" "")]
     (filename path)))
 
-(defn dirname
-  [path]
-  (parent path))
-
 (defn absolute?
   "Whether path `p` is absolute."
   [p]

+ 0 - 27
deps/common/src/logseq/common/util.cljs

@@ -48,16 +48,6 @@
   (when (string? tag-name)
     (not (re-find #"[#\t\r\n]+" tag-name))))
 
-(defn tag?
-  "Whether `s` is a tag."
-  [s]
-  (and (string? s)
-       (string/starts-with? s "#")
-       (or
-        (not (string/includes? s " "))
-        (string/starts-with? s "#[[")
-        (string/ends-with? s "]]"))))
-
 (defn safe-subs
   ([s start]
    (let [c (count s)]
@@ -66,10 +56,6 @@
    (let [c (count s)]
      (subs s (min c start) (min c end)))))
 
-(defn unquote-string
-  [v]
-  (string/trim (subs v 1 (dec (count v)))))
-
 (defn wrapped-by
   [v start end]
   (and (string? v) (>= (count v) 2)
@@ -254,15 +240,6 @@
   [fmt & args]
   (apply gstring/format fmt args))
 
-(defn remove-first [pred coll]
-  ((fn inner [coll]
-     (lazy-seq
-      (when-let [[x & xs] (seq coll)]
-        (if (pred x)
-          xs
-          (cons x (inner xs))))))
-   coll))
-
 (defn concat-without-nil
   [& cols]
   (->> (apply concat cols)
@@ -298,10 +275,6 @@
   [s old-value new-value]
   (string/replace s (re-pattern (str "(?i)" (escape-regex-chars old-value))) new-value))
 
-(defn replace-first-ignore-case
-  [s old-value new-value]
-  (string/replace-first s (re-pattern (str "(?i)" (escape-regex-chars old-value))) new-value))
-
 (defn sort-coll-by-dependency
   "Sort the elements in the collection based on dependencies.
 coll:  [{:id 1 :depend-on 2} {:id 2 :depend-on 3} {:id 3}]

+ 0 - 4
deps/common/src/logseq/common/util/block_ref.cljs

@@ -8,10 +8,6 @@
   (str left-parens right-parens))
 (def block-ref-re #"\(\(([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})\)\)")
 
-(defn get-all-block-ref-ids
-  [content]
-  (map second (re-seq block-ref-re content)))
-
 (defn get-block-ref-id
   "Extracts block id from block-ref using regex"
   [s]

+ 0 - 7
deps/common/src/logseq/common/util/macro.cljs

@@ -4,19 +4,12 @@
 
 (def left-braces "Opening characters for macro" "{{")
 (def right-braces "Closing characters for macro" "}}")
-(def query-macro (str left-braces "query"))
 
 (defn macro?
   [*s]
   (when-let [s (and (string? *s) (string/trim *s))]
     (and (string/starts-with? s left-braces) (string/ends-with? s right-braces))))
 
-(defn query-macro?
-  [s]
-  (and (string? s)
-       (string/includes? s (str query-macro " "))
-       (not (string/includes? s (str "`" query-macro)))))
-
 (defn macro-subs
   [macro-content arguments]
   (loop [s macro-content

+ 0 - 15
deps/common/test/logseq/common/path_test.cljs

@@ -12,21 +12,6 @@
   (is (= ["some-song" ""] (path/split-ext "some-song")))
   (is (= ["some-file.edn" "txt"] (path/split-ext "some-file.edn.txt"))))
 
-(deftest safe-file-name?
-  (testing "safe-file-name"
-    (is (path/safe-filename? "foo"))
-    (is (path/safe-filename? "foo bar"))
-    (is (path/safe-filename? "foo-bar"))
-    (is (path/safe-filename? "foo_bar"))
-    (is (path/safe-filename? "foo.bar"))
-    (is (path/safe-filename? "foo..bar"))
-    (is (path/safe-filename? "foo...bar"))
-    (is (not (path/safe-filename? "foo/bar")))
-    (is (not (path/safe-filename? "foo?bar")))
-    (is (not (path/safe-filename? "foo<bar")))
-    (is (not (path/safe-filename? "foo>bar")))))
-
-
 (deftest path-join
   (testing "path-join"
     (is (= "foo/bar" (path/path-join "foo" "bar")))

+ 0 - 4
deps/graph-parser/.carve/ignore

@@ -3,15 +3,11 @@ logseq.graph-parser.mldoc/ast-export-markdown
 ;; API
 logseq.graph-parser.mldoc/block-with-title?
 ;; API
-logseq.graph-parser.mldoc/link?
-;; API
 logseq.graph-parser.mldoc/->db-edn
 ;; API
 logseq.graph-parser.text/get-file-basename
 ;; API
 logseq.graph-parser.mldoc/mldoc-link?
-;; public var
-logseq.graph-parser.schema.mldoc/block-ast-coll-schema
 ;; API
 logseq.graph-parser.text/get-page-name
 logseq.graph-parser.text/get-namespace-last-part

+ 0 - 6
deps/graph-parser/src/logseq/graph_parser/mldoc.cljc

@@ -201,12 +201,6 @@
                 ;; 3. local asset link
                 (boolean (common-config/local-relative-asset? ref-value))))))))
 
-(defn link?
-  [format link]
-  (when (string? link)
-    (some-> (first (inline->edn link (default-config format)))
-            ast-link?)))
-
 (defn mldoc-link?
   "Check whether s is a link (including page/block refs)."
   [format s]

+ 0 - 3
deps/graph-parser/src/logseq/graph_parser/schema/mldoc.cljc

@@ -215,6 +215,3 @@
 
 (def block-ast-with-pos-coll-schema
   [:sequential [:cat block-ast-schema [:maybe pos-schema]]])
-
-(def block-ast-coll-schema
-  [:sequential block-ast-schema])

+ 0 - 36
deps/graph-parser/test/logseq/graph_parser/mldoc_test.cljs

@@ -3,42 +3,6 @@
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.text :as text]))
 
-(deftest test-link
-  (testing "non-link"
-    (are [x y] (= (gp-mldoc/link? :markdown x) y)
-      "google.com" false))
-
-  (testing "plain links"
-    (are [x y] (= (gp-mldoc/link? :markdown x) y)
-      "http://www.google.com" true
-      "http://google.com" true))
-
-  (testing "org links with labels"
-    (are [x y] (= (gp-mldoc/link? :org x) y)
-      "[[http://www.google.com][google]]" true
-      "[[http://google.com][google]]" true
-      "[[https://www.google.com][google]]" true
-      "[[https://google.com][google]]" true))
-
-  (testing "org links without labels"
-    (are [x y] (= (gp-mldoc/link? :org x) y)
-      "[[http://www.google.com]]" true
-      "[[https://www.google.com]]" true
-      "[[draws/2022-03-06-15-00-28.excalidraw]]" true
-      "[[assets/2022-03-06-15-00-28.pdf]]" true))
-
-  (testing "markdown links"
-    (are [x y] (= (gp-mldoc/link? :markdown x) y)
-      "[google](http://www.google.com)" true
-      "[google](https://www.google.com)" true
-      "[[draws/2022-03-06-15-00-28.excalidraw]]" true
-      "![a pdf](assets/2022-03-06-15-00-28.pdf)" true))
-
-  ;; https://github.com/logseq/logseq/issues/4308
-  (testing "parsing links should be finished"
-    (are [x y] (= (gp-mldoc/link? :markdown x) y)
-      "[YouTube](https://www.youtube.com/watch?v=-8ym7pyUs9gL) - [Vimeo](https://vimeo.com/677920303) {{youtube https://www.youtube.com/watch?v=-8ym7pyUs9g}}" true)))
-
 (def md-config (gp-mldoc/default-config :markdown))
 
 (deftest src-test

+ 0 - 0
deps/graph-parser/src/logseq/graph_parser/test/docs_graph_helper.cljs → deps/graph-parser/test/logseq/graph_parser/test/docs_graph_helper.cljs


+ 0 - 1
src/dev-cljs/gen_malli_kondo_config/core.cljs

@@ -2,7 +2,6 @@
   "Used to generate kondo config from malli-schema"
   (:require-macros [gen-malli-kondo-config.collect :refer [collect-schema]])
   (:require [frontend.util]
-            [frontend.util.list]
             [malli.clj-kondo :as mc]
             [malli.instrument]))
 

+ 0 - 41
src/main/frontend/config.cljs

@@ -104,47 +104,6 @@
 
 (def media-formats (set/union (common-config/img-formats) audio-formats video-formats))
 
-(defn extname-of-supported?
-  ([input] (extname-of-supported?
-            input
-            [image-formats doc-formats audio-formats
-             video-formats markup-formats
-             (common-config/text-formats)]))
-  ([input formats]
-   (when-let [input (some->
-                     (cond-> input
-                       (and (string? input)
-                            (not (string/blank? input)))
-                       (string/replace-first "." ""))
-                     (util/safe-lower-case)
-                     (keyword))]
-     (boolean
-      (some
-       (fn [s]
-         (contains? s input))
-       formats)))))
-
-(defn ext-of-video?
-  ([s] (ext-of-video? s true))
-  ([s html5?]
-   (when-let [s (and (string? s) (util/get-file-ext s))]
-     (let [video-formats' (cond-> video-formats
-                            html5? (disj :mkv))]
-       (extname-of-supported? s [video-formats'])))))
-
-(defn ext-of-audio?
-  ([s] (ext-of-audio? s true))
-  ([s html5?]
-   (when-let [s (and (string? s) (util/get-file-ext s))]
-     (let [audio-formats' (cond-> audio-formats
-                            html5? (disj :wma :ogg))]
-       (extname-of-supported? s [audio-formats'])))))
-
-(defn ext-of-image?
-  [s]
-  (when-let [s (and (string? s) (util/get-file-ext s))]
-    (extname-of-supported? s [image-formats])))
-
 (def mobile?
   "Triggering condition: Mobile phones
    *** Warning!!! ***

+ 0 - 8
src/main/frontend/date.cljs

@@ -87,14 +87,6 @@
                  :minute "2-digit"
                  :hourCycle "h23"}))))
 
-(defn normalize-date
-  [s]
-  (common-date/normalize-date s (state/get-date-formatter)))
-
-(defn normalize-journal-title
-  [title]
-  (common-date/normalize-journal-title title (state/get-date-formatter)))
-
 (defn valid-journal-title?
   [title]
   (common-date/valid-journal-title? title (state/get-date-formatter)))

+ 5 - 7
src/main/frontend/db.cljs

@@ -14,7 +14,6 @@
 (import-vars
  [frontend.db.conn
   ;; TODO: remove later
-  get-repo-path
   get-repo-name
   get-short-repo-name
   get-db
@@ -24,13 +23,12 @@
   entity pull pull-many]
 
  [frontend.db.model
-  delete-files get-block-and-children get-block-by-uuid sort-by-order
-  get-block-parent get-block-parents parents-collapsed?
-  get-block-immediate-children get-block-page
-  get-file file-exists?  get-files-full
-  get-latest-journals get-page get-case-page get-page-alias-names
+  get-block-and-children get-block-by-uuid sort-by-order
+  get-block-parent get-block-parents
+  get-block-immediate-children get-file
+  get-latest-journals get-page get-case-page
   get-page-format journal-page? page? sub-block
-  page-empty? page-exists? get-alias-source-page
+  page-exists? get-alias-source-page
   has-children? whiteboard-page?])
 
 (defn start-db-conn!

+ 0 - 55
src/main/frontend/db/model.cljs

@@ -26,23 +26,6 @@
   (when-let [db (conn/get-db repo)]
     (ldb/get-alias-source-page db alias-id)))
 
-(defn file-exists?
-  [repo path]
-  (when (and repo path)
-    (when-let [db (conn/get-db repo)]
-      (db-utils/entity db [:file/path path]))))
-
-(defn get-files-full
-  [repo]
-  (when-let [db (conn/get-db repo)]
-    (->>
-     (d/q
-      '[:find (pull ?file [*])
-        :where
-        [?file :file/path]]
-      db)
-     (flatten))))
-
 (defn get-file
   ([path]
    (get-file (state/get-current-repo) path))
@@ -109,13 +92,6 @@ independent of format as format specific heading characters are stripped"
   [repo-url page-id]
   (ldb/page-alias-set (conn/get-db repo-url) page-id))
 
-(defn get-page-alias-names
-  [repo page-id]
-  (let [alias-ids (->> (page-alias-set repo page-id)
-                       (remove #{page-id}))]
-    (when (seq alias-ids)
-      (map (fn [id] (:block/title (db-utils/entity id))) alias-ids))))
-
 (defn with-pages
   [blocks]
   (let [pages-ids (->> (map (comp :db/id :block/page) blocks)
@@ -255,13 +231,6 @@ independent of format as format specific heading characters are stripped"
     (when-let [db (conn/get-db repo)]
       (ldb/page-exists? db page-name tags))))
 
-(defn page-empty?
-  "Whether a page is empty. Does it has a non-page block?
-  `page-id` could be either a string or a db/id."
-  [repo page-id]
-  (when-let [db (conn/get-db repo)]
-    (ldb/page-empty? db page-id)))
-
 (defn parents-collapsed?
   [repo block-uuid]
   (when-let [block (:block/parent (get-block-parents-v2 repo block-uuid))]
@@ -313,36 +282,12 @@ independent of format as format specific heading characters are stripped"
   (when-let [db (conn/get-db repo)]
     (graph-view/get-pages-that-mentioned-page db page-id include-journals?)))
 
-(defn get-referenced-blocks
-  ([eid]
-   (get-referenced-blocks (state/get-current-repo) eid))
-  ([repo eid]
-   (when repo
-     (when (conn/get-db repo)
-       (let [entity (db-utils/entity eid)
-             ids (page-alias-set repo eid)
-             entities (mapcat (fn [id]
-                                (:block/_refs (db-utils/entity id))) ids)]
-         (->> entities
-              (remove (fn [block]
-                        (or
-                         (= (:db/id block) eid)
-                         (= eid (:db/id (:block/page block)))
-                         (ldb/hidden? (:block/page block))
-                         (contains? (set (map :db/id (:block/tags block))) (:db/id entity))
-                         (some? (get block (:db/ident entity))))))
-              (util/distinct-by :db/id)))))))
-
 (defn journal-page?
   "sanitized page-name only"
   [page-name]
   (when (string? page-name)
     (ldb/journal? (ldb/get-page (conn/get-db) page-name))))
 
-(defn delete-files
-  [files]
-  (mapv (fn [path] [:db.fn/retractEntity [:file/path path]]) files))
-
 (defn whiteboard-page?
   "Given a page entity, page object or page name, check if it is a whiteboard page"
   [page]

+ 1 - 30
src/main/frontend/format/block.cljs

@@ -2,12 +2,10 @@
   "Block code needed by app but not graph-parser. This should be the only frontend
    namespace that has references to legacy file attributes like :block/pre-block?
    as they are being removed from graph-parser output"
-  (:require [cljs-time.format :as tf]
-            [cljs.cache :as cache]
+  (:require [cljs.cache :as cache]
             [clojure.string :as string]
             [frontend.common.cache :as common.cache]
             [frontend.config :as config]
-            [frontend.date :as date]
             [frontend.db :as db]
             [frontend.format :as format]
             [frontend.format.mldoc :as mldoc]
@@ -45,33 +43,6 @@ and handles unexpected failure."
         (notification/show! "An unexpected error occurred during block extraction." :error)
         []))))
 
-(defn- normalize-as-percentage
-  [block]
-  (some->> block
-           str
-           (re-matches #"(-?\d+\.?\d*)%")
-           second
-           (#(/ % 100))))
-
-(defn- normalize-as-date
-  [block]
-  (some->> block
-           str
-           date/normalize-date
-           (tf/unparse date/custom-formatter)))
-
-(defn normalize-block
-  "Normalizes supported formats such as dates and percentages.
-   Be careful, this function may harm query sort performance!
-   - nlp-date? - Enable NLP parsing on date items.
-       Requires heavy computation (see `normalize-as-date` for details)"
-  [block nlp-date?]
-  (->> [normalize-as-percentage (when nlp-date? normalize-as-date) identity]
-       (remove nil?)
-       (map #(% (if (set? block) (first block) block)))
-       (remove nil?)
-       (first)))
-
 (defn parse-block
   [{:block/keys [uuid title format] :as block}]
   (when-not (string/blank? title)

+ 0 - 32
src/main/frontend/util.cljc

@@ -194,10 +194,6 @@
      (p/do!
       (.setStyle StatusBar (clj->js {:style (.-Dark Style)})))))
 
-(defn find-first
-  [pred coll]
-  (first (filter pred coll)))
-
 (defn find-index
   "Find first index of an element in list"
   [pred-or-val coll]
@@ -368,22 +364,6 @@
            last-newline-content (subs s (inc before-last-newline-length) from-newline-index)]
        (.countGraphemes splitter last-newline-content))))
 
-#?(:cljs
-   (defn get-text-range
-     "Return the substring of the first grapheme-num characters of s if first-line? is true,
-      otherwise return the substring of s before the last \n and the first grapheme-num characters.
-
-      grapheme-num treats multi-char as 1, like emoji characters"
-     [s grapheme-num first-line?]
-     (let [newline-pos (if first-line?
-                         0
-                         (inc (or (string/last-index-of s \newline) -1)))
-           ^js splitter (GraphemeSplitter.)
-           ^js newline-graphemes (.splitGraphemes splitter (subs s newline-pos))
-           ^js newline-graphemes (.slice newline-graphemes 0 grapheme-num)
-           content (.join newline-graphemes "")]
-       (subs s 0 (+ newline-pos (count content))))))
-
 #?(:cljs
    (defn stop [e]
      (when e (doto e (.preventDefault) (.stopPropagation)))))
@@ -1011,18 +991,6 @@
         {:result ret#
          :time (- (cljs.core/system-time) start#)})))
 
-;; TODO: profile and profileEnd
-
-(comment
-  (= (get-relative-path "journals/2020_11_18.org" "pages/grant_ideas.org")
-     "../pages/grant_ideas.org")
-
-  (= (get-relative-path "journals/2020_11_18.org" "journals/2020_11_19.org")
-     "./2020_11_19.org")
-
-  (= (get-relative-path "a/b/c/d/g.org" "a/b/c/e/f.org")
-     "../e/f.org"))
-
 (defn keyname [key] (str (namespace key) "/" (name key)))
 
 #?(:cljs

+ 0 - 29
src/main/frontend/util/list.cljs

@@ -1,29 +0,0 @@
-(ns frontend.util.list
-  "High level list operations for use in editor"
-  (:require [clojure.string :as string]))
-
-(defn- newline?
-  [line]
-  (or (= line "\n") (= line "\r\n")))
-
-(defn re-order-items
-  [lines start-idx]
-  (loop [lines lines
-         idx start-idx
-         result []
-         double-newlines? false]
-    (let [[line & others] lines]
-      (if (empty? lines)
-        (->> result
-             (map (fn [line] (if (newline? line) "" line)))
-             (string/join "\n"))
-        (let [[_ num-str] (re-find #"^(\d+){1}\." line)
-              num (if num-str (parse-long num-str) nil)
-              double-newlines?' (or double-newlines?
-                                     (and (newline? line) (seq others) (newline? (first others))))
-              [idx' result'] (if (and (not double-newlines?') num)
-                               (let [idx' (inc idx)
-                                     line' (string/replace-first line (str num ".") (str idx' "."))]
-                                 [idx' (conj result line')])
-                               [idx (conj result line)])]
-          (recur others idx' result' double-newlines?'))))))

+ 3 - 40
src/test/frontend/db/model_test.cljs

@@ -1,5 +1,5 @@
 (ns frontend.db.model-test
-  (:require [cljs.test :refer [use-fixtures deftest is are]]
+  (:require [cljs.test :refer [use-fixtures deftest is]]
             [datascript.core :as d]
             [frontend.db :as db]
             [frontend.db.conn :as conn]
@@ -11,38 +11,6 @@
 
 (def test-db test-helper/test-db)
 
-(deftest test-page-alias-with-multiple-alias
-  (let [ab-uuid (random-uuid)
-        aa-uuid (random-uuid)]
-    (load-test-files
-     [{:page {:block/title "ab"
-              :build/keep-uuid? true
-              :block/uuid ab-uuid
-              :build/properties {:block/alias #{[:block/uuid aa-uuid]
-                                                [:build/page {:block/title "ad"}]}}}}
-      {:page {:block/title "aa"
-              :build/keep-uuid? true
-              :block/uuid aa-uuid
-              :build/properties {:block/alias #{[:block/uuid ab-uuid]
-                                                [:build/page {:block/title "ac"}]}}}}
-      {:page {:block/title "ae"}
-       :blocks [{:block/title (str "## ref to [[" ab-uuid "]]")}]}]))
-
-  (let [aid (:db/id (test-helper/find-page-by-title "aa"))
-        bid (:db/id (test-helper/find-page-by-title "ab"))
-        a-aliases (model/page-alias-set test-db aid)
-        b-aliases (model/page-alias-set test-db bid)
-        alias-names (model/get-page-alias-names test-db aid)
-        b-ref-blocks (model/get-referenced-blocks bid)
-        a-ref-blocks (model/get-referenced-blocks aid)]
-
-    (are [x y] (= x y)
-      4 (count a-aliases)
-      4 (count b-aliases)
-      1 (count b-ref-blocks)
-      1 (count a-ref-blocks)
-      #{"ab" "ac" "ad"} (set alias-names))))
-
 (deftest test-page-alias-set
   (let [ab-uuid (random-uuid)]
     (load-test-files
@@ -56,13 +24,8 @@
        :blocks [{:block/title (str "## ref to [[" ab-uuid "]]")}]}]))
 
   (let [page-id (:db/id (test-helper/find-page-by-title "aa"))
-        a-aliases (model/page-alias-set test-db page-id)
-        alias-names (model/get-page-alias-names test-db page-id)
-        a-ref-blocks (model/get-referenced-blocks page-id)]
-    (are [x y] (= x y)
-      3 (count a-aliases)
-      1 (count a-ref-blocks)
-      #{"ab" "ac"} (set alias-names))))
+        a-aliases (model/page-alias-set test-db page-id)]
+    (is (= 3 (count a-aliases)))))
 
 (defn- page-mention-check?
   [page-name include-journals?]

+ 0 - 117
src/test/frontend/format/block_test.cljs

@@ -1,117 +0,0 @@
-(ns frontend.format.block-test 
-  (:require [cljs.test :refer [deftest testing are]]
-            [frontend.format.block :as block]
-            [frontend.date :as date]
-            [frontend.util :as util]))
-
-(deftest test-normalize-date
-  (testing "normalize date values"
-    (are [x y] (= (block/normalize-block x true) y)
-         "Aug 12th, 2022"
-         "2022-08-12T00:00:00Z"
-
-         "2022-08-12T00:00:00Z"
-         "2022-08-12T00:00:00Z"
-
-         #{"Aug 12th, 2022"}
-         "2022-08-12T00:00:00Z"
-
-         #{"2022-08-12T00:00:00Z"}
-         "2022-08-12T00:00:00Z")))
-
-(deftest monitor-normalize-date-time
-  (testing "monitor time consumption of normalize date values"
-    (are [x _y timeout] (>= timeout (:time (util/with-time (block/normalize-block x true))))
-      "Aug 12th, 2022"
-      "2022-08-12T00:00:00Z"
-      50.0 ;; actual 2.2
-
-      "2022-08-12T00:00:00Z"
-      "2022-08-12T00:00:00Z"
-      1000.0 ;; actual 125
-
-      #{"Aug 12th, 2022"}
-      "2022-08-12T00:00:00Z"
-      50.0 ;; actual 1.7
-
-      #{"2022-08-12T00:00:00Z"}
-      "2022-08-12T00:00:00Z"
-      250.0  ;; actual 17.0
-      )))
-
-(deftest test-normalize-percentage
-  (testing "normalize percentages"
-    (are [x y] (= (block/normalize-block x false) y)
-         "50%"
-         0.5
-
-         "0%"
-         0
-
-         "-5%"
-         -0.05
-
-         #{"50%"}
-         0.5)))
-
-(deftest test-normalize-random-values
-  (testing "random values should not be processed"
-    (are [x y] (= (block/normalize-block x false) y)
-         "anreanre"
-         "anreanre"
-
-         ""
-         ""
-
-         "a.0%"
-         "a.0%"
-
-         "%"
-         "%"
-
-         "-%"
-         "-%")))
-
-(deftest monitor-normalize-randome-values-time
-  (testing "monitor time consumption of random values should not be processed"
-    (are [x _y timeout] (>= timeout (:time (util/with-time (block/normalize-block x false))))
-      "anreanre"
-      "anreanre"
-      2.0 ;; actual 0.07
-
-      ""
-      ""
-      2.0 ;; actual 0.07
-
-      "a.0%"
-      "a.0%"
-      0.5 ;; actual 0.02
-
-      "%"
-      "%"
-      1.0 ;; actual 0.03
-
-      "-%"
-      "-%"
-      0.5 ;; actual 0.02
-      )))
-
-(deftest test-normalize-journal-title
-  (testing "normalize journal titles"
-    (are [x y] (let [f #(-> % date/normalize-journal-title str)]
-                 (= (f x) y))
-      "Aug 12th, 2022"
-      "20220812T000000"
-
-      "2022-08-12"
-      "20220812T000000"
-
-      "2022-10"
-      ""
-
-      "2022Q4"
-      ""
-
-      "2022-08"
-      "")))
-

+ 0 - 30
src/test/frontend/util/list_test.cljs

@@ -1,30 +0,0 @@
-(ns frontend.util.list-test
-  (:require [cljs.test :refer [deftest is testing]]
-            [frontend.util.list :as list-util]))
-
-(deftest test-re-order-items
-  (testing "Single list"
-    (is (= (list-util/re-order-items
-            ["2. x"
-             "3. x"]
-            2)
-           "3. x\n4. x"))
-    (is (= (list-util/re-order-items
-            ["7. x"
-             "foo"
-             "bar 3."
-             "5. x"
-             "baz"]
-            2)
-           "3. x\nfoo\nbar 3.\n4. x\nbaz")))
-  (testing "Only reorder the first list"
-    (is (= (list-util/re-order-items
-            ["7. x"
-             "foo"
-             "\n"
-             "\n"
-             "bar 3."
-             "5. x"
-             "baz"]
-            2)
-           "3. x\nfoo\n\n\nbar 3.\n5. x\nbaz"))))

+ 2 - 38
src/test/frontend/util_test.cljs

@@ -1,11 +1,6 @@
 (ns frontend.util-test
   (:require [cljs.test :refer [deftest is testing]]
-            [frontend.util :as util]
-            [frontend.config :as config]))
-
-(deftest test-find-first
-  (testing "find-first"
-    (is (= 1 (util/find-first identity [1])))))
+            [frontend.util :as util]))
 
 (deftest test-delete-emoji-current-pos
   (testing "safe current position from end for emoji"
@@ -39,24 +34,6 @@
     (is (= 1 (util/get-line-pos "abc\n😀d\ne" 6)))
     (is (= 2 (util/get-line-pos "ab\nc😀d\ne" 6)))))
 
-(deftest test-get-text-range
-  (testing "get-text-range"
-    (is (= "" (util/get-text-range "abcdefg" 0 true)))
-    (is (= "" (util/get-text-range "abcdefg" 0 false)))
-    (is (= "abcdefg" (util/get-text-range "abcdefg" 10 true)))
-    (is (= "abcdefg" (util/get-text-range "abcdefg" 10 false)))
-    (is (= "abc" (util/get-text-range "abcdefg" 3 true)))
-    (is (= "abc" (util/get-text-range "abcdefg" 3 false)))
-    (is (= "abc" (util/get-text-range "abcdefg\nhijklmn" 3 true)))
-    (is (= "abcdefg\nhij" (util/get-text-range "abcdefg\nhijklmn" 3 false)))
-    (is (= "abcdefg\nhijklmn" (util/get-text-range "abcdefg\nhijklmn" 10 false)))
-    (is (= "abcdefg\nhijklmn\nopq" (util/get-text-range "abcdefg\nhijklmn\nopqrst" 3 false)))
-    (is (= "a😀b" (util/get-text-range "a😀bcdefg" 3 true)))
-    (is (= "a😀b" (util/get-text-range "a😀bcdefg" 3 false)))
-    (is (= "a😀b" (util/get-text-range "a😀bcdefg\nhijklmn" 3 true)))
-    (is (= "a😀bcdefg\nhij" (util/get-text-range "a😀bcdefg\nhijklmn" 3 false)))
-    (is (= "a😀bcdefg\nh😀i" (util/get-text-range "a😀bcdefg\nh😀ijklmn" 3 false)))))
-
 (deftest test-memoize-last
   (testing "memoize-last add test"
     (let [actual-ops (atom 0)
@@ -75,17 +52,4 @@
       (is (= (m+ 3 5) 8))
       (is (= @actual-ops 4))
       (is (= (m+ 3 5) 8))
-      (is (= @actual-ops 4)))))
-
-(deftest test-media-format-from-input
-  (testing "predicate file type from ext (html5 supported)"
-    (is (= (config/ext-of-audio? "file.mp3") true))
-    (is (= (config/ext-of-audio? "fIle.mP3") true))
-    (is (= (config/ext-of-audio? "https://x.com/file.mp3") true))
-    (is (= (config/ext-of-audio? "file.wma") false))
-    (is (= (config/ext-of-audio? "file.wma" false) true))
-    (is (= (config/ext-of-video? "file.mp4") true))
-    (is (= (config/ext-of-video? "file.mp3") false))
-    (is (= (config/ext-of-image? "file.svg") true))
-    (is (= (config/ext-of-image? "a.file.png") true))
-    (is (= (config/ext-of-image? "file.tiff") false))))
+      (is (= @actual-ops 4)))))