summaryrefslogtreecommitdiffstats
path: root/tests/parse.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parse.sh')
-rwxr-xr-xtests/parse.sh77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/parse.sh b/tests/parse.sh
new file mode 100755
index 0000000..eadd2cf
--- /dev/null
+++ b/tests/parse.sh
@@ -0,0 +1,77 @@
+# Tests @'s date/time parsing
+#
+# Copyright (C) 2022 P. J. McDermott
+#
+# This file is part of @
+#
+# @ is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# @ 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with @. If not, see <http://www.gnu.org/licenses/>.
+
+set -eu
+
+. "${TOP_SRCDIR}/tests/aux/tap-functions.sh"
+
+now='1969-12-31 23:59:30'
+tgt='1970-01-01 00:00:00'
+
+fmts="$(TZ=UTC0 "${TOP_BUILDDIR}/atsign" -d "${tgt}" -F)"
+time_fmts="$(printf '%s\n' "${fmts}" | \
+ sed -n '/^Time formats:$/,/^Date formats:$/s/^ \* //p')"
+date_fmts="$(printf '%s\n' "${fmts}" | \
+ sed -n '/^Date formats:$/,/^Additional formats:$/s/^ \* //p')"
+misc_fmts="$(printf '%s\n' "${fmts}" | \
+ sed -n '/^Additional formats:$/,$s/^ \* //p')"
+
+plan_ $((\
+ $(printf '%s\n' "${time_fmts}" | wc -l) + \
+ $(printf '%s\n' "${time_fmts}" | wc -l) * \
+ $(printf '%s\n' "${date_fmts}" | wc -l) * \
+ 2 + \
+ $(printf '%s\n' "${misc_fmts}" | wc -l) \
+ ))
+
+IFS='
+'
+
+for fmt in $(printf '%s\n' "${fmts}"); do
+ diag_ "${fmt}"
+done
+
+test_fmt()
+{
+ now="${1}"
+ tgt="${2}"
+ fmt="${3}"
+ shift 3
+
+ got="$(TZ=UTC0 "${TOP_BUILDDIR}/atsign" -d "${now}" "${fmt}" 2>&1)" || :
+ if [ x"${got}" = x"${tgt}" ]; then
+ ok_ -- "${fmt}"
+ else
+ not_ok_ -- "${fmt}"
+ diag_ " Failed test '${fmt}'"
+ diag_ " got: '${got}'"
+ diag_ " expected: '${tgt}'"
+ fi
+}
+
+for time_fmt in ${time_fmts}; do
+ test_fmt "${now}" "${tgt}" "${time_fmt}"
+ for date_fmt in ${date_fmts}; do
+ test_fmt "${now}" "${tgt}" "${date_fmt} ${time_fmt}"
+ test_fmt "${now}" "${tgt}" "${time_fmt} ${date_fmt}"
+ done
+done
+for misc_fmt in ${misc_fmts}; do
+ test_fmt "${now}" "${tgt}" "${misc_fmt}"
+done