Skip to content

Commit

Permalink
feat: unit tests for numbering
Browse files Browse the repository at this point in the history
  • Loading branch information
erdos committed Nov 1, 2020
1 parent a8e12f2 commit c4ab6e7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/stencil/model/numbering.clj
Expand Up @@ -50,17 +50,21 @@


(defn- xml-lvl-parse [tree]
(assert (= ooxml/tag-lvl (:tag tree)))
(letfn [(node-attr [tag] (-> tree (find-node (comp #{tag} name :tag)) :attrs ooxml/val))]
{:lvl-text (node-attr "lvlText")
:num-fmt (node-attr "numFmt")
:start (->int (node-attr "start"))}))


(defn prepare-numbering-xml [xml-tree] xml-tree)


(defn- parse [numbering-file]
(assert numbering-file)
(with-open [r (io/input-stream (io/file numbering-file))]
(let [tree (xml/parse r)]
tree)))
(prepare-numbering-xml tree))))


(defn main-numbering [dir main-document main-document-rels]
Expand All @@ -77,6 +81,6 @@
(defn style-def-for [id lvl]
(assert (string? id))
(assert (integer? lvl))
(-> (:parsed *numbering*)
(get-id-style-xml id lvl)
(xml-lvl-parse)))
(some-> (:parsed *numbering*)
(get-id-style-xml id lvl)
(xml-lvl-parse)))
49 changes: 49 additions & 0 deletions test/stencil/model/numbering_test.clj
@@ -0,0 +1,49 @@
(ns stencil.model.numbering-test
(:require [stencil.model.numbering :refer :all]
[stencil.ooxml :as ooxml]
[clojure.test :refer [deftest testing is are]]))

(defn hiccup [body]
(assert (vector? body))
(let [[tag attrs & children]
(if (map? (second body)) body (list* (first body) {} (next body)))]
{:tag tag, :attrs attrs, :content (mapv hiccup children)}))

(deftest test-style-for-def-empty
(binding [*numbering* {:parsed (prepare-numbering-xml {:tag :numbering :content []})}]
(is (= nil (style-def-for "id-1" 2)))))

(deftest test-style-for-def-with-abstract
(binding [*numbering*
{:parsed
(prepare-numbering-xml
(hiccup
[:numbering
[ooxml/tag-abstract-num {ooxml/xml-abstract-num-id "a1"}
[ooxml/tag-lvl {ooxml/attr-ilvl "2"}
[:start {ooxml/val "1"}]
[:numFmt {ooxml/val "none"}]
[:suff {ooxml/val "nothing"}]
[:lvlText {ooxml/val ""}]
[:lvlJc {ooxml/val "start"}]]]
[ooxml/tag-num {ooxml/attr-numId "id-1"}
[ooxml/xml-abstract-num-id {ooxml/val "a1"}]]]))}]
(is (= {:lvl-text "", :num-fmt "none", :start 1}
(style-def-for "id-1" 2)))))


(deftest test-style-for-def
(binding [*numbering*
{:parsed
(prepare-numbering-xml
(hiccup
[:numbering
[ooxml/tag-num {ooxml/attr-numId "id-1"}
[ooxml/tag-lvl {ooxml/attr-ilvl "2"}
[:start {ooxml/val "1"}]
[:numFmt {ooxml/val "none"}]
[:suff {ooxml/val "nothing"}]
[:lvlText {ooxml/val ""}]
[:lvlJc {ooxml/val "start"}]]]]))}]
(is (= {:lvl-text "", :num-fmt "none", :start 1}
(style-def-for "id-1" 2)))))

0 comments on commit c4ab6e7

Please sign in to comment.