diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index 2e9cb66..f1930be 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -1 +1,2 @@ -{:output {:progress true}} +{:output {:progress true} + :lint-as {luciolucio.holi.test-setup/defcalendartest clojure.test/deftest}} diff --git a/Makefile b/Makefile index f954c5d..1a0cc49 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ SRC_AND_TEST := src test clean: ## Clean up CP cache and generated files clean-prepare: ## Clean up files changed via prepare.sh test: ## Run tests +repl: ## Start a REPL test-cljs: ## Run cljs tests repl-cljs: ## Start a ClojureScript REPL perftest: ## Run performance tests @@ -57,6 +58,9 @@ test: gen-holidays # Holidays are needed so that `luciolucio.holi.core/holiday-d yarn-install: @yarn install +repl: gen-holidays + @clojure -M:dev:test:repl + test-cljs: yarn-install gen-holidays # Holidays are needed so that `luciolucio.holi.core/holiday-datelists` can load, but are not used in tests @clojure -M:test:shadow-cljs compile test @node out/tests.js diff --git a/deps.edn b/deps.edn index 78e501b..07ddc70 100644 --- a/deps.edn +++ b/deps.edn @@ -1,22 +1,25 @@ {:paths ["src" "resources"] :deps {org.clojure/clojure {:mvn/version "1.11.1"} - instaparse/instaparse {:mvn/version "1.4.12"} - tick/tick {:mvn/version "0.7.5"} + instaparse/instaparse {:mvn/version "1.5.0"} + tick/tick {:mvn/version "1.0"} easter-day/easter-day {:mvn/version "0.1.1"}} - :aliases {:test {:extra-paths ["test" "test-resources"] - :extra-deps {lambdaisland/kaocha {:mvn/version "1.87.1366"} + :aliases {:dev {:extra-paths ["dev"]} + :test {:extra-paths ["test" "test-resources"] + :extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"} criterium/criterium {:mvn/version "0.4.6"}}} - + :repl {:extra-deps {nrepl/nrepl {:mvn/version "1.3.0"} + cider/cider-nrepl {:mvn/version "0.50.2"}} + :main-opts ["-m" "nrepl.cmdline" "--interactive" "--middleware" "[\"cider.nrepl/cider-middleware\"]"]} :cljfmt {:main-opts ["-m" "cljfmt.main"] - :extra-deps {dev.weavejester/cljfmt {:mvn/version "0.11.2"}}} + :extra-deps {dev.weavejester/cljfmt {:mvn/version "0.13.0"}}} :lint {:main-opts ["-m" "clj-kondo.main" "--lint"] - :extra-deps {clj-kondo/clj-kondo {:mvn/version "2023.10.20"}}} + :extra-deps {clj-kondo/clj-kondo {:mvn/version "2024.09.27"}}} - :build {:extra-deps {io.github.clojure/tools.build {:git/tag "v0.9.6" :git/sha "8e78bcc"}} + :build {:extra-deps {io.github.clojure/tools.build {:git/tag "v0.10.5" :git/sha "2a21b7a"}} :ns-default build} - :shadow-cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.26.2"}} + :shadow-cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.28.19"}} :main-opts ["-m" "shadow.cljs.devtools.cli"]} :generate {:main-opts ["-m" "luciolucio.holi.generate"]}}} diff --git a/test/luciolucio/holi/add_test/business_days_calendar_test.cljc b/test/luciolucio/holi/add_test/business_days_calendar_test.cljc index bcfc950..185e4c6 100644 --- a/test/luciolucio/holi/add_test/business_days_calendar_test.cljc +++ b/test/luciolucio/holi/add_test/business_days_calendar_test.cljc @@ -1,13 +1,11 @@ (ns luciolucio.holi.add-test.business-days-calendar-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t]) #?(:clj (:import (clojure.lang ExceptionInfo)))) -(ct/use-fixtures :each setup/test-datelist-fixture) - (defn- ->d [s] (t/date s)) (defn- ->dt [s] (t/date-time (str s "T11:11:00"))) @@ -22,7 +20,7 @@ ; date-time + fri-sat (= (->dt expected-fri-sat) (holi/add (->dt date) days :business-days :fri-sat "DAY-THREE")))) -(ct/deftest should-calculate-correct-date-when-add-with-business-days-calendar +(defcalendartest should-calculate-correct-date-when-add-with-business-days-calendar (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-07-30" days expected-sat-sun expected-fri-sat) 2 "2020-08-04" "2020-08-04" @@ -30,7 +28,7 @@ 5 "2020-08-07" "2020-08-09" -5 "2020-07-23" "2020-07-23")) -(ct/deftest should-calculate-correct-date-when-add-friday-with-business-days-calendar +(defcalendartest should-calculate-correct-date-when-add-friday-with-business-days-calendar (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-07-31" days expected-sat-sun expected-fri-sat) 1 "2020-08-04" "2020-08-02" @@ -38,7 +36,7 @@ -1 "2020-07-30" "2020-07-30" -5 "2020-07-24" "2020-07-26")) -(ct/deftest should-calculate-correct-date-when-add-saturday-with-business-days-calendar +(defcalendartest should-calculate-correct-date-when-add-saturday-with-business-days-calendar (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-08-01" days expected-sat-sun expected-fri-sat) 1 "2020-08-04" "2020-08-02" @@ -46,7 +44,7 @@ -1 "2020-07-31" "2020-07-30" -5 "2020-07-27" "2020-07-26")) -(ct/deftest should-calculate-correct-date-when-add-sunday-with-business-days-calendar +(defcalendartest should-calculate-correct-date-when-add-sunday-with-business-days-calendar (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-08-02" days expected-sat-sun expected-fri-sat) 1 "2020-08-04" "2020-08-04" @@ -54,7 +52,7 @@ -1 "2020-07-31" "2020-07-30" -5 "2020-07-27" "2020-07-26")) -(ct/deftest should-go-to-next-business-day-or-stay-when-add-zero-days-with-business-days-calendar +(defcalendartest should-go-to-next-business-day-or-stay-when-add-zero-days-with-business-days-calendar (ct/are [date expected-sat-sun expected-fri-sat] (all-cases-pass? date 0 expected-sat-sun expected-fri-sat) "2020-07-31" "2020-07-31" "2020-08-02" @@ -63,7 +61,7 @@ "2020-08-03" "2020-08-04" "2020-08-04" "2020-08-04" "2020-08-04" "2020-08-04")) -(ct/deftest should-calculate-correct-date-when-add-with-holiday-coinciding-with-weekend +(defcalendartest should-calculate-correct-date-when-add-with-holiday-coinciding-with-weekend (ct/testing "date" (ct/testing "sat-sun" (ct/is (= (->d "2020-01-22") (holi/add (->d "2020-01-18") 3 :business-days :sat-sun "HOLIDAY-ON-SAT-SUN-WEEKEND")))) @@ -75,7 +73,7 @@ (ct/testing "fri-sat" (ct/is (= (->dt "2020-01-21") (holi/add (->dt "2020-01-17") 3 :business-days :fri-sat "HOLIDAY-ON-FRI-SAT-WEEKEND")))))) -(ct/deftest +(defcalendartest ^{:doc "This test relies on DAY-THREE.datelist, in which 3Aug20 is a holiday. Any result outside 2020 should raise an exception"} should-throw-when-add-with-business-days-calendar-and-result-beyond-limit-years diff --git a/test/luciolucio/holi/add_test/business_days_default_weekend_option_test.cljc b/test/luciolucio/holi/add_test/business_days_default_weekend_option_test.cljc index 89b6ad3..bc6a59b 100644 --- a/test/luciolucio/holi/add_test/business_days_default_weekend_option_test.cljc +++ b/test/luciolucio/holi/add_test/business_days_default_weekend_option_test.cljc @@ -1,12 +1,10 @@ (ns luciolucio.holi.add-test.business-days-default-weekend-option-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t])) -(ct/use-fixtures :each setup/test-datelist-fixture) - -(ct/deftest should-default-weekend-option-to-sat-sun-when-add-with-no-weekend-option +(defcalendartest should-default-weekend-option-to-sat-sun-when-add-with-no-weekend-option (ct/testing "date" (ct/testing "[date n unit]" (ct/is (= (holi/add (t/date "2020-07-30") 3 :business-days) diff --git a/test/luciolucio/holi/add_test/business_days_inexistent_calendar_test.cljc b/test/luciolucio/holi/add_test/business_days_inexistent_calendar_test.cljc index 2906133..ff93262 100644 --- a/test/luciolucio/holi/add_test/business_days_inexistent_calendar_test.cljc +++ b/test/luciolucio/holi/add_test/business_days_inexistent_calendar_test.cljc @@ -1,14 +1,12 @@ (ns luciolucio.holi.add-test.business-days-inexistent-calendar-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t]) #?(:clj (:import (clojure.lang ExceptionInfo)))) -(ct/use-fixtures :each setup/test-datelist-fixture) - -(ct/deftest should-throw-when-add-date-with-inexistent-calendar-or-starting-with-WEEKEND +(defcalendartest should-throw-when-add-date-with-inexistent-calendar-or-starting-with-WEEKEND (ct/testing "date" (ct/testing "[date n unit calendar]" (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): X" (holi/add (t/date "2020-08-03") 1 :business-days "X")))) diff --git a/test/luciolucio/holi/add_test/business_days_multi_calendar_test.cljc b/test/luciolucio/holi/add_test/business_days_multi_calendar_test.cljc index 99901d8..f7d349c 100644 --- a/test/luciolucio/holi/add_test/business_days_multi_calendar_test.cljc +++ b/test/luciolucio/holi/add_test/business_days_multi_calendar_test.cljc @@ -1,13 +1,11 @@ (ns luciolucio.holi.add-test.business-days-multi-calendar-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t]) #?(:clj (:import (clojure.lang ExceptionInfo)))) -(ct/use-fixtures :each setup/test-datelist-fixture) - (defn- ->d [s] (t/date s)) (defn- ->dt [s] (t/date-time (str s "T11:11:00"))) @@ -22,7 +20,7 @@ ; date-time + fri-sat (= (->dt expected-fri-sat) (holi/add (->dt date) days :business-days :fri-sat "DAY-THREE" "DAY-TWENTY-NINE")))) -(ct/deftest should-calculate-correct-date-when-add-with-business-days-multi-calendar +(defcalendartest should-calculate-correct-date-when-add-with-business-days-multi-calendar (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-07-30" days expected-sat-sun expected-fri-sat) 2 "2020-08-04" "2020-08-04" @@ -30,7 +28,7 @@ 5 "2020-08-07" "2020-08-09" -5 "2020-07-22" "2020-07-22")) -(ct/deftest should-calculate-correct-date-when-add-friday-with-business-days-multi-calendar +(defcalendartest should-calculate-correct-date-when-add-friday-with-business-days-multi-calendar (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-07-31" days expected-sat-sun expected-fri-sat) 2 "2020-08-05" "2020-08-04" @@ -38,7 +36,7 @@ 7 "2020-08-12" "2020-08-11" -5 "2020-07-23" "2020-07-23")) -(ct/deftest should-calculate-correct-date-when-add-saturday-with-business-days-multi-calendar +(defcalendartest should-calculate-correct-date-when-add-saturday-with-business-days-multi-calendar (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-08-01" days expected-sat-sun expected-fri-sat) 1 "2020-08-04" "2020-08-02" @@ -46,14 +44,14 @@ -1 "2020-07-31" "2020-07-30" -5 "2020-07-24" "2020-07-23")) -(ct/deftest should-calculate-correct-date-when-add-sunday-with-business-days-multi-calendar +(defcalendartest should-calculate-correct-date-when-add-sunday-with-business-days-multi-calendar (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-08-02" days expected-sat-sun expected-fri-sat) 1 "2020-08-04" "2020-08-04" -1 "2020-07-31" "2020-07-30" -5 "2020-07-24" "2020-07-23")) -(ct/deftest should-go-to-next-business-day-or-stay-when-add-zero-days-with-business-days-multi-calendar +(defcalendartest should-go-to-next-business-day-or-stay-when-add-zero-days-with-business-days-multi-calendar (ct/are [start-date expected-sat-sun expected-fri-sat] (all-cases-pass? start-date 0 expected-sat-sun expected-fri-sat) "2020-07-28" "2020-07-28" "2020-07-28" @@ -65,7 +63,7 @@ "2020-08-03" "2020-08-04" "2020-08-04" "2020-08-04" "2020-08-04" "2020-08-04")) -(ct/deftest +(defcalendartest ^{:doc "This test relies on datelists DAY-THREE and DAY-TWENTY-NINE-2021, which list 3Aug20 and 29Jul21 as holidays, respectively. Any result before 2020 or after 2021 should raise an exception"} should-throw-when-add-date-with-business-days-multi-calendar-and-result-beyond-limit-years diff --git a/test/luciolucio/holi/add_test/business_days_no_calendar_test.cljc b/test/luciolucio/holi/add_test/business_days_no_calendar_test.cljc index 0d825da..ccbb75f 100644 --- a/test/luciolucio/holi/add_test/business_days_no_calendar_test.cljc +++ b/test/luciolucio/holi/add_test/business_days_no_calendar_test.cljc @@ -1,13 +1,11 @@ (ns luciolucio.holi.add-test.business-days-no-calendar-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t]) #?(:clj (:import (clojure.lang ExceptionInfo)))) -(ct/use-fixtures :each setup/test-datelist-fixture) - (defn- ->d [s] (t/date s)) (defn- ->dt [s] (t/date-time (str s "T11:11:00"))) @@ -22,14 +20,14 @@ ; date-time + fri-sat (= (->dt expected-fri-sat) (holi/add (->dt date) days :business-days :fri-sat)))) -(ct/deftest should-calculate-correct-date-when-add-with-business-days +(defcalendartest should-calculate-correct-date-when-add-with-business-days (ct/are [date days expected-sat-sun expected-fri-sat] (all-cases-pass? date days expected-sat-sun expected-fri-sat) "2020-07-30" 1 "2020-07-31" "2020-08-02" "2020-07-30" 2 "2020-08-03" "2020-08-03" "2020-07-29" -3 "2020-07-24" "2020-07-26")) -(ct/deftest should-calculate-correct-date-when-add-friday-with-business-days +(defcalendartest should-calculate-correct-date-when-add-friday-with-business-days (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-07-31" days expected-sat-sun expected-fri-sat) 1 "2020-08-03" "2020-08-02" @@ -37,7 +35,7 @@ -1 "2020-07-30" "2020-07-30" -5 "2020-07-24" "2020-07-26")) -(ct/deftest should-calculate-correct-date-when-add-saturday-with-business-days +(defcalendartest should-calculate-correct-date-when-add-saturday-with-business-days (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-08-01" days expected-sat-sun expected-fri-sat) 1 "2020-08-03" "2020-08-02" @@ -45,7 +43,7 @@ -1 "2020-07-31" "2020-07-30" -5 "2020-07-27" "2020-07-26")) -(ct/deftest should-calculate-correct-date-when-add-sunday-with-business-days +(defcalendartest should-calculate-correct-date-when-add-sunday-with-business-days (ct/are [days expected-sat-sun expected-fri-sat] (all-cases-pass? "2020-08-02" days expected-sat-sun expected-fri-sat) 1 "2020-08-03" "2020-08-03" @@ -53,7 +51,7 @@ -1 "2020-07-31" "2020-07-30" -5 "2020-07-27" "2020-07-26")) -(ct/deftest should-go-to-next-business-day-or-stay-when-add-zero-days-with-business-days +(defcalendartest should-go-to-next-business-day-or-stay-when-add-zero-days-with-business-days (ct/are [start-date expected-sat-sun expected-fri-sat] (all-cases-pass? start-date 0 expected-sat-sun expected-fri-sat) "2020-07-30" "2020-07-30" "2020-07-30" @@ -62,7 +60,7 @@ "2020-08-02" "2020-08-03" "2020-08-02" "2020-08-03" "2020-08-03" "2020-08-03")) -(ct/deftest +(defcalendartest ^{:doc "This test relies on TEST-WEEKEND-SAT-SUN and TEST-WEEKEND-FRI-SAT, which list weekends in 2020. Any result outside 2020 should raise an exception"} should-throw-when-add-date-with-business-days-and-result-beyond-limit-years diff --git a/test/luciolucio/holi/add_test/business_days_vs_business_day_equivalence_test.cljc b/test/luciolucio/holi/add_test/business_days_vs_business_day_equivalence_test.cljc index 8083d32..82b4aaa 100644 --- a/test/luciolucio/holi/add_test/business_days_vs_business_day_equivalence_test.cljc +++ b/test/luciolucio/holi/add_test/business_days_vs_business_day_equivalence_test.cljc @@ -1,12 +1,10 @@ (ns luciolucio.holi.add-test.business-days-vs-business-day-equivalence-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t])) -(ct/use-fixtures :each setup/test-datelist-fixture) - -(ct/deftest should-calculate-the-same-result-when-add-with-business-days-or-business-day +(defcalendartest should-calculate-the-same-result-when-add-with-business-days-or-business-day (ct/testing "date" (ct/testing "[date n unit]" (ct/is (= (holi/add (t/date "2020-07-30") 3 :business-days) diff --git a/test/luciolucio/holi/holidays_in_date_test.cljc b/test/luciolucio/holi/holidays_in_date_test.cljc index 3febc94..b590db6 100644 --- a/test/luciolucio/holi/holidays_in_date_test.cljc +++ b/test/luciolucio/holi/holidays_in_date_test.cljc @@ -1,14 +1,12 @@ (ns luciolucio.holi.holidays-in-date-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t]) #?(:clj (:import (clojure.lang ExceptionInfo)))) -(ct/use-fixtures :each setup/test-datelist-fixture) - -(ct/deftest should-return-holidays-when-holidays-in-date-with-date +(defcalendartest should-return-holidays-when-holidays-in-date-with-date (ct/are [date calendar expected] (= expected (holi/holidays-in-date (t/date date) calendar)) "2020-08-01" "DAY-TWENTY-NINE" [] @@ -16,7 +14,7 @@ "2020-07-30" "DAY-THREE" [] "2020-08-03" "DAY-THREE" ["Third Day"])) -(ct/deftest should-return-holidays-when-holidays-in-date-with-date-time +(defcalendartest should-return-holidays-when-holidays-in-date-with-date-time (ct/are [date calendar expected] (= expected (holi/holidays-in-date (t/date-time date) calendar)) "2020-08-01T00:00:00" "DAY-TWENTY-NINE" [] @@ -24,7 +22,7 @@ "2020-07-30T22:22:22" "DAY-THREE" [] "2020-08-03T00:33:33" "DAY-THREE" ["Third Day"])) -(ct/deftest +(defcalendartest ^{:doc "This test relies on TEST-WEEKEND and DAY-THREE, which only list dates in 2020. Any argument outside 2020 should raise an exception"} should-throw-when-holidays-in-date-with-date-beyond-limit-year @@ -33,7 +31,7 @@ "2021-08-03" "DAY-THREE" "2019-08-03" "DAY-THREE")) -(ct/deftest +(defcalendartest ^{:doc "This test relies on TEST-WEEKEND and DAY-THREE, which only list dates in 2020. Any argument outside 2020 should raise an exception"} should-throw-when-holidays-in-date-with-date-time-beyond-limit-year @@ -42,7 +40,7 @@ "2021-08-03T10:10:10" "DAY-THREE" "2019-08-03T23:59:59" "DAY-THREE")) -(ct/deftest should-throw-when-holidays-in-date-with-inexistent-calendar-or-starting-with-WEEKEND +(defcalendartest should-throw-when-holidays-in-date-with-inexistent-calendar-or-starting-with-WEEKEND (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): HOL" (holi/holidays-in-date (t/date "2020-10-10") "HOL"))) (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): WEEKEND" (holi/holidays-in-date (t/date "2020-10-10") "WEEKEND"))) (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): WEEKENDO" (holi/holidays-in-date (t/date "2020-10-10") "WEEKENDO"))) diff --git a/test/luciolucio/holi/holidays_in_year_test.cljc b/test/luciolucio/holi/holidays_in_year_test.cljc index 8252cad..a1e01bb 100644 --- a/test/luciolucio/holi/holidays_in_year_test.cljc +++ b/test/luciolucio/holi/holidays_in_year_test.cljc @@ -1,14 +1,12 @@ (ns luciolucio.holi.holidays-in-year-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t]) #?(:clj (:import (clojure.lang ExceptionInfo)))) -(ct/use-fixtures :each setup/test-datelist-fixture) - -(ct/deftest should-list-the-correct-holidays-for-calendar-and-year-when-holidays-in-year +(defcalendartest should-list-the-correct-holidays-for-calendar-and-year-when-holidays-in-year (ct/are [year expected] (= expected (holi/holidays-in-year year "TEST-US")) 2021 [{:date (t/date "2021-01-01") :name "New Year's Day"} @@ -59,11 +57,11 @@ {:date (t/date "2024-11-28") :name "Thanksgiving"} {:date (t/date "2024-12-25") :name "Christmas"}])) -(ct/deftest should-throw-when-holidays-in-year-with-year-beyond-limits +(defcalendartest should-throw-when-holidays-in-year-with-year-beyond-limits (ct/is (thrown-with-msg? ExceptionInfo #"Year is out of bounds" (holi/holidays-in-year 1942 "TEST-US"))) (ct/is (thrown-with-msg? ExceptionInfo #"Year is out of bounds" (holi/holidays-in-year 2104 "TEST-US")))) -(ct/deftest +(defcalendartest ^{:doc "These should say 'Unknown calendar(s)' before checking that the year is out of bounds"} should-throw-when-holidays-in-year-with-inexistent-calendar-or-starting-with-WEEKEND diff --git a/test/luciolucio/holi/is_business_day_test.cljc b/test/luciolucio/holi/is_business_day_test.cljc index 3d14042..abdf8ba 100644 --- a/test/luciolucio/holi/is_business_day_test.cljc +++ b/test/luciolucio/holi/is_business_day_test.cljc @@ -1,14 +1,12 @@ (ns luciolucio.holi.is-business-day-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t]) #?(:clj (:import (clojure.lang ExceptionInfo)))) -(ct/use-fixtures :each setup/test-datelist-fixture) - -(ct/deftest should-identify-business-days-when-business-days?-with-date +(defcalendartest should-identify-business-days-when-business-days?-with-date (ct/are [date calendars expected-sat-sun expected-fri-sat] (and (= expected-sat-sun (apply holi/business-day? (t/date date) :sat-sun calendars)) (= expected-sat-sun (apply holi/business-day? (t/date-time (str date "T11:11:00")) :sat-sun calendars)) @@ -25,7 +23,7 @@ "2020-08-01" ["DAY-THREE"] false false "2020-08-03" ["DAY-THREE"] false false)) -(ct/deftest should-default-weekend-option-to-sat-sun-when-business-day?-with-no-weekend-option +(defcalendartest should-default-weekend-option-to-sat-sun-when-business-day?-with-no-weekend-option (ct/testing "date" (ct/testing "[date]" (ct/is (= (holi/business-day? (t/date "2020-08-02")) @@ -48,7 +46,7 @@ (ct/is (= (holi/business-day? (t/date-time "2020-08-02T11:11:00") "DAY-THREE" "DAY-TWENTY-NINE") (holi/business-day? (t/date-time "2020-08-02T11:11:00") :sat-sun "DAY-THREE" "DAY-TWENTY-NINE")))))) -(ct/deftest +(defcalendartest ^{:doc "This test relies on TEST-WEEKEND and/or DAY-THREE, both of which only list dates in 2020. Any argument outside 2020 should raise an exception"} should-throw-when-business-day?-with-date-beyond-limit-year @@ -83,7 +81,7 @@ "2019-12-31" [] "2019-12-31" ["DAY-THREE"])))) -(ct/deftest should-throw-when-business-day?-with-inexistent-calendar-or-starting-with-WEEKEND +(defcalendartest should-throw-when-business-day?-with-inexistent-calendar-or-starting-with-WEEKEND (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): NOT-A-CALENDAR!" (holi/business-day? (t/date "2020-10-10") :sat-sun "NOT-A-CALENDAR!"))) (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): NOT-A-CALENDAR!" (holi/business-day? (t/date "2020-10-10") :fri-sat "NOT-A-CALENDAR!"))) (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): WEEKEND" (holi/business-day? (t/date "2020-10-10") :fri-sat "WEEKEND"))) diff --git a/test/luciolucio/holi/is_holiday_test.cljc b/test/luciolucio/holi/is_holiday_test.cljc index 3cafc04..41a3cc0 100644 --- a/test/luciolucio/holi/is_holiday_test.cljc +++ b/test/luciolucio/holi/is_holiday_test.cljc @@ -1,14 +1,12 @@ (ns luciolucio.holi.is-holiday-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t]) #?(:clj (:import (clojure.lang ExceptionInfo)))) -(ct/use-fixtures :each setup/test-datelist-fixture) - -(ct/deftest should-identify-holidays-when-holiday?-with-date +(defcalendartest should-identify-holidays-when-holiday?-with-date (ct/are [date calendar expected] (= expected (holi/holiday? date calendar)) (t/date "2020-08-01") "DAY-TWENTY-NINE" false @@ -18,7 +16,7 @@ (t/date "2020-08-01") "DAY-THREE" false (t/date "2020-08-03") "DAY-THREE" true)) -(ct/deftest should-identify-holidays-when-holiday?-with-date-time +(defcalendartest should-identify-holidays-when-holiday?-with-date-time (ct/are [date calendar expected] (= expected (holi/holiday? date calendar)) (t/date-time "2020-08-01T00:00:00") "DAY-TWENTY-NINE" false @@ -28,7 +26,7 @@ (t/date-time "2020-08-01T16:40:40") "DAY-THREE" false (t/date-time "2020-08-03T09:09:09") "DAY-THREE" true)) -(ct/deftest +(defcalendartest ^{:doc "This test relies on TEST-WEEKEND and DAY-THREE, which only list dates in 2020. Any argument outside 2020 should raise an exception"} should-throw-when-holiday?-with-date-beyond-limit-year @@ -37,7 +35,7 @@ "2021-08-03" "DAY-THREE" "2019-08-03" "DAY-THREE")) -(ct/deftest +(defcalendartest ^{:doc "This test relies on TEST-WEEKEND and DAY-THREE, which only list dates in 2020. Any argument outside 2020 should raise an exception"} should-throw-when-holiday?-with-date-time-beyond-limit-year @@ -46,7 +44,7 @@ "2021-08-03T10:10:10" "DAY-THREE" "2019-08-03T23:59:59" "DAY-THREE")) -(ct/deftest should-throw-when-holiday?-with-inexistent-calendar-or-starting-with-WEEKEND +(defcalendartest should-throw-when-holiday?-with-inexistent-calendar-or-starting-with-WEEKEND (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): C-A-L" (holi/holiday? (t/date "2020-10-10") "C-A-L"))) (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): WEEKEND" (holi/holiday? (t/date "2020-10-10") "WEEKEND"))) (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): WEEKENDO" (holi/holiday? (t/date "2020-10-10") "WEEKENDO"))) diff --git a/test/luciolucio/holi/is_non_business_day_test.cljc b/test/luciolucio/holi/is_non_business_day_test.cljc index 91f4e08..c4cb4fc 100644 --- a/test/luciolucio/holi/is_non_business_day_test.cljc +++ b/test/luciolucio/holi/is_non_business_day_test.cljc @@ -1,14 +1,12 @@ (ns luciolucio.holi.is-non-business-day-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t]) #?(:clj (:import (clojure.lang ExceptionInfo)))) -(ct/use-fixtures :each setup/test-datelist-fixture) - -(ct/deftest should-identify-non-business-days-when-non-business-day? +(defcalendartest should-identify-non-business-days-when-non-business-day? (ct/are [date calendars expected-sat-sun expected-fri-sat] (and (= expected-sat-sun (apply holi/non-business-day? (t/date date) :sat-sun calendars)) (= expected-sat-sun (apply holi/non-business-day? (t/date-time (str date "T11:11:00")) :sat-sun calendars)) @@ -25,7 +23,7 @@ "2020-08-01" ["DAY-THREE"] true true "2020-08-03" ["DAY-THREE"] true true)) -(ct/deftest should-default-weekend-option-to-sat-sun-when-non-business-day?-with-no-weekend-option +(defcalendartest should-default-weekend-option-to-sat-sun-when-non-business-day?-with-no-weekend-option (ct/testing "date" (ct/testing "[date]" (ct/is (= (holi/non-business-day? (t/date "2020-08-02")) @@ -48,7 +46,7 @@ (ct/is (= (holi/non-business-day? (t/date-time "2020-08-02T11:11:00") "DAY-THREE" "DAY-TWENTY-NINE") (holi/non-business-day? (t/date-time "2020-08-02T11:11:00") :sat-sun "DAY-THREE" "DAY-TWENTY-NINE")))))) -(ct/deftest +(defcalendartest ^{:doc "This test relies on TEST-WEEKEND and/or DAY-THREE, both of which only list dates in 2020. Any argument outside 2020 should raise an exception"} should-throw-when-non-business-day?-with-date-beyond-limit-year @@ -83,7 +81,7 @@ "2019-12-31" [] "2019-12-31" ["DAY-THREE"])))) -(ct/deftest should-throw-when-non-business-day?-with-inexistent-calendar-or-starting-with-WEEKEND +(defcalendartest should-throw-when-non-business-day?-with-inexistent-calendar-or-starting-with-WEEKEND (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): NOT-A-CALENDAR!" (holi/non-business-day? (t/date "2020-10-10") :sat-sun "NOT-A-CALENDAR!"))) (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): NOT-A-CALENDAR!" (holi/non-business-day? (t/date "2020-10-10") :fri-sat "NOT-A-CALENDAR!"))) (ct/is (thrown-with-msg? ExceptionInfo #"Unknown calendar\(s\): WEEKEND" (holi/non-business-day? (t/date "2020-10-10") :fri-sat "WEEKEND"))) diff --git a/test/luciolucio/holi/is_weekend_test.cljc b/test/luciolucio/holi/is_weekend_test.cljc index 0779ba8..215e896 100644 --- a/test/luciolucio/holi/is_weekend_test.cljc +++ b/test/luciolucio/holi/is_weekend_test.cljc @@ -1,17 +1,15 @@ (ns luciolucio.holi.is-weekend-test (:require [clojure.test :as ct] [luciolucio.holi :as holi] - [luciolucio.holi.test-setup :as setup] + [luciolucio.holi.test-setup :refer [defcalendartest]] [tick.core :as t]) #?(:clj (:import (clojure.lang ExceptionInfo)))) -(ct/use-fixtures :each setup/test-datelist-fixture) - -(ct/deftest should-default-weekend-option-to-sat-sun-when-weekend?-with-no-weekend-option +(defcalendartest should-default-weekend-option-to-sat-sun-when-weekend?-with-no-weekend-option (ct/is (= (holi/weekend? (t/date "2020-08-01")) (holi/weekend? (t/date "2020-08-01") :sat-sun)))) -(ct/deftest should-identify-weekends-when-weekend? +(defcalendartest should-identify-weekends-when-weekend? (ct/are [date expected-sat-sun expected-fri-sat] (and (= expected-sat-sun (holi/weekend? (t/date date) :sat-sun)) (= expected-fri-sat (holi/weekend? (t/date date) :fri-sat)) @@ -23,7 +21,7 @@ "2020-08-02" true false "2020-08-03" false false)) -(ct/deftest +(defcalendartest ^{:doc "This test relies on TEST-WEEKEND-SAT-SUN and TEST-WEEKEND-FRI-SAT datelists, which list weekends in 2020. Any argument outside 2020 should raise an exception"} should-throw-when-weekend?-with-date-beyond-limit-year diff --git a/test/luciolucio/holi/test_setup.cljc b/test/luciolucio/holi/test_setup.cljc index 01229f3..829dc68 100644 --- a/test/luciolucio/holi/test_setup.cljc +++ b/test/luciolucio/holi/test_setup.cljc @@ -1,5 +1,6 @@ (ns luciolucio.holi.test-setup - (:require [luciolucio.holi.core] + (:require [clojure.test :as ct] + [luciolucio.holi.core] [luciolucio.holi.util :as util :include-macros true])) (def holiday-datelists @@ -12,6 +13,9 @@ "HOLIDAY-ON-SAT-SUN-WEEKEND" (util/slurp-resource "HOLIDAY-ON-SAT-SUN-WEEKEND.datelist") "TEST-US" (util/slurp-resource "TEST-US.datelist")}) -(defn test-datelist-fixture [f] - (with-redefs [luciolucio.holi.core/holiday-datelists holiday-datelists] - (f))) +(defmacro with-test-calendars [& body] + `(with-redefs [luciolucio.holi.core/holiday-datelists holiday-datelists] + ~@body)) + +(defmacro defcalendartest [name & body] + `(ct/deftest ~name (with-test-calendars ~@body)))