Skip to content

Commit

Permalink
Setting up tests(java)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranshila committed Sep 3, 2021
1 parent 46eccfb commit d0dda06
Show file tree
Hide file tree
Showing 11 changed files with 797 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.class
.lsp/
yarn-error.log
junit.xml
/.cpcache
/.lein-*
/.nrepl-history
Expand Down
12 changes: 8 additions & 4 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
cljs-bean/cljs-bean {:mvn/version "1.7.0"}
thheller/shadow-cljs {:mvn/version "2.15.5"}}

:aliases
{:build {:extra-paths ["build"]
:deps {io.github.seancorfield/build-clj {:git/url "https://github.com/kiranshila/build-clj" :git/sha "a4e03bc9e4ed78087120c4e7b10152cff1a4837b"}}
:ns-default build}}}
:aliases {:test {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "1.0.887"}
lambdaisland/kaocha-junit-xml {:mvn/version "0.0.76"}
lambdaisland/kaocha-cloverage {:mvn/version "1.0.75"}}
:main-opts ["-m" "kaocha.runner"]}
:build {:extra-paths ["build"]
:deps {io.github.seancorfield/build-clj {:git/url "https://github.com/kiranshila/build-clj" :git/sha "a4e03bc9e4ed78087120c4e7b10152cff1a4837b"}}
:ns-default build}}}
2 changes: 1 addition & 1 deletion src/cybermonday/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
true ir/md-to-ir
(:process-templates? opts) templates/parse-templates
true (lowering/to-html-hiccup opts)
true utils/cleanup-whitespace)))
true utils/cleanup)))
([md] (parse-body md nil)))

