summaryrefslogtreecommitdiffstats
path: root/tmac/tests/e_line-numbering-works.sh
blob: 427840e54b82394563e73c0d60f18635956a7c66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/sh
#
# Copyright (C) 2021 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"

# Test the line numbering feature.

input='.nr pp 18 \\" to make troff output consistent with nroff
.if r mypo .po \\n[mypo]u
.if !d C .ds C\\" empty
.pp
Feck, vex loping bad jazz: quench my thirst.
Feck, vex loping bad jazz: quench my thirst.
.pp
.n1 \\*C
Jackdaws love my big sphinx of quartz.
Jackdaws love my big sphinx of quartz.
Jackdaws love my big sphinx of quartz.
.pp
How vexingly quick daft zebras jump!
.pp
.n2 +6
Waltz, bad nymph, for quick jigs vex.
Waltz, bad nymph, for quick jigs vex.
.pp
.n2 99
Pack my box with five dozen liquor jugs.
Pack my box with five dozen liquor jugs.
Pack my box with five dozen liquor jugs.
.pp
.n2
The five boxing wizards jump quickly.
The five boxing wizards jump quickly.'

fail=

wail () {
    echo "...FAILED" >&2
    fail=YES
}

echo '*** basic output (line number field prepended)' >&2
output=$(echo "$input" | "$groff" -Tascii -P-cbou -me)

echo "$output"

# We expect the foregoing to produce a me(7) diagnostic complaining of a
# negative page offset but we're not testing for that.

echo 'checking for 0 page offset and 5n paragraph indentation (1)' >&2
echo "$output" | grep -q '^     Feck.*vex$' || wail # 5 spaces

# troff uses backspaces to emit the line number, so we can't anchor the
# matches to the beginning of the line with '^'.

# These patterns have 6 embedded spaces until further notice.
echo 'checking for line number field plus 60n line length' >&2
echo "$output" | grep -q '1      Jackdaws.*love$' || wail

echo 'checking for non-numbering of blank lines' >&2
echo "$output" | grep -q '4      How.*jump!$' || wail

echo 'checking offset-advanced two-digit line number' >&2
echo "$output" | grep -q '^10      Waltz,.*bad nymph$'

echo 'checking three-digit line number' >&2
echo "$output" | grep -q '^100      with.*dozen$'

echo 'checking for 0 page offset and 5n paragraph indentation (2)' >&2
echo "$output" | grep -q '^     The.*boxing$' || wail # 5 spaces

echo '*** roff(1)-compatible output (shorter line length)' >&2
output=$(echo "$input" | "$groff" -dCC -Tascii -P-cbou -me)

echo "$output"

echo 'checking for 0 page offset and 5n paragraph indentation (1)' >&2
echo "$output" | grep -q '^     Feck.*vex' || wail # 5 spaces

echo 'checking for line number field plus 56n line length' >&2
echo "$output" \
    | grep -q '  1      Jackdaws.*Jackdaws$' || wail # 2, then 6 spaces

# These patterns have 6 embedded spaces until further notice.
echo 'checking for non-numbering of blank lines' >&2
echo "$output" | grep -q '4      How.*jump!$' || wail

echo 'checking offset-advanced two-digit line number' >&2
echo "$output" | grep -q ' 10      Waltz,.*bad$' || wail

echo 'checking three-digit line number' >&2
echo "$output" | grep -q '^100      box.*dozen$'

echo 'checking for 0 page offset and 5n paragraph indentation (2)' >&2
echo "$output" | grep -q '^     The.*boxing$' || wail # 5 spaces

echo '*** output with 4n page offset' >&2
output=$(echo "$input" | "$groff" -rmypo=4n -Tascii -P-cbou -me)

echo "$output"

echo 'checking for 4n page offset and 5n paragraph indentation (1)' >&2
echo "$output" | grep -q '^         Feck.*vex' || wail # 9 spaces

echo 'checking for line number field plus 60n line length' >&2
echo "$output" \
    | grep -q '  1      Jackdaws.*love$' || wail # 2, then 6 spaces

# These patterns have 6 embedded spaces until further notice.
echo 'checking for non-numbering of blank lines' >&2
echo "$output" | grep -q '4      How.*jump!$' || wail

echo 'checking offset-advanced two-digit line number' >&2
echo "$output" | grep -q ' 10      Waltz,.*bad$' || wail

echo 'checking three-digit line number' >&2
echo "$output" | grep -q '^100      box.*dozen$'

echo 'checking for 4n page offset and 5n paragraph indentation (2)' >&2
echo "$output" | grep -q '^         The.*boxing$' || wail # 9 spaces

test -z "$fail"

# vim:set ai et sw=4 ts=4 tw=72: