Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
{:output {:progress true}}
{:output {:progress true}
:lint-as {luciolucio.holi.test-setup/defcalendartest clojure.test/deftest}}
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -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"]}}}
18 changes: 8 additions & 10 deletions test/luciolucio/holi/add_test/business_days_calendar_test.cljc
Original file line number Diff line number Diff line change
@@ -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")))

Expand All @@ -22,39 +20,39 @@
; 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"
1 "2020-07-31" "2020-08-02"
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"
7 "2020-08-12" "2020-08-11"
-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"
7 "2020-08-12" "2020-08-11"
-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"
7 "2020-08-12" "2020-08-12"
-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"
Expand All @@ -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"))))
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"))))
Expand Down
Original file line number Diff line number Diff line change
@@ -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")))

Expand All @@ -22,38 +20,38 @@
; 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"
1 "2020-07-31" "2020-08-02"
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"
1 "2020-08-04" "2020-08-02"
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"
7 "2020-08-12" "2020-08-11"
-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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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")))

Expand All @@ -22,38 +20,38 @@
; 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"
2 "2020-08-04" "2020-08-03"
-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"
7 "2020-08-11" "2020-08-10"
-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"
5 "2020-08-07" "2020-08-09"
-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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
14 changes: 6 additions & 8 deletions test/luciolucio/holi/holidays_in_date_test.cljc
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
(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" []
"2020-07-29" "DAY-TWENTY-NINE" ["Twenty Ninth Day"]
"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" []
"2020-07-29T11:11:22" "DAY-TWENTY-NINE" ["Twenty Ninth Day"]
"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
Expand All @@ -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
Expand All @@ -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")))
Expand Down
Loading
Loading