mirror of
https://github.com/logseq/logseq.git
synced 2026-05-29 23:19:38 +00:00
Necessary parts of mldoc are nbb compatible
Also merged in parser tests which were not running
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
(ns frontend.parser
|
||||
(:require [cljs.test :refer [is deftest]]
|
||||
[logseq.graph-parser.mldoc :as gp-mldoc]
|
||||
[frontend.format.mldoc :as mldoc :refer [->edn]]))
|
||||
|
||||
(def md-config (gp-mldoc/default-config :markdown))
|
||||
|
||||
(deftest src-test
|
||||
(is (=
|
||||
(first (->edn "```
|
||||
: hello
|
||||
```" md-config))
|
||||
[["Src"
|
||||
{:lines [": hello" "\n"],
|
||||
:pos_meta {:start_pos 4, :end_pos 12},
|
||||
:full_content "```\n: hello\n```"}]
|
||||
{:start_pos 0, :end_pos 15}])))
|
||||
|
||||
(deftest name-definition-test
|
||||
(is (=
|
||||
(first (->edn "term
|
||||
: definition" md-config))
|
||||
[["List"
|
||||
[{:content [["Paragraph" [["Plain" "definition"]]]],
|
||||
:items [],
|
||||
:name [["Plain" "term"]],
|
||||
:indent 0,
|
||||
:ordered false}]]
|
||||
{:start_pos 0, :end_pos 17}])))
|
||||
@@ -1,38 +1,38 @@
|
||||
(ns frontend.format.mldoc-test
|
||||
(:require [frontend.format.mldoc :as mldoc]
|
||||
[logseq.graph-parser.mldoc :as gp-mldoc]
|
||||
(ns logseq.graph-parser.mldoc-test
|
||||
(:require [logseq.graph-parser.mldoc :as gp-mldoc]
|
||||
["fs" :as fs]
|
||||
["child_process" :as child-process]
|
||||
[clojure.string :as string]
|
||||
[clojure.edn :as edn]
|
||||
[frontend.format]
|
||||
[cljs.test :refer [testing deftest are is]]))
|
||||
|
||||
(deftest test-link
|
||||
(testing "non-link"
|
||||
(are [x y] (= (mldoc/link? :markdown x) y)
|
||||
(are [x y] (= (gp-mldoc/link? :markdown x) y)
|
||||
"google.com" false))
|
||||
|
||||
(testing "plain links"
|
||||
(are [x y] (= (mldoc/link? :markdown x) y)
|
||||
(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] (= (mldoc/link? :org x) y)
|
||||
(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] (= (mldoc/link? :org x) y)
|
||||
(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] (= (mldoc/link? :markdown x) y)
|
||||
(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
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
;; https://github.com/logseq/logseq/issues/4308
|
||||
(testing "parsing links should be finished"
|
||||
(are [x y] (= (mldoc/link? :markdown x) y)
|
||||
(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)))
|
||||
|
||||
;; TODO: Reuse with repo-test fns
|
||||
@@ -75,8 +75,8 @@
|
||||
(let [format (if (string/ends-with? path ".org")
|
||||
:org :markdown)]
|
||||
[path
|
||||
(mldoc/->edn content
|
||||
(gp-mldoc/default-config format))])))
|
||||
(gp-mldoc/->edn content
|
||||
(gp-mldoc/default-config format))])))
|
||||
(into {}))]
|
||||
(is (= {"CommentBlock" 1,
|
||||
"Custom" 41,
|
||||
@@ -97,9 +97,35 @@
|
||||
(->> asts-by-file (mapcat val) (map ffirst) frequencies))
|
||||
"AST node type counts")
|
||||
|
||||
; (println :DIFF)
|
||||
; (prn (butlast (clojure.data/diff (edn/read-string (slurp "mldoc-asts.edn"))
|
||||
; asts-by-file)))
|
||||
;; This is just temporary
|
||||
(is (= (edn/read-string (slurp "mldoc-asts.edn"))
|
||||
asts-by-file)
|
||||
"Matches initial AST")
|
||||
#_(println "Wrote asts for" (count asts-by-file) "files")
|
||||
#_(fs/writeFileSync "mldoc-asts.edn" (pr-str asts-by-file))))
|
||||
|
||||
(def md-config (gp-mldoc/default-config :markdown))
|
||||
|
||||
(deftest src-test
|
||||
(is (= [["Src"
|
||||
{:lines [": hello" "\n"],
|
||||
:pos_meta {:start_pos 4, :end_pos 12},
|
||||
:full_content "```\n: hello\n```"}]
|
||||
{:start_pos 0, :end_pos 15}]
|
||||
(first (gp-mldoc/->edn "```
|
||||
: hello
|
||||
```" md-config)))))
|
||||
|
||||
(deftest name-definition-test
|
||||
(is (= [["List"
|
||||
[{:content [["Paragraph" [["Plain" "definition"]]]],
|
||||
:items [],
|
||||
:name [["Plain" "term"]],
|
||||
:indent 0,
|
||||
:ordered false}]]
|
||||
{:start_pos 0, :end_pos 17}]
|
||||
(first (gp-mldoc/->edn "term
|
||||
: definition" md-config)))))
|
||||
Reference in New Issue
Block a user