all things implemented - probably works

This commit is contained in:
Michael Jerger 2017-02-08 20:09:01 +01:00
parent e9d1c1e194
commit 439ae6fba8
2 changed files with 64 additions and 22 deletions

View file

@ -2,11 +2,21 @@
(:require
[clojure.string :as s]))
(defn- uri-level [uri]
(count (s/split uri #"/")))
(defn uri-level [uri]
(- (count
(s/split uri #"/"))
1)
)
(defn- filter-pages-for-uri [uri pages]
(filter #(s/starts-with? (:uri %) uri) pages))
(defn filter-pages-for-uri [uri pages]
(let [html? (s/ends-with? uri ".html")
clean? (s/ends-with? uri "/")
clean-uri (cond
html? (subs uri 0 (- (count uri) 5))
clean? (subs uri 0 (- (count uri) 1))
:default uri)]
(filter #(s/starts-with? (:uri %) clean-uri) pages))
)
(defn build-nav-map-level
"builds one level of nav-map and recurs to next level."

View file

@ -14,17 +14,38 @@
:page-index page-index
:children children})
(deftest test-navmap-pages
(testing
"No pages or posts nothing to copy"
(let [pages [(page "/pages/nav1/" 0)
(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)
]
expected [(enhanced-page
])
(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)
])
(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))))
))
(deftest test-navmap-pages
(testing
"No pages or posts nothing to copy"
(let [expected-clean [(enhanced-page
"/pages/nav1/" 0
[(enhanced-page
"/pages/nav1/nav11/" 1
@ -33,8 +54,19 @@
(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)]
)]
]
(is (= expected
(sut/build-nav-map pages)))
(is (= expected-clean
(sut/build-nav-map pages-clean)))
(is (= expected-dirty
(sut/build-nav-map pages-dirty)))
)
))