extract_test.cljs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. (ns logseq.graph-parser.extract-test
  2. (:require [cljs.test :refer [deftest is]]
  3. [logseq.graph-parser.extract :as extract]
  4. [clojure.pprint :as pprint]))
  5. (defn- extract
  6. [text]
  7. (let [result (extract/extract-blocks-pages "a.md" text {:block-pattern "-"})
  8. result (last result)
  9. lefts (map (juxt :block/parent :block/left) result)]
  10. (if (not= (count lefts) (count (distinct lefts)))
  11. (do
  12. (pprint/pprint (map (fn [x] (select-keys x [:block/uuid :block/level :block/content :block/left])) result))
  13. (throw (js/Error. ":block/parent && :block/left conflicts")))
  14. (mapv :block/content result))))
  15. (deftest test-extract-blocks-pages
  16. []
  17. (is (= ["a" "b" "c"]
  18. (extract
  19. "- a
  20. - b
  21. - c")))
  22. (is (= ["## hello" "world" "nice" "nice" "bingo" "world"]
  23. (extract "## hello
  24. - world
  25. - nice
  26. - nice
  27. - bingo
  28. - world")))
  29. (is (= ["# a" "## b" "### c" "#### d" "### e" "f" "g" "h" "i" "j"]
  30. (extract "# a
  31. ## b
  32. ### c
  33. #### d
  34. ### e
  35. - f
  36. - g
  37. - h
  38. - i
  39. - j"))))
  40. (deftest test-regression-1902
  41. []
  42. (is (= ["line1" "line2" "line3" "line4"]
  43. (extract
  44. "- line1
  45. - line2
  46. - line3
  47. - line4"))))