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-03-22 07:05:36 +00:00
|
|
|
|
|
|
|
(deftest test-normalized-page-root-uri
|
|
|
|
(testing
|
|
|
|
(is (= "" (sut/normalized-page-root-uri "")))
|
|
|
|
(is (= "/root/" (sut/normalized-page-root-uri "root")))
|
|
|
|
(is (= "/root/" (sut/normalized-page-root-uri "/root")))
|
|
|
|
(is (= "/root/" (sut/normalized-page-root-uri "root/")))
|
|
|
|
(is (= "/root/" (sut/normalized-page-root-uri "/root/")))
|
|
|
|
))
|
2017-02-08 19:09:01 +00:00
|
|
|
|
2017-03-22 07:05:36 +00:00
|
|
|
(deftest test-uri-level
|
|
|
|
(testing
|
|
|
|
(is (= 2 (sut/uri-level "/pages/nav1/")))
|
|
|
|
(is (= 2 (sut/uri-level "/pages/nav1.html")))
|
|
|
|
))
|
|
|
|
|
|
|
|
(def pages-clean-1 [(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 expected-clean-1 [(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)]
|
|
|
|
)])
|
2017-02-08 19:09:01 +00:00
|
|
|
|
|
|
|
(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-03-22 07:05:36 +00:00
|
|
|
(def 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)]
|
|
|
|
)])
|
|
|
|
|
|
|
|
(def pages-clean-2 [(page "/pages/1/" 0)
|
|
|
|
(page "/pages/2/" 1)
|
|
|
|
(page "/pages/2/22/" 0)])
|
|
|
|
|
|
|
|
(def expected-clean-2 [(page "/pages/1/" 0)
|
|
|
|
(enhanced-page
|
|
|
|
"/pages/2/" 1
|
|
|
|
[(page "/pages/2/22/" 0)])])
|
|
|
|
|
|
|
|
(def pages-clean-3 [(page "/1/" 0)
|
|
|
|
(page "/2/" 1)
|
|
|
|
(page "/2/22/" 0)])
|
|
|
|
|
|
|
|
(def expected-clean-3 [(page "/1/" 0)
|
|
|
|
(enhanced-page
|
|
|
|
"/2/" 1
|
|
|
|
[(page "/2/22/" 0)])])
|
2017-02-08 19:09:01 +00:00
|
|
|
|
2017-02-09 07:52:42 +00:00
|
|
|
(deftest test-hierarchic-pages
|
2017-02-08 18:22:15 +00:00
|
|
|
(testing
|
2017-03-22 07:05:36 +00:00
|
|
|
"hierarchic expectations"
|
|
|
|
(is (= expected-clean-1
|
|
|
|
(sut/build-hierarchic-map "pages" pages-clean-1)))
|
2017-02-08 19:09:01 +00:00
|
|
|
(is (= expected-dirty
|
2017-03-22 07:05:36 +00:00
|
|
|
(sut/build-hierarchic-map "pages" pages-dirty)))
|
|
|
|
(is (= expected-clean-2
|
|
|
|
(sut/build-hierarchic-map "pages" pages-clean-2)))
|
|
|
|
(is (= expected-clean-3
|
|
|
|
(sut/build-hierarchic-map "" pages-clean-3)))
|
2017-02-08 18:22:15 +00:00
|
|
|
)
|
2017-03-22 07:05:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
(deftest test-filter-pages-for-uri
|
|
|
|
(testing
|
|
|
|
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1/" pages-clean-1))))
|
|
|
|
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1.html" pages-dirty))))
|
|
|
|
))
|