Skip to content

Commit

Permalink
Mldoc tests run under nbb
Browse files Browse the repository at this point in the history
  • Loading branch information
logseq-cldwalker committed May 11, 2022
1 parent 20b8b96 commit b79b1ca
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 42 deletions.
1 change: 1 addition & 0 deletions .clj-kondo/config.edn
Expand Up @@ -21,6 +21,7 @@
frontend.util util
frontend.config config
frontend.format.mldoc mldoc
logseq.graph-parser.text text
logseq.graph-parser.mldoc gp-mldoc
logseq.graph-parser.util gp-util
logseq.graph-parser.config gp-config}}}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Expand Up @@ -74,11 +74,13 @@ jobs:
- name: Fetch yarn deps
run: yarn install --frozen-lockfile

- name: Run ClojureScript test
- name: Run ClojureScript tests
run: |
yarn cljs:test
node static/tests.js
- name: Run nbb tests for graph-parser
run: yarn nbb-logseq -cp src/main:src/test -m logseq.graph-parser.nbb-test-runner/run-tests
# In this job because it depends on an npm package
- name: Load nbb compatible namespaces
run: bb test:load-nbb-compatible-namespaces
Expand Down
5 changes: 5 additions & 0 deletions src/main/frontend/format.cljs
Expand Up @@ -3,8 +3,13 @@
[frontend.format.adoc :refer [->AdocMode]]
[frontend.format.protocol :as protocol]
[logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.text :as text]
[clojure.string :as string]))

;; TODO: Properly fix this circular dependency:
;; mldoc/->edn > text/parse-property > mldoc/link? ->mldoc/inline->edn + mldoc/default-config
(set! gp-mldoc/parse-property text/parse-property)

(defonce mldoc-record (->MldocMode))
(defonce adoc-record (->AdocMode))

Expand Down
5 changes: 0 additions & 5 deletions src/main/logseq/graph_parser/text.cljs
Expand Up @@ -363,8 +363,3 @@

:else
(split-page-refs-without-brackets v)))))

;; TODO: Properly fix this circular dependency:
;; mldoc/->edn > text/parse-property > mldoc/link? ->mldoc/inline->edn + mldoc/default-config
(set! gp-mldoc/parse-property parse-property)
; (alter-var-root #'gp-mldoc/parse-property (constantly parse-property))
3 changes: 1 addition & 2 deletions src/test/logseq/graph_parser/mldoc_test.cljs
Expand Up @@ -3,7 +3,6 @@
["fs" :as fs]
["child_process" :as child-process]
[clojure.string :as string]
[clojure.edn :as edn]
;; hack needed for parse-property to exist
[logseq.graph-parser.text]
[cljs.test :refer [testing deftest are is]]))
Expand Down Expand Up @@ -103,7 +102,7 @@
; (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"))
#_(is (= (clojure.edn/read-string (slurp "mldoc-asts.edn"))
asts-by-file)
"Matches initial AST")
#_(println "Wrote asts for" (count asts-by-file) "files")
Expand Down
21 changes: 21 additions & 0 deletions src/test/logseq/graph_parser/nbb_test_runner.cljs
@@ -0,0 +1,21 @@
(ns logseq.graph-parser.nbb-test-runner
"Nbb tests for graph-parser"
(:require [cljs.test :as t]
[logseq.graph-parser.mldoc :as gp-mldoc]
[logseq.graph-parser.text :as text]
; [logseq.graph-parser.text-test]
[logseq.graph-parser.mldoc-test]))

(defmethod cljs.test/report [:cljs.test/default :end-run-tests] [m]
(when-not (cljs.test/successful? m)
(set! (.-exitCode js/process) 1)))

