Skip to content

Commit

Permalink
Added more tests, removed hard line break
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranshila committed Sep 3, 2021
1 parent b580919 commit 8ab1677
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 10 deletions.
6 changes: 0 additions & 6 deletions doc/02-AST.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ Please note that some of these are Flexmark specific and not available in remark
[:markdown/ordered-list-item {} "Item"]
```

### Hard Line Break

```clojure
[:markdown/hard-line-break {}]
```

### Soft Line Break

```clojure
Expand Down
2 changes: 1 addition & 1 deletion src/cybermonday/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
{Paragraph :p
Emphasis :em
ThematicBreak :hr
HardLineBreak :markdown/hard-line-break
HardLineBreak :br
SoftLineBreak :markdown/soft-line-break
Document :div
StrongEmphasis :strong
Expand Down
88 changes: 85 additions & 3 deletions test/cybermonday/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,61 @@

(t/deftest ir
(t/testing "Parsing to IR"
(t/testing "Paragraphs"
(t/is (= [:div {} [:p {} "aaa"] [:p {} "bbb"]] (ir/md-to-ir "aaa\n\nbbb")))
(t/is (= [:div {} [:p {} "aaabbb"]] (ir/md-to-ir " aaabbb")))
(t/is (= [:div {} [:p {} "aaa" [:br {}] "bbb"]] (ir/md-to-ir "aaa \nbbb "))))
(t/testing "Block Quotes"
(t/is (= [:div {} [:blockquote {}
[:markdown/heading {:level 1} "Foo"]
[:p {} "bar"]]]
(ir/md-to-ir "> # Foo\n> bar")))
(t/is (= [:div {} [:blockquote {}
[:p {} "foo"]
[:p {} "bar"]]]
(ir/md-to-ir "> foo\n>\n> bar")))
#_(t/is (= [:div {} [:blockquote {} ;; Softline breaks are not working in JS
[:blockquote {}
[:blockquote {}
[:p {} "foo\nbar\nbaz"]]]]]
(ir/md-to-ir ">>> foo\n> bar\n>>baz"))))
(t/testing "List Items"

(t/is (= [:div {} [:ol {}
[:markdown/ordered-list-item {} [:p {} "One"]]
[:markdown/ordered-list-item {} [:p {} "Two"]]
[:markdown/ordered-list-item {} [:p {} "Three"]]]]
(ir/md-to-ir "1. One\n2. Two\n3. Three")))
(t/is (= [:div {} [:ul {}
[:markdown/bullet-list-item {} [:p {} "One"]]
[:markdown/bullet-list-item {} [:p {} "Two"]]
[:markdown/bullet-list-item {} [:p {} "Three"]]]]
(ir/md-to-ir "- One\n- Two\n- Three")))
(t/is (= [:div {} [:ul {}
[:markdown/bullet-list-item {}
[:p {} "foo"]
[:ul {}
[:markdown/bullet-list-item {}
[:p {} "bar"]
[:ul {}
[:markdown/bullet-list-item {}
[:p {} "baz"]
[:ul {}
[:markdown/bullet-list-item {}
[:p {} "boo"]]]]]]]]]]
(ir/md-to-ir "- foo\n - bar\n - baz\n - boo")))
(t/is (= [:div {}
[:ul {}
[:markdown/bullet-list-item {}
[:p {} "foo"]]
[:markdown/bullet-list-item {}
[:p {} "bar"]]]
[:ul {}
[:markdown/bullet-list-item {}
[:p {} "baz"]]]]
(ir/md-to-ir "- foo\n- bar\n+ baz"))))
(t/testing "Inlines"
(t/is (= [:div {} [:p {} [:code {} "hi"] "lo`"]] (ir/md-to-ir "`hi`lo`"))))
(t/testing "Thematic Breaks"
(t/is (= [:div {} [:hr {}]] (ir/md-to-ir "***")))
(t/is (= [:div {} [:hr {}]] (ir/md-to-ir "---")))
Expand All @@ -22,10 +77,37 @@
(t/is (= [:div {} [:markdown/heading {:level 1} [:em {} "Heading"]]] (ir/md-to-ir "# *Heading*")))
(t/is (= [:div {} [:markdown/heading {:level 1} "Heading"]] (ir/md-to-ir "Heading\n===\n")))
(t/is (= [:div {} [:markdown/heading {:level 2} "Heading"]] (ir/md-to-ir "Heading\n-\n")))
(t/is (= [:div {} [:markdown/heading {:level 1}
[:p {:class "foo" :id "heading"} "Heading"]]] (ir/md-to-ir "# <p class=\"foo\" id=heading>Heading</p>"))))
(t/is (= [:div {}
[:markdown/heading {:level 1}
[:p {:class "foo" :id "heading"} "Heading"]]] (ir/md-to-ir "# <p class=\"foo\" id=heading>Heading</p>"))))
(t/testing "Code Blocks"
(t/is (= [:div {} [:markdown/fenced-code-block {:language "clojure"} "(+ 1 1)"]] (ir/md-to-ir "```clojure\n(+ 1 1)\n```")))
(t/is (= [:div {} [:markdown/fenced-code-block {:language nil} "foo + bar"]] (ir/md-to-ir "```\nfoo + bar\n```")))
(t/is (= [:div {} [:markdown/indented-code-block {} "x = x+1"]] (ir/md-to-ir "\tx = x+1\n")))
(t/is (= [:div {} [:markdown/indented-code-block {} "x = x+1"]] (ir/md-to-ir " x = x+1\n"))))))
(t/is (= [:div {} [:markdown/indented-code-block {} "x = x+1"]] (ir/md-to-ir " x = x+1\n"))))
(t/testing "Links"
(t/is (= [:div {}
[:markdown/reference {:title "title" :label "foo" :url "/url"}]
[:p {}
[:markdown/link-ref
{:reference [:markdown/reference {:title "title" :label "foo" :url "/url"}]}
"foo"]]]
(ir/md-to-ir "[foo]: /url \"title\"\n\n[foo]")))
(t/is (= [:div {} [:p {} [:a {:href "/uri" :title nil} "link"]]] (ir/md-to-ir "[link](/uri)")))
(t/is (= [:div {} [:p {} [:a {:href "#fragment" :title "title"} "link"]]] (ir/md-to-ir "[link](#fragment \"title\")")))
(t/is (= [:div {} [:p {} [:markdown/autolink {:href "https://kiranshila.com"}]]] (ir/md-to-ir "<https://kiranshila.com>")))
(t/is (= [:div {} [:p {} [:markdown/mail-link {:address "[email protected]"}]]] (ir/md-to-ir "<[email protected]>"))))
(t/testing "Images"
(t/is (= [:div {} [:p {} [:img {:alt "foo" :src "/url" :title "title"}]]] (ir/md-to-ir "![foo](/url \"title\")")))
#_(t/is (= [:div {} [:p {} ;; Complex image ref example broken in js
[:markdown/image-ref
{:reference
[:markdown/reference {:label "foo *bar*"
:title "train & tracks"
:url "train.jpg"}]}
"foo "
[:em {} "bar"]]]
[:markdown/reference {:label "foo *bar*"
:title "train & tracks"
:url "train.jpg"}]]
(ir/md-to-ir "![foo *bar*][]\n\n[foo *bar*]: train.jpg \"train & tracks\""))))))

0 comments on commit 8ab1677

Please sign in to comment.