test(fs): simple test for protocol-url

enhance/apis-improvements
Andelf 2023-04-26 11:14:27 +08:00 committed by Gabriel Horner
parent 0c91829365
commit 880ea8b00e
2 changed files with 13 additions and 1 deletions

View File

@ -315,5 +315,5 @@
This is a loose check, it only checks if there is a valid protocol prefix."
[p]
(boolean (and (re-find #"^[a-zA-Z0-9_+\-\.]+:" p)
(boolean (and (re-find #"^[a-zA-Z0-9_+\-\.]{2,}:" p) ;; HACK: avoid matching windows drive
(not (string/includes? p " ")))))

View File

@ -45,3 +45,15 @@
(is (false? (path/absolute? "test.md")))
(is (false? (path/absolute? "test")))
(is (false? (path/absolute? "D:test.md")))))
(deftest protocol-url
(testing "protocol url"
(is (true? (path/protocol-url? "mailto:help@logseq.com")))
(is (true? (path/protocol-url? "https://logseq.com")))
(is (true? (path/protocol-url? "ftp://logseq.com")))
(is (true? (path/protocol-url? "file:///home/xxx/logseq/test.md")))
(is (true? (path/protocol-url? "assets:///home/xxx/logseq/test.md")))
(is (false? (path/protocol-url? "logseq/test.md")))
(is (false? (path/protocol-url? "test.md")))
(is (false? (path/protocol-url? "test")))
(is (false? (path/protocol-url? "D:test.md")))))