enhance get-page-name and add some tests

pull/3101/head
leizhe 2021-11-09 10:35:41 +08:00 committed by Tienson Qin
parent 238a74f3a3
commit 86302b41f1
2 changed files with 23 additions and 1 deletions

View File

@ -20,7 +20,8 @@
(or (when-let [[_ label _path] (re-matches markdown-page-ref-re s)]
(string/trim label))
(when-let [[_ path _label] (re-matches org-page-ref-re s)]
(get-file-basename path))
(-> (get-file-basename path)
(string/replace "." "/")))
(-> (re-matches page-ref-re-0 s)
second))))

View File

@ -2,6 +2,27 @@
(:require [cljs.test :refer [are deftest testing]]
[frontend.text :as text]))
(deftest test-get-page-name
[]
(are [x y] (= (text/get-page-name x) y)
"[[page]]" "page"
"[[another page]]" "another page"
"[single bracket]" nil
"no brackets" nil
"[[file:./page.org][page]]" "page"
"[[file:./pages/page.org][page]]" "page"
"[[file:./namespace.page.org][namespace/page]]" "namespace/page"
"[[file:./pages/namespace.page.org][namespace/page]]" "namespace/page"
"[[file:./pages/namespace.page.org][please don't change me]]" "namespace/page"
"[page](file:./page.md)" "page"
"[page](file:.pages/page.md)" "page"
"[logseq/page](file:./logseq.page.md)" "logseq/page"
"[logseq/page](file:./pages/logseq.page.md)" "logseq/page"))
(deftest page-ref?
[]
(are [x y] (= (text/page-ref? x) y)