(defn parse-md
Expand Down
5 changes: 3 additions & 2 deletions src/cybermonday/utils.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@

(def html-comment-re #"<!--([\s\S]*?)-->")

(defn cleanup-whitespace
"Removes excess whitespace from the resulting AST."
(defn cleanup
"Removes excess whitespace and nils from the resulting AST."
[hiccup]
(walk/postwalk
(fn [item]
(cond
(string? item) (when (seq item) item)
(hiccup? item) (filterv (complement nil?) item)
:else item))
hiccup))
35 changes: 35 additions & 0 deletions test/cybermonday/test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(ns cybermonday.test
(:require [clojure.test :refer [deftest testing is]]
[cybermonday.ir :as ir]
[cybermonday.core :as cm]
[clojure.edn :as edn]
[clojure.java.io :as io]))

(def test-document (slurp (io/resource "test-document.md")))
(def test-frontmatter-document (slurp (io/resource "test-frontmatter.md")))

(def expected-ir (edn/read-string (slurp (io/resource "expected-ir.edn"))))
(def expected-html (edn/read-string (slurp (io/resource "expected-html.edn"))))

(deftest ir
(testing "Parsing to IR"
(is (= expected-ir (ir/md-to-ir test-document)))))

(deftest frontmatter
(testing "Parsing frontmatter"
(let [{:keys [frontmatter body]} (cm/parse-md test-frontmatter-document)]
(is (= {:title "Test Frontmatter"
:author (list "Kiran Shila")
:code "data"
:tags (list "cybermonday" "unit-tests")}
frontmatter))
(is (= [:div {}
[:h1 {:id "test"} "Test"]
[:p {} "This file contains " [:em {} "markdown"]]]
body)))))

(deftest html
(testing "Parsing to HTML"
(is (= expected-html (cm/parse-body test-document)))))

(cm/parse-body test-document)
175 changes: 175 additions & 0 deletions test/expected-html.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
[:div
{}
[:h1 {:id "cybermonday-test-document"} "Cybermonday Test Document"]
[:p
{}
"This document will hopefully cover all the different AST node types that are"
"available in commonmark + the enabled features in Cybermonday."]
[:h2 {:id "easy-stuff"} "Easy stuff"]
[:p {} "Here are two different kinds of lists:"]
[:p {} "An ordered list"]
[:ol {} [:li {} [:p {} "Foo"]] [:li {} [:p {} "Bar"]] [:li {} [:p {} "Baz"]]]
[:p {} "And unordered list"]
[:ul
{}
[:li {} [:p {} "Test1"]]
[:li {} [:p {} "Test2"]]
[:li {} [:p {} "Test3"]]]
[:p {} "We can nest the lists"]
[:ol
{}
[:li {} [:p {} "First item"]]
[:li {} [:p {} "Second item"]]
[:li
{}
[:p {} "Third item"]
[:ol {} [:li {} [:p {} "Indented item"]] [:li {} [:p {} "Indented item"]]]]
[:li {} [:p {} "Fourth item"]]]
[:ul
{}
[:li {} [:p {} "First item"]]
[:li {} [:p {} "Second item"]]
[:li
{}
[:p {} "Third item"]
[:ul {} [:li {} [:p {} "Indented item"]] [:li {} [:p {} "Indented item"]]]]
[:li {} [:p {} "Fourth item"]]]
[:ol
{}
[:li {} [:p {} "First item"]]
[:li {} [:p {} "Second item"]]
[:li
{}
[:p {} "Third item"]
[:ul {} [:li {} [:p {} "Indented item"]] [:li {} [:p {} "Indented item"]]]]
[:li {} [:p {} "Fourth item"]]]
[:p {} "All heading levels"]
[:h1 {:id "heading-level-1"} "Heading level 1"]
[:h2 {:id "heading-level-2"} "Heading level 2"]
[:h3 {:id "heading-level-3"} "Heading level 3"]
[:h4 {:id "heading-level-4"} "Heading level 4"]
[:h5 {:id "heading-level-5"} "Heading level 5"]
[:h6 {:id "heading-level-6"} "Heading level 6"]
[:p {} "####### This shouldn't be a heading"]
[:h1
{:id "alternative-heading-syntaxheading-level-1"}
"Alternative heading syntax"
"Heading level 1"]
[:h2 {:id "heading-level-2"} "Heading level 2"]
[:p
{}
"This should be one paragraph."
"Even though they are on different lines"]
[:p {} "This however is a new paragraph."]
[:p {} "We can create an hr with"]
[:hr {}]
[:p
{}
"Here is text with "
[:strong {} "Bold"]
", "
[:strong {} "bold"]
", "
[:em {} "italic"]
", "
[:em {} "italic"]
", "
[:strong {} [:em {} "bold_italic"]]
"."]
[:blockquote {} [:p {} "This is a quote"]]
[:blockquote {} [:p {} "This is a quote with " [:em {} "markdown"] " in it."]]
[:blockquote
{}
[:p
{}
"This is a quote with "
[:em {} "markdown"]
" and "
[:p {:class "my-class"} "HTML"]
" in it"]]
[:blockquote
{}
[:p {} "This is a quote"]
[:blockquote {} [:p {} "With another quote in it"]]]
[:p {} [:img {:src "image_url.png", :alt "An Image!", :title nil}]]
[:p {} "Here is some code"]
[:pre {} [:code {:class "language-julia"} "using LinearAlgebra\n"]]
[:p {} "Also some " [:code {} "inline code stuff"] "."]
[:h1 {:id "links"} "Links"]
[:p
{}
"My favorite search engine is "
[:a {:href "https://duckduckgo.com", :title nil} "Duck Duck Go"]
"."]
[:p
{}
"My favorite search engine is "
[:a
{:href "https://duckduckgo.com",
:title "The best search engine for privacy"}
"Duck Duck Go"]
"."]
[:p
{}
[:a {:href "https://www.markdownguide.org"} "https://www.markdownguide.org"]
[:a {:href "mailto:[email protected]"}]]
[:p
{}
"You can markdown links too: I love supporting the "
[:strong {} [:a {:href "https://eff.org", :title nil} "EFF"]]
"."
[:a
{:href "https://en.wikipedia.org/wiki/Hobbit#Lifestyle", :title nil}
"hobbit-hole"]]
[:p
{}
"Here is an image link:"
[:a
{:href
"https://www.flickr.com/photos/beaurogers/31833779864/in/photolist-Qv3rFw-34mt9F-a9Cmfy-5Ha3Zi-9msKdv-o3hgjr-hWpUte-4WMsJ1-KUQ8N-deshUb-vssBD-6CQci6-8AFCiD-zsJWT-nNfsgB-dPDwZJ-bn9JGn-5HtSXY-6CUhAL-a4UTXB-ugPum-KUPSo-fBLNm-6CUmpy-4WMsc9-8a7D3T-83KJev-6CQ2bK-nNusHJ-a78rQH-nw3NvT-7aq2qf-8wwBso-3nNceh-ugSKP-4mh4kh-bbeeqH-a7biME-q3PtTf-brFpgb-cg38zw-bXMZc-nJPELD-f58Lmo-bXMYG-bz8AAi-bxNtNT-bXMYi-bXMY6-bXMYv",
:title nil}
[:img
{:src "/assets/images/shiprock.jpg",
:alt "An old rock in the desert",
:title "Shiprock, New Mexico by Beau Rogers"}]]]
[:p
{}
"We should be able to escape stuff like: You use backticks (\\`code\\`) to write"
"inline code."]
[:h1 {:id "non-commonmark-stuff"} "Non-commonmark stuff"]
[:p {} "Checkboxes from github"]
[:ul
{}
[:li
{}
[:input {:checked true, :disabled true, :type "checkbox"}]
[:p {} "#739"]]
[:li
{}
[:input {:checked false, :disabled true, :type "checkbox"}]
[:p {} "https://github.com/octo-org/octo-repo/issues/740"]]
[:li
{}
[:input {:checked false, :disabled true, :type "checkbox"}]
[:p {} "Add delight to the experience when all tasks are complete :tada:"]]]
[:p {} "Tables"]
[:table
{}
[:thead {} [:tr {} [:th {} "First Header"] [:th {} "Second Header"]]]
[:tbody
{}
[:tr {} [:td {} "Content Cell"] [:td {} "Content Cell"]]
[:tr {} [:td {} "Content Cell"] [:td {} "Content Cell"]]]]
[:p {} "We can do inline math with " [:code {} "y=mx+b"]]
[:p {} "We can do block math with just a code block"]
[:pre {} [:code {:class "language-math"} "E=mc^2\n"]]
[:p {} "Finally, we can do footnotes"]
[:p
{}
"Paragraph with a footnote reference"
[:sup {:id "fnref-1"} [:a {:href "#fn-1"}]]]
[:li
{:id "fn-1"}
[:p
[:span "Footnote text added at the bottom of the document\n"]
[:a {:href "#fnref-1"} ""]]]]
Loading

0 comments on commit d0dda06

Please sign in to comment.