rss-thread-watcher/test/rss_thread_watch/utils_test.clj

62 lines
2.4 KiB
Clojure

;; Copyright (C) 2023 Felisp
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as published by
;; the Free Software Foundation, version 3 of the License.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(ns rss-thread-watch.utils-test
(:require [clojure.test :refer :all]
[rss-thread-watch.utils :refer :all]))
(def first-map
"Example config map with two keys"
{:a :b
:c "c"
:nested {:fst 1 :scnd {:super :nested}}})
(def pony-map
"Map containing none of the items in map 1"
{:best-pony "Twilight Sparkle"})
(def conflicting-basic-merge (conj pony-map {:a 17 :c 15}))
(def deep-pony-map {:a "x"
:c :something-else
:nested {:ponies "everywhere"
:fst 69}})
(def empty-map {})
(deftest map-deep-merge-missing-test
(testing "Full and no-replace"
(is (= first-map (map-apply-defaults first-map empty-map))
"No defaults should return conf map unchanged")
(is (= first-map (map-apply-defaults empty-map first-map))
"Empty map should be completely replaced by defaults"))
(testing "Basic merge"
(is (= (conj pony-map first-map) (map-apply-defaults first-map pony-map))
"When all keys unique, maps should be conjd")
(is (= (conj first-map pony-map) (map-apply-defaults first-map pony-map))
"When all keys unique, maps should be conjd, order matters")
(is (= (conj first-map pony-map) (map-apply-defaults pony-map first-map))
"When all keys unique, maps should be conjd, more order that matters")
(is (= (conj first-map pony-map) (map-apply-defaults first-map pony-map))
"Conflicting basic merge"))
;; Most important part, this is the reason we have the function in the first place
;; Conj wont merge deep
(testing "Nested merge"
(is (= {:a :b
:c "c"
:nested {:ponies "everywhere"
:fst 1
:scnd {:super :nested}}}
(map-apply-defaults first-map deep-pony-map)))))