gbranden pushed a commit to branch master
in repository groff.
commit 5f608c758ffc1558fd4d07f387a3559bd6b95af5
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Jul 19 13:53:40 2024 -0500
Add test of *roff arithmetic.
* src/roff/groff/tests/arithmetic-works.sh: Do it.
* src/roff/groff/groff.am (groff_TESTS): Run test.
---
ChangeLog | 7 ++
src/roff/groff/groff.am | 1 +
src/roff/groff/tests/arithmetic-works.sh | 118 +++++++++++++++++++++++++++++++
3 files changed, 126 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 4b734a655..72f9e976d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-07-19 G. Branden Robinson <[email protected]>
+
+ Add test of *roff arithmetic.
+
+ * src/roff/groff/tests/arithmetic-works.sh: Do it.
+ * src/roff/groff/groff.am (groff_TESTS): Run test.
+
2024-07-19 G. Branden Robinson <[email protected]>
[troff]: Prevent traps on overflowing integer arithmetic.
diff --git a/src/roff/groff/groff.am b/src/roff/groff/groff.am
index 7e9ebe212..119a14567 100644
--- a/src/roff/groff/groff.am
+++ b/src/roff/groff/groff.am
@@ -38,6 +38,7 @@ EXTRA_DIST += src/roff/groff/groff.1.man
groff_TESTS = \
src/roff/groff/tests/ab_works.sh \
src/roff/groff/tests/adjustment_works.sh \
+ src/roff/groff/tests/arithmetic-works.sh \
src/roff/groff/tests/backslash-X-works.sh \
src/roff/groff/tests/backslash-exclamation-early-does-not-fail.sh \
src/roff/groff/tests/break_zero-length_output_line_sanely.sh \
diff --git a/src/roff/groff/tests/arithmetic-works.sh
b/src/roff/groff/tests/arithmetic-works.sh
new file mode 100755
index 000000000..3f0b91701
--- /dev/null
+++ b/src/roff/groff/tests/arithmetic-works.sh
@@ -0,0 +1,118 @@
+#!/bin/sh
+#
+# Copyright (C) 2024 Free Software Foundation, Inc.
+#
+# This file is part of groff.
+#
+# groff 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.
+#
+# groff 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 this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+fail=
+
+wail () {
+ echo "...FAILED" >&2
+ fail=yes
+}
+
+# Unit-test saturating arithmetic.
+
+# Start with a couple of cases that proved fragile when developing it.
+#
+# Incrementing a formatter internal via a request should produce the
+# expected changes in magnitude (not repeat or square them).
+#
+# Vertical spacing exercises `vunits` and line length, `hunits`.
+
+input='.
+.ec @
+.nf
+.vs +2
+@&.v=@n(.v
+.ll -2
+@&.l=@n(.l
+.'
+
+# Expected:
+#
+# .v=40
+# .l=1512
+
+output=$(echo "$input" | "$groff" -T ascii)
+echo "$output"
+
+echo "checking that vertical spacing is correctly incremented" >&2
+echo "$output" | grep -Fqx '.l=1512' || wail
+
+echo "checking that line length is correctly incremented" >&2
+echo "$output" | grep -Fqx '.l=1512' || wail
+
+# Exercise boundary values.
+
+input='.
+.ec @
+.nf
+.nr i 99999999999999999999
+1: 99999999999999999999 -> @ni
+.nr i (-99999999999999999999)
+2: (-99999999999999999999) -> @ni
+.nr i 2147483647
+3: assign 2147483647 -> @ni
+.nr i +1
+4: incr 2147483647 -> @ni
+.nr i 2147483647
+.nr i (-1)*@ni
+5: (-1)*2147483647 -> @ni
+.nr i -1
+6: decr -2147483648 -> @ni
+.nr i -2147483648
+.nr i (-1)*@ni
+7: (-1)*(-2147483648) -> @ni
+.'
+
+output=$(echo "$input" | "$groff" -T ascii)
+echo "$output"
+
+# saturating: 2147483647
+echo "checking assignment of huge value to register" >&2
+echo "$output" \
+ | grep -Fqx '1: 99999999999999999999 -> 1410065407' || wail
+
+# saturating: -2147483648
+echo "checking assignment of huge negative value to register" >&2
+echo "$output" \
+ | grep -Fqx '2: (-99999999999999999999) -> -1410065407' || wail
+
+echo "checking assignment of 2^31 - 1 to register" >&2
+echo "$output" | grep -Fqx '3: assign 2147483647 -> 2147483647' || wail
+
+# saturating: -2147483648
+echo "checking saturating incrementation of register" >&2
+echo "$output" | grep -Fqx '4: incr 2147483647 -> -2147483648' || wail
+
+echo "checking negation of positive register" >&2
+echo "$output" | grep -Fqx '5: (-1)*2147483647 -> -2147483647' || wail
+
+echo "checking saturating decrementation of register" >&2
+echo "$output" | grep -Fqx '6: decr -2147483648 -> -2147483648' || wail
+
+# saturating: 2147483647
+echo "checking negation of negatively saturated register" >&2
+echo "$output" | grep -Fqx '7: (-1)*(-2147483648) -> 0' \
+ || wail
+
+test -z "$fail"
+
+# vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72:
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit