Bläddra i källkod

All query-dsl tests pass for db graphs

Add to CI. Also fix graph-parser lint and typo
Gabriel Horner 2 år sedan
förälder
incheckning
991c0994e5

+ 7 - 3
.github/workflows/build.yml

@@ -77,10 +77,14 @@ jobs:
       - name: Fetch yarn deps
         run: yarn install --frozen-lockfile
 
+      - name: Build test asset
+        run: clojure -M:test compile test
+
+      - name: Run some ClojureScript tests against DB version
+        run: DB_GRAPH=1 node static/tests.js -r frontend.db.query-dsl-test
+
       - name: Run ClojureScript tests
-        run: |
-          yarn cljs:test
-          node static/tests.js
+        run: node static/tests.js
 
   lint:
     runs-on: ubuntu-latest

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

@@ -37,6 +37,8 @@ logseq.graph-parser/get-blocks-to-delete
 ;; Future use & be unified with markdown colon
 logseq.graph-parser.property/colons-org
 ;; API
+logseq.graph-parser.property/full-built-in-properties
+;; API
 logseq.graph-parser.util.db/resolve-input
 ;; TODO: use fast-remove-nils instead
 logseq.graph-parser.util/remove-nils

+ 1 - 1
src/main/frontend/db/query_dsl.cljs

@@ -613,7 +613,7 @@ Some bindings in this fn:
     col))
 
 (defn get-db-property-value
-  "Fetch a property's value given a block map and proeprty name. Similar to
+  "Fetch a property's value given a block map and property name. Similar to
   query-table/sort-by-fn. We should standardize this soon"
   [m prop]
   (case prop

+ 3 - 2
src/test/frontend/db/query_dsl_test.cljs

@@ -138,7 +138,7 @@ prop-d:: nada"}])
               (dsl-query "(property prop-d)")))
       "Blocks that have a property"))
 
-(deftest ^:focus block-property-queries
+(deftest block-property-queries
   (testing "block property tests with default config"
     (test-helper/with-config {}
       (block-property-queries-test))))
@@ -479,7 +479,8 @@ tags: [[other]]
 
 (deftest between-queries
   (load-test-files [{:file/path "journals/2020_12_26.md"
-                     :file/content "- DONE 26-b1
+                     :file/content "foo::bar
+- DONE 26-b1
 created-at:: 1608968448113
 - LATER 26-b2-modified-later
 created-at:: 1608968448114

+ 25 - 17
src/test/frontend/test/helper.cljs

@@ -37,8 +37,9 @@
 (defn- property-lines->properties
   [property-lines]
   (->> property-lines
-       (map #(let [[k v] (string/split % #"::\s*" 2)]
-               [(keyword k) (parse-property-value v)]))
+       (keep #(let [[k v] (string/split % #"::\s*" 2)]
+               (when (string/includes? % "::")
+                 [(keyword k) (parse-property-value v)])))
        (into {})))
 
 (defn- build-block-properties
@@ -51,7 +52,10 @@
           (mapv (fn [s]
                   (let [[content & props] (string/split-lines s)]
                     {:name-or-content content
-                     :properties (property-lines->properties props)}))))}
+                     ;; If no property chars may accidentally parse child blocks
+                     ;; so don't do property parsing
+                     :properties (when (and (string/includes? s ":: ") props)
+                                   (property-lines->properties props))}))))}
     {:page-properties
      (->> file-content
           string/split-lines
@@ -74,22 +78,26 @@
         (build-block-properties (:file/content file))]
     (if page-properties
       (merge file
-             {:file/block-properties [{:name-or-content (file-path->page-name (:file/path file))
-                                       :properties page-properties
-                                       :page-properties? true}]
-              :page-properties? false})
+             {:file/block-properties (vec (keep #(when (seq (:properties %)) %)
+                                                [{:name-or-content (file-path->page-name (:file/path file))
+                                                  :properties page-properties
+                                                  :page-properties? true}]))})
       (merge file
-             {:file/block-properties (cond-> block-properties
+             {:file/block-properties
+              ;; Filter out empty empty properties to avoid needless downstream processing
+              (cond-> (vec (keep #(when (seq (:properties %)) %) block-properties))
                                        ;; Optionally add page properties as a page block
-                                       (re-find #"^\s*[^-]+" (:name-or-content (first block-properties)))
-                                       (conj {:name-or-content (file-path->page-name (:file/path file))
-                                              :properties (->> (:name-or-content (first block-properties))
-                                                               string/split-lines
-                                                               property-lines->properties)
-                                              :page-properties? true}))
-              ;; Rewrite content to strip it of properties which shouldn't be in content
-              :file/content (string/join "\n"
-                                         (map (fn [x] (str "- " (:name-or-content x))) block-properties))}))))
+                (re-find #"^\s*[^-]+" (:name-or-content (first block-properties)))
+                (conj {:name-or-content (file-path->page-name (:file/path file))
+                       :properties (->> (:name-or-content (first block-properties))
+                                        string/split-lines
+                                        property-lines->properties)
+                       :page-properties? true}))}
+             ;; Rewrite content to strip it of properties which shouldn't be in content
+             ;; but only if properties are detected
+             (when (some #(seq (:properties %)) block-properties)
+               {:file/content (string/join "\n"
+                                           (map (fn [x] (str "- " (:name-or-content x))) block-properties))})))))
 
 (defn- load-test-files-for-db-graph
   [files*]