groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 14/16: [troff]: Add unit test for `device` request.


From: G. Branden Robinson
Subject: [groff] 14/16: [troff]: Add unit test for `device` request.
Date: Wed, 10 Jan 2024 23:55:05 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 76b48901e8815939636edb91040c4ff2ac2bca1a
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Jan 8 19:31:59 2024 -0600

    [troff]: Add unit test for `device` request.
    
    * src/roff/groff/tests/device-request-works.sh: Add test.
    * src/roff/groff/groff.am (groff_TESTS): Run test.
    
    Fixes <https://savannah.gnu.org/bugs/?64959>.
---
 ChangeLog                                    |  9 ++++
 src/roff/groff/groff.am                      |  1 +
 src/roff/groff/tests/device-request-works.sh | 75 ++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index ad0a6b8f6..c660d4ec8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-01-08  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [troff]: Add unit test for `device` request.
+
+       * src/roff/groff/tests/device-request-works.sh: Add test.
+       * src/roff/groff/groff.am (groff_TESTS): Run test.
+
+       Fixes <https://savannah.gnu.org/bugs/?64959>.
+
 2024-01-08  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * doc/groff.texi (Postprocessor Access):
diff --git a/src/roff/groff/groff.am b/src/roff/groff/groff.am
index c90756552..94c7249bd 100644
--- a/src/roff/groff/groff.am
+++ b/src/roff/groff/groff.am
@@ -42,6 +42,7 @@ groff_TESTS = \
   src/roff/groff/tests/break_zero-length_output_line_sanely.sh \
   src/roff/groff/tests/cf-request-early-does-not-fail.sh \
   src/roff/groff/tests/detect-evil-link-time-optimizer.sh \
+  src/roff/groff/tests/device-request-works.sh \
   src/roff/groff/tests/device_control_escapes_express_basic_latin.sh \
   src/roff/groff/tests/do_not_loop_infinitely_when_breaking_cjk.sh \
   src/roff/groff/tests/dot-cp_register_works.sh \
diff --git a/src/roff/groff/tests/device-request-works.sh 
b/src/roff/groff/tests/device-request-works.sh
new file mode 100755
index 000000000..f30853676
--- /dev/null
+++ b/src/roff/groff/tests/device-request-works.sh
@@ -0,0 +1,75 @@
+#!/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
+}
+
+# A break request is necessary to create a partially collected line in
+# the top-level diversion.
+
+input_plain='.device ps: nop
+.br'
+
+input_quoted='.device " ps: nop
+.br'
+
+# We need to portably get a backslash into the string, and we can't
+# change the escape character because despite appearances, this notation
+# isn't a groff escape sequence: it's passed to the output device.
+#
+# Omit the trailing newline; it is supplied below.
+#
+# 8 backslashes
+input_special=$(printf ".device pdf: \\\\\\\\[u007E]\n.br")
+
+for device in ascii cp1047 dvi html xhtml latin1 lbp lj4 pdf ps utf8 \
+              X75 X75-12 X100 X100-12
+do
+  echo "checking 'device' request basic operation on $device device" >&2
+  output=$(printf "%s\n" "$input_plain" | "$groff" -T $device -Z) \
+    || wail
+  echo "$output"
+  echo "$output" | grep -Eq 'x * X *ps: nop' || wail
+
+  echo "checking quoteful 'device' operation on $device device" >&2
+  output=$(printf "%s\n" "$input_quoted" | "$groff" -T $device -Z) \
+    || wail
+  echo "$output"
+  # 2 spaces before '*ps:'
+  echo "$output" | grep -Eq 'x * X  *ps: nop' || wail
+
+  echo "checking that Unicode escape sequence is preserved on $device" \
+       " device" >&2
+  output=$(printf "%s\n" "$input_special" | "$groff" -T $device -Z) \
+    || wail
+  echo "$output"
+  # 3 backslashes
+  echo "$output" | grep -Eq 'x * X *pdf: \\\[u007E\]' || wail
+done
+
+test -z "$fail"
+
+# vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]