From 4aa6bf978f28c38e0faebadbec9ffe40f366a52a Mon Sep 17 00:00:00 2001 From: "Johan Mynhardt (MEA)" <johanmynhardt@gmail.com> Date: Sat, 21 May 2022 16:19:57 +0200 Subject: [PATCH 1/4] Add test for `transform` java.lang.ClassCastException When `obj` argument is a string (X)HTML payload and not a string URL or URI, the following exception is thrown: ```clojure java.lang.ClassCastException: class java.lang.Class cannot be cast to class clojure.lang.IFn ``` --- test/html_to_md/transformer_test.clj | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/html_to_md/transformer_test.clj diff --git a/test/html_to_md/transformer_test.clj b/test/html_to_md/transformer_test.clj new file mode 100644 index 0000000..e1b7e5f --- /dev/null +++ b/test/html_to_md/transformer_test.clj @@ -0,0 +1,13 @@ +(ns html-to-md.transformer-test + (:require + [clojure.string :as str] + [clojure.test :as t :refer [deftest is testing]] + [html-to-md.html-to-md :refer [markdown-dispatcher]] + [html-to-md.transformer :refer [transform]])) + +(deftest transform-payload + (testing "String `obj` for: 3. A string representation of an (X)HTML fragment;" + (is (= "# This is a header" + (str/trim (-> "<h1>This is a header" + (transform markdown-dispatcher) + (first))))))) From 44b28902db6c7aaa53bbf5c22b4fb527a2724e7b Mon Sep 17 00:00:00 2001 From: "Johan Mynhardt (MEA)" <johanmynhardt@gmail.com> Date: Sat, 21 May 2022 16:26:28 +0200 Subject: [PATCH 2/4] Fix: java.lang.ClassCastException Use trailing dot in constructing the StringReader: `(java.io.StringReader. s)` --- src/html_to_md/transformer.clj | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/html_to_md/transformer.clj b/src/html_to_md/transformer.clj index 5933b3c..445aba5 100644 --- a/src/html_to_md/transformer.clj +++ b/src/html_to_md/transformer.clj @@ -93,6 +93,4 @@ (if url (transform url dispatcher) ;; otherwise, if s is not a URL, consider it as an HTML fragment, ;; parse and process it - (process (tagsoup/parser (java.io.StringReader s)) dispatcher) - ))) - + (process (tagsoup/parser (java.io.StringReader. s)) dispatcher)))) From ac80507b5f5c39213a649d0aee2ca4877ac1ce4d Mon Sep 17 00:00:00 2001 From: Johan Mynhardt <johanmynhardt@gmail.com> Date: Thu, 26 May 2022 04:10:09 +0200 Subject: [PATCH 3/4] Update transformer_test.clj Use more appropriate test without `str/trim`. --- test/html_to_md/transformer_test.clj | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/html_to_md/transformer_test.clj b/test/html_to_md/transformer_test.clj index e1b7e5f..1a1e6d8 100644 --- a/test/html_to_md/transformer_test.clj +++ b/test/html_to_md/transformer_test.clj @@ -7,7 +7,5 @@ (deftest transform-payload (testing "String `obj` for: 3. A string representation of an (X)HTML fragment;" - (is (= "# This is a header" - (str/trim (-> "<h1>This is a header" - (transform markdown-dispatcher) - (first))))))) + (is (= '("\n# This is a header\n") + (transform "<h1>This is a header</h1>" markdown-dispatcher))))) From 08af65936684b8ff60a9b3ec83eb534f9c261836 Mon Sep 17 00:00:00 2001 From: "Johan Mynhardt (MEA)" <johanmynhardt@gmail.com> Date: Thu, 26 May 2022 21:24:56 +0200 Subject: [PATCH 4/4] Remove unused import. --- test/html_to_md/transformer_test.clj | 1 - 1 file changed, 1 deletion(-) diff --git a/test/html_to_md/transformer_test.clj b/test/html_to_md/transformer_test.clj index 1a1e6d8..48369a4 100644 --- a/test/html_to_md/transformer_test.clj +++ b/test/html_to_md/transformer_test.clj @@ -1,6 +1,5 @@ (ns html-to-md.transformer-test (:require - [clojure.string :as str] [clojure.test :as t :refer [deftest is testing]] [html-to-md.html-to-md :refer [markdown-dispatcher]] [html-to-md.transformer :refer [transform]]))