Add more java.time classes, test with cljc.java-time tests

This commit is contained in:
Michiel Borkent 2020-05-29 20:28:42 +02:00
parent d4492071b6
commit 696d4102a7
5 changed files with 129 additions and 2 deletions

View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -eo pipefail
if [ "$BABASHKA_TEST_ENV" = "native" ]; then
BB_CMD="./bb"
else
BB_CMD="lein bb"
fi
export BABASHKA_CLASSPATH
BABASHKA_CLASSPATH="$(clojure -Sdeps '{:deps {cljc.java-time {:git/url "https://github.com/henryw374/cljc.java-time.git" :sha "e3d184b78e933322b3fcaa6ca66cbb8f42a6b35c"}}}' -Spath)"
$BB_CMD -cp "$BABASHKA_CLASSPATH:test-resources/lib_tests" -e "
(require '[clojure.java.io :as io])
(require '[cljc.java-time-test])
(require '[clojure.test :as t])
(let [{:keys [:test :pass :fail :error]} (t/run-tests 'cljc.java-time-test)]
(when-not (pos? test)
(System/exit 1))
(System/exit (+ fail error)))
"

View file

@ -23,3 +23,4 @@ script/lib_tests/clojure_data_csv_test
script/lib_tests/combinatorics_test script/lib_tests/combinatorics_test
script/lib_tests/doric_test script/lib_tests/doric_test
script/lib_tests/clojure_data_zip_test script/lib_tests/clojure_data_zip_test
script/lib_tests/cljc_java_time_test

View file

@ -109,6 +109,7 @@
java.lang.Exception java.lang.Exception
java.lang.Integer java.lang.Integer
java.lang.Long java.lang.Long
java.lang.Number
java.lang.NumberFormatException java.lang.NumberFormatException
java.lang.Math java.lang.Math
java.lang.Object java.lang.Object
@ -152,7 +153,7 @@
java.nio.file.attribute.PosixFilePermissions]) java.nio.file.attribute.PosixFilePermissions])
java.security.MessageDigest java.security.MessageDigest
~@(when features/java-time? ~@(when features/java-time?
'[java.time.format.DateTimeFormatter `[java.time.format.DateTimeFormatter
java.time.Clock java.time.Clock
java.time.DateTimeException java.time.DateTimeException
java.time.DayOfWeek java.time.DayOfWeek
@ -172,8 +173,19 @@
java.time.ZonedDateTime java.time.ZonedDateTime
java.time.ZoneId java.time.ZoneId
java.time.ZoneOffset java.time.ZoneOffset
java.time.format.DateTimeFormatterBuilder
java.time.format.DecimalStyle
java.time.format.ResolverStyle
java.time.format.SignStyle
java.time.temporal.ChronoField
java.time.temporal.ChronoUnit java.time.temporal.ChronoUnit
java.time.temporal.TemporalAccessor]) java.time.temporal.IsoFields
java.time.temporal.TemporalField
~(symbol "[Ljava.time.temporal.TemporalField;")
java.time.format.TextStyle
java.time.temporal.Temporal
java.time.temporal.TemporalAccessor
java.time.temporal.TemporalAdjuster])
java.util.concurrent.LinkedBlockingQueue java.util.concurrent.LinkedBlockingQueue
java.util.jar.JarFile java.util.jar.JarFile
java.util.jar.JarEntry java.util.jar.JarEntry
@ -185,6 +197,7 @@
java.util.Date java.util.Date
java.util.MissingResourceException java.util.MissingResourceException
java.util.Properties java.util.Properties
java.util.Set
java.util.UUID java.util.UUID
java.util.concurrent.TimeUnit java.util.concurrent.TimeUnit
java.util.zip.InflaterInputStream java.util.zip.InflaterInputStream

View file

@ -411,6 +411,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
File java.io.File File java.io.File
Long java.lang.Long Long java.lang.Long
Math java.lang.Math Math java.lang.Math
Number java.lang.Number
NumberFormatException java.lang.NumberFormatException NumberFormatException java.lang.NumberFormatException
Object java.lang.Object Object java.lang.Object
Runtime java.lang.Runtime Runtime java.lang.Runtime

