From 983753c8591e347c89b54539e6925668e5e73b7e Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 2 Apr 2017 16:09:47 -0400 Subject: [PATCH] fix css unit tests consistency sort map attribute keys before generating style string so they always get generated in the same way --- src/clj_htmltopdf/css.clj | 2 +- test/clj_htmltopdf/test/css.clj | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/clj_htmltopdf/css.clj b/src/clj_htmltopdf/css.clj index f9ac911..97285bd 100644 --- a/src/clj_htmltopdf/css.clj +++ b/src/clj_htmltopdf/css.clj @@ -34,7 +34,7 @@ (.append sb indent) (.append sb (css-rule-name-str names)) (.append sb " {\n") - (doseq [[attr-name attr-value] attrs] + (doseq [[attr-name attr-value] (sort-by first attrs)] (when-let [attr-str (css-attr-str attr-name attr-value)] (.append sb attr-indent) (.append sb attr-str) diff --git a/test/clj_htmltopdf/test/css.clj b/test/clj_htmltopdf/test/css.clj index 5cb3792..d30316c 100644 --- a/test/clj_htmltopdf/test/css.clj +++ b/test/clj_htmltopdf/test/css.clj @@ -50,9 +50,9 @@ (str (css-rule->str (StringBuilder.) [:p {}])))) (is (= "p {\n font-weight: bold;\n}\n" (str (css-rule->str (StringBuilder.) [:p {:font-weight "bold"}])))) - (is (= "p {\n font-weight: bold;\n color: #000;\n}\n" + (is (= "p {\n color: #000;\n font-weight: bold;\n}\n" (str (css-rule->str (StringBuilder.) [:p {:font-weight "bold" :color "#000"}])))) - (is (= "@page {\n size: 8.5in 11in;\n margin: 10%;\n @top-right {\n content: \"Page \" counter(page);\n }\n @top-left {\n content: \"Foobar\";\n border: solid red;\n }\n}\n" + (is (= "@page {\n margin: 10%;\n size: 8.5in 11in;\n @top-right {\n content: \"Page \" counter(page);\n }\n @top-left {\n border: solid red;\n content: \"Foobar\";\n }\n}\n" (str (css-rule->str (StringBuilder.) ["@page" @@ -91,7 +91,7 @@ :color "black"}] [:p {:font-size "12pt"}]]))) - (is (= "body {\n background-color: white;\n color: black;\n}\n@page {\n size: 8.5in 11in;\n margin: 10%;\n @top-right {\n content: \"Page \" counter(page);\n }\n @top-left {\n content: \"Foobar\";\n border: solid red;\n }\n}\n" + (is (= "body {\n background-color: white;\n color: black;\n}\n@page {\n margin: 10%;\n size: 8.5in 11in;\n @top-right {\n content: \"Page \" counter(page);\n }\n @top-left {\n border: solid red;\n content: \"Foobar\";\n }\n}\n" (css->str [[:body {:background-color "white"