2024-01-08 02:15:22 +01:00
|
|
|
;; 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/>.
|
|
|
|
|
2024-01-05 14:31:44 +01:00
|
|
|
(ns rss-thread-watch.utils-test
|
|
|
|
(:require [clojure.test :refer :all]
|
|
|
|
[rss-thread-watch.utils :refer :all]))
|
|
|
|
|
2024-01-08 03:01:42 +01:00
|
|
|
(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}})
|
|
|
|
|
2024-01-06 06:05:21 +01:00
|
|
|
(def empty-map {})
|
2024-01-05 14:31:44 +01:00
|
|
|
|
2024-01-08 03:22:50 +01:00
|
|
|
(deftest map-apply-defaults-test
|
2024-01-08 03:01:42 +01:00
|
|
|
(testing "Full and no-replace"
|
2024-01-06 06:05:21 +01:00
|
|
|
(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))
|
2024-01-08 03:01:42 +01:00
|
|
|
"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)))))
|
2024-01-08 03:29:53 +01:00
|
|
|
|
|
|
|
(deftest fmap-test
|
|
|
|
(testing "Applying function to values of map"
|
|
|
|
(is (= {:a 2 :b 3} (fmap (fn [k v] (inc v))
|
|
|
|
{:a 1 :b 2})))))
|