]> git.draconx.ca Git - dxcommon.git/blob - tests/functions.at
e1d556b0a71d59e697f14c3701f23b9fb33faa0a
[dxcommon.git] / tests / functions.at
1 dnl Copyright © 2015, 2021-2023 Nick Bowler
2 dnl
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
6
7 AT_BANNER([Binary packing functions])
8
9 TEST_TAP_SIMPLE([signed unpacking], [packtests], [], [pack])
10 TEST_TAP_SIMPLE([unsigned unpacking], [packtestu], [], [pack])
11 TEST_TAP_SIMPLE([64-bit signed unpacking], [packtests64], [], [pack])
12 TEST_TAP_SIMPLE([64-bit unsigned unpacking], [packtestu64], [], [pack])
13
14 AT_BANNER([Help formatting functions])
15
16 AT_SETUP([help_print_desc])
17 AT_KEYWORDS([help])
18
19 AT_SKIP_IF([test ! -x "$builddir/t/helpdesc"])
20
21 AT_DATA([test.txt],
22 [[this is the first line
23 this is the second line
24 this is the third line
25 and so on
26 ]])
27
28 sed -e '5,$s/^/     /' -e '6,$s/^/     /' \
29   -e '10,$s/^/                    /' \
30   -e '13s/^ *//' -e '14,$s/^/          /' \
31   test.txt test.txt test.txt test.txt >expout
32
33 AT_CHECK(["$builddir/t/helpdesc" 0 0 10 5 30 20 40 40 <test.txt],
34   [0], [expout])
35
36 AT_CLEANUP
37
38 AT_SETUP([help_print_desc (empty description)])
39 AT_KEYWORDS([help])
40
41 AT_SKIP_IF([test ! -x "$builddir/t/helpdesc"])
42
43 AT_CHECK(["$builddir/t/helpdesc" 0 0 0 20 </dev/null])
44 AT_CHECK(["$builddir/t/helpdesc" 1 20 </dev/null], [0], [
45 ])
46
47 AT_CLEANUP
48
49 AT_SETUP([help_print_optstring])
50 AT_KEYWORDS([help])
51
52 AT_SKIP_IF([test ! -x "$builddir/t/helpopt"])
53
54 AT_CHECK([m4_join([ ],
55   ["$builddir/t/helpopt"],
56   [--foo],
57   [--bar -b],
58   [--baz ARG],
59   [--baz -B ARG],
60   [--quux '@<:@ARG@:>@'],
61   [--quux -q '@<:@ARG@:>@'],
62   [--hello-this-is-a-very-long-option 20],
63   [--hello-this-is-a-very-long-option 50],
64   [--not-long 12],
65   [--flagged -f \&])], [0],
66 [[  --foo       7
67   -b, --bar     11
68   --baz=ARG     11
69   -B, --baz=ARG 15
70   --quux[=ARG]  14
71   -q, --quux[=ARG]      18
72   --hello-this-is-a-very-long-option
73         0
74   --hello-this-is-a-very-long-option    36
75   --not-long    12
76   --flagged     11
77 ]])
78
79 AT_CLEANUP
80
81 AT_SETUP([help_print_optstring (getopt_long_only)])
82 AT_KEYWORDS([help])
83
84 AT_SKIP_IF([test ! -x "$builddir/t/helpopt2"])
85
86 AT_CHECK([m4_join([ ],
87   ["$builddir/t/helpopt2"],
88   [--foo],
89   [--bar -b],
90   [--baz ARG],
91   [--baz -B ARG],
92   [--quux '@<:@ARG@:>@'],
93   [--quux -q '@<:@ARG@:>@'],
94   [--hello-this-is-a-very-long-option 20],
95   [--hello-this-is-a-very-long-option 50],
96   [--not-long 12],
97   [--flagged -f \&])], [0],
98 [[  -foo        6
99   -bar  6
100   -baz ARG      10
101   -baz ARG      10
102   -quux [ARG]   13
103   -quux [ARG]   13
104   -hello-this-is-a-very-long-option
105         0
106   -hello-this-is-a-very-long-option     35
107   -not-long     11
108   -flagged      10
109 ]])
110
111 AT_CLEANUP
112
113 AT_SETUP([help_print_optstring (NLS fullwidth/halfwidth)])
114 AT_KEYWORDS([help nls])
115
116 AT_SKIP_IF([test ! -x "$builddir/t/helpopt3"])
117 TEST_UTF8_LOCALE([locale_utf8])
118
119 # Avoid some deficient shell parsers barfing on UTF-8 sequences by
120 # generating them this way using octal escapes.
121 $AWK -f - >expout <<'EOF'
122 BEGIN {
123   zenkaku = "--\345\205\250\350\247\222";
124   hankaku = "--\357\276\212\357\276\235\357\275\266\357\275\270"
125
126   print zenkaku, hankaku >"args"
127
128   print "  " zenkaku "\t" "8"
129   print "  " hankaku "\t" "8"
130 }
131 EOF
132
133 AT_CHECK([LC_ALL=$locale_utf8 xargs "$builddir/t/helpopt3" <args],
134   [0], [expout])
135
136 AT_CLEANUP
137
138 AT_BANNER([Miscellaneous functions])
139
140 TEST_TAP_SIMPLE([copyright_symbol], [copysym], [], [])