2017-02-09 07:52:42 +00:00
|
|
|
(ns cryogen-core.hierarchic-test
|
2017-02-08 18:22:15 +00:00
|
|
|
(:require
|
|
|
|
[clojure.test :refer :all]
|
2017-02-09 07:52:42 +00:00
|
|
|
[cryogen-core.hierarchic :as sut]))
|
2017-02-08 18:22:15 +00:00
|
|
|
|
|
|
|
(defn- page [uri page-index]
|
|
|
|
{:uri uri
|
|
|
|
:content uri
|
|
|
|
:page-index page-index})
|
|
|
|
|
|
|
|
(defn- enhanced-page [uri page-index children]
|
|
|
|
{:uri uri
|
|
|
|
:content uri
|
|
|
|
:page-index page-index
|
|
|
|
:children children})
|
2017-02-08 19:09:01 +00:00
|
|
|
|
|
|
|
(def pages-clean [(page "/pages/nav1/" 0)
|
|
|
|
(page "/pages/nav1/nav11/" 1)
|
|
|
|
(page "/pages/nav1/nav13/" 3)
|
|
|
|
(page "/pages/nav1/nav11/nav112/" 2)
|
|
|
|
(page "/pages/nav1/nav12/" 2)
|
|
|
|
(page "/pages/nav1/nav11/xnav111/" 1)
|
|
|
|
])
|
|
|
|
|
|
|
|
(def pages-dirty [(page "/pages/nav1.html" 0)
|
|
|
|
(page "/pages/nav1/nav11.html" 1)
|
|
|
|
(page "/pages/nav1/nav13.html" 3)
|
|
|
|
(page "/pages/nav1/nav11/nav112.html" 2)
|
|
|
|
(page "/pages/nav1/nav12.html" 2)
|
|
|
|
(page "/pages/nav1/nav11/xnav111.html" 1)
|
|
|
|
])
|
2017-02-08 18:22:15 +00:00
|
|
|
|
2017-02-08 19:09:01 +00:00
|
|
|
(deftest test-uri-level
|
|
|
|
(testing
|
|
|
|
(is (= 2 (sut/uri-level "/pages/nav1/")))
|
|
|
|
(is (= 2 (sut/uri-level "/pages/nav1.html")))
|
|
|
|
))
|
|
|
|
|
|
|
|
(deftest test-filter-pages-for-uri
|
|
|
|
(testing
|
|
|
|
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1/" pages-clean))))
|
|
|
|
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1.html" pages-dirty))))
|
|
|
|
))
|
|
|
|
|
2017-02-09 07:52:42 +00:00
|
|
|
(deftest test-hierarchic-pages
|
2017-02-08 18:22:15 +00:00
|
|
|
(testing
|
|
|
|
"No pages or posts nothing to copy"
|
2017-02-08 19:09:01 +00:00
|
|
|
(let [expected-clean [(enhanced-page
|
|
|
|
"/pages/nav1/" 0
|
|
|
|
[(enhanced-page
|
|
|
|
"/pages/nav1/nav11/" 1
|
|
|
|
[(page "/pages/nav1/nav11/xnav111/" 1)
|
|
|
|
(page "/pages/nav1/nav11/nav112/" 2)])
|
|
|
|
(page "/pages/nav1/nav12/" 2)
|
|
|
|
(page "/pages/nav1/nav13/" 3)]
|
|
|
|
)]
|
|
|
|
expected-dirty [(enhanced-page
|
|
|
|
"/pages/nav1.html" 0
|
|
|
|
[(enhanced-page
|
|
|
|
"/pages/nav1/nav11.html" 1
|
|
|
|
[(page "/pages/nav1/nav11/xnav111.html" 1)
|
|
|
|
(page "/pages/nav1/nav11/nav112.html" 2)])
|
|
|
|
(page "/pages/nav1/nav12.html" 2)
|
|
|
|
(page "/pages/nav1/nav13.html" 3)]
|
|
|
|
)]
|
2017-02-08 18:22:15 +00:00
|
|
|
]
|
2017-02-08 19:09:01 +00:00
|
|
|
(is (= expected-clean
|
2017-02-09 07:52:42 +00:00
|
|
|
(sut/build-hierarchic-map pages-clean)))
|
2017-02-08 19:09:01 +00:00
|
|
|
(is (= expected-dirty
|
2017-02-09 07:52:42 +00:00
|
|
|
(sut/build-hierarchic-map pages-dirty)))
|
2017-02-08 18:22:15 +00:00
|
|
|
)
|
|
|
|
))
|