View file

@ -0,0 +1,90 @@
(ns cljc.java-time-test
(:require [clojure.test :refer [deftest testing is]]
[cljc.java-time.temporal.chrono-field]
[cljc.java-time.temporal.chrono-unit]
[cljc.java-time.temporal.iso-fields]
[cljc.java-time.temporal.temporal]
[cljc.java-time.temporal.temporal-accessor]
[cljc.java-time.temporal.temporal-adjuster]
[cljc.java-time.format.date-time-formatter]
[cljc.java-time.format.resolver-style]
[cljc.java-time.format.date-time-formatter-builder]
[cljc.java-time.format.decimal-style]
[cljc.java-time.format.sign-style]
[cljc.java-time.format.text-style]
[cljc.java-time.clock :as clock]
[cljc.java-time.day-of-week :as day-of-week]
[cljc.java-time.duration :as duration]
[cljc.java-time.instant :as instant]
[cljc.java-time.local-date :as local-date]
[cljc.java-time.local-date-time :as local-date-time]
[cljc.java-time.local-time :as local-time]
[cljc.java-time.month :as month]
[cljc.java-time.month-day :as month-day]
[cljc.java-time.offset-date-time :as offset-date-time]
[cljc.java-time.offset-time :as offset-time]
[cljc.java-time.period :as period]
[cljc.java-time.year :as year]
[cljc.java-time.year-month :as year-month]
[cljc.java-time.zone-id :as zone-id]
[cljc.java-time.zone-offset :as zone-offset]
[cljc.java-time.zoned-date-time :as zoned-date-time]
[cljc.java-time.extn.predicates :as predicates]
#?(:cljs [cljs.java-time.extend-eq-and-compare])))
#?(:clj
(deftest multi-tail-var-args
(testing "multi-tail var args example"
(is (let [a (make-array java.time.temporal.TemporalField 1)]
(aset a 0 cljc.java-time.temporal.chrono-field/nano-of-second)
(cljc.java-time.format.date-time-formatter/with-resolver-fields
cljc.java-time.format.date-time-formatter/iso-instant
a))))))
(deftest normal-multi-tail
(is (year-month/of (int 12) (int 12)))
(is (year-month/of (int 12) month/january)))
(deftest get-longs
(testing "normal getter"
(is (year-month/get-year
(year-month/now))))
(testing "getLong, which has a different name in jsjoda :-S "
(is (year-month/get-long
(year-month/now)
cljc.java-time.temporal.chrono-field/month-of-year))))
(deftest leap-year
(testing "no obv. way to accommodate both isLeap methods. just going with the static one"
(is (year/is-leap 24))))
(deftest of-works-in-js-and-jvm
(is (= (local-date-time/of 2011 month/january 3 11 59) (local-date-time/of 2011 month/january 3 11 59))))
(deftest predicates
(is (true? (predicates/clock? (clock/system-utc))))
(is (true? (predicates/day-of-week? day-of-week/monday)))
(is (true? (predicates/duration? (duration/parse "PT1M"))))
(is (true? (predicates/instant? (instant/now))))
(is (true? (predicates/local-date? (local-date/now))))
(is (true? (predicates/local-date-time? (local-date-time/now))))
(is (true? (predicates/local-time? (local-time/now))))
(is (true? (predicates/month? month/may)))
(is (true? (predicates/month-day? (month-day/now))))
(is (true? (predicates/offset-date-time? (offset-date-time/now))))
(is (true? (predicates/offset-time? (offset-time/now))))
(is (true? (predicates/period? (period/parse "P1D"))))
(is (true? (predicates/year? (year/now))))
(is (true? (predicates/year-month? (year-month/now))))
(is (true? (predicates/zone-id? (zone-id/system-default))))
(is (true? (predicates/zone-offset? zone-offset/utc)))
(is (true? (predicates/zoned-date-time? (zoned-date-time/now))))
(is (true? (predicates/date? (local-date/now))))
(is (true? (predicates/date-time? (local-date-time/now))))
(is (true? (predicates/time? (local-time/now))))
(is (false? (predicates/local-date? 16)))
(is (false? (predicates/month? 16))))