;; run this function with: nbb-logseq -m logseq.test.nbb-test-runner/run-tests
(defn run-tests []
;; This hack is the same as the one in frontend.format. This has to be in an nbb only
;; ns since alter-var-root doesn't exist in cljs and nbb doesn't support set! yet
#_:clj-kondo/ignore
(alter-var-root #'gp-mldoc/parse-property (constantly text/parse-property))
(t/run-tests 'logseq.graph-parser.mldoc-test
;; TODO: Enable when https://github.com/babashka/nbb/issues/187 works
#_'logseq.graph-parser.text-test))
48 changes: 25 additions & 23 deletions src/test/logseq/graph_parser/text_test.cljs
@@ -1,32 +1,30 @@
(ns logseq.graph-parser.text-test
(:require [cljs.test :refer [are deftest testing]]
[frontend.config :as config]
[frontend.state :as state]
[logseq.graph-parser.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
"[[page]]" "page"
"[[another page]]" "another page"
"[single bracket]" nil
"no brackets" nil

"[[another page]]" "another page"
"[[nested [[page]]]]" "nested [[page]]"
"[[another page]]" "another page"
"[[nested [[page]]]]" "nested [[page]]"

"[[file:./page.org][page]]" "page"
"[[file:./pages/page.org][page]]" "page"
"[[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"
"[[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"
"[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"))
"[logseq/page](file:./logseq.page.md)" "logseq/page"
"[logseq/page](file:./pages/logseq.page.md)" "logseq/page"))

(deftest page-ref?
[]
Expand Down Expand Up @@ -76,22 +74,26 @@
"#tag1,#tag2" #{"tag1" "tag2"}
"[[Jan 26th, 2021]], hello" #{"hello" "Jan 26th, 2021"}))

(def block-patterns
{:markdown "-"
:org "*"})

(deftest remove-level-spaces
[]
(testing "markdown"
(are [x y] (= (text/remove-level-spaces x :markdown (config/get-block-pattern :markdown) true) y)
(are [x y] (= (text/remove-level-spaces x :markdown (block-patterns :markdown) true) y)
"- foobar" "foobar"
" - foobar" "foobar"))
(testing "markdown without spaces between the `#` and title"
(are [x y] (= (text/remove-level-spaces x :markdown (config/get-block-pattern :markdown)) y)
(are [x y] (= (text/remove-level-spaces x :markdown (block-patterns :markdown)) y)
"-foobar" "foobar"))
(testing "org"
(are [x y] (= (text/remove-level-spaces x :org (config/get-block-pattern :org) true) y)
(are [x y] (= (text/remove-level-spaces x :org (block-patterns :org) true) y)
"* foobar" "foobar"
"** foobar" "foobar"
"********************* foobar" "foobar"))
(testing "org without spaces between the `#` and title"
(are [x y] (= (text/remove-level-spaces x :org (config/get-block-pattern :org)) y)
(are [x y] (= (text/remove-level-spaces x :org (block-patterns :org)) y)
"*foobar" "foobar"
"**foobar" "foobar"
"*********************foobar" "foobar")))
Expand Down Expand Up @@ -128,7 +130,7 @@

(deftest test-parse-property
(testing "parse-property"
(are [k v y] (= (text/parse-property k v (state/get-config)) y)
(are [k v y] (= (text/parse-property k v {}) y)
:tags "foo" "foo"
:tags "foo, bar" #{"foo" "bar"}
:tags "foo,bar" #{"foo" "bar"}
Expand All @@ -140,7 +142,7 @@
:tags "[[foo [[bar]]]]" #{"foo [[bar]]"}
:tags "[[foo [[bar]]]], baz" #{"baz" "foo [[bar]]"}))
(testing "parse-property with quoted strings"
(are [k v y] (= (text/parse-property k v (state/get-config)) y)
(are [k v y] (= (text/parse-property k v {}) y)
:tags "\"foo, bar\"" "\"foo, bar\""
:tags "\"[[foo]], [[bar]]\"" "\"[[foo]], [[bar]]\""
:tags "baz, \"[[foo]], [[bar]]\"" #{"baz"})))
Expand Down
11 changes: 0 additions & 11 deletions src/test/logseq/test/nbb_test_runner.cljs

This file was deleted.

0 comments on commit b79b1ca

Please sign in to comment.