Add `rdbl-d64`, Git textconv filter for .d64 files (1541 floppy for C64)
[sunny256-utils.git] / tests / txt2uc.t
blob553930240ea5d592097384e5e2a6dc0695a95320
1 #!/usr/bin/env perl
3 #=======================================================================
4 # txt2uc.t
5 # File ID: 3c8499a2-394c-11e5-b0e5-fefdb24f8e10
7 # Test suite for txt2uc(1).
9 # Character set: UTF-8
10 # ©opyleft 2015– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
15 use strict;
16 use warnings;
18 BEGIN {
19 use Test::More qw{no_plan};
20 # use_ok() goes here
23 use Getopt::Long;
25 local $| = 1;
27 our $CMDB = "txt2uc";
28 our $CMD = "../$CMDB";
30 our %Opt = (
32 'all' => 0,
33 'help' => 0,
34 'quiet' => 0,
35 'todo' => 0,
36 'verbose' => 0,
37 'version' => 0,
41 our $progname = $0;
42 $progname =~ s/^.*\/(.*?)$/$1/;
43 our $VERSION = '0.0.0';
45 my %descriptions = ();
47 Getopt::Long::Configure('bundling');
48 GetOptions(
50 'all|a' => \$Opt{'all'},
51 'help|h' => \$Opt{'help'},
52 'quiet|q+' => \$Opt{'quiet'},
53 'todo|t' => \$Opt{'todo'},
54 'verbose|v+' => \$Opt{'verbose'},
55 'version' => \$Opt{'version'},
57 ) || die("$progname: Option error. Use -h for help.\n");
59 $Opt{'verbose'} -= $Opt{'quiet'};
60 $Opt{'help'} && usage(0);
61 if ($Opt{'version'}) {
62 print_version();
63 exit(0);
66 exit(main());
68 sub main {
69 # {{{
70 my $Retval = 0;
71 my $ucfile = "$ENV{'HOME'}/.unichar.sqlite";
73 diag(sprintf('========== Executing %s v%s ==========',
74 $progname, $VERSION));
76 if ($Opt{'todo'} && !$Opt{'all'}) {
77 goto todo_section;
80 =pod
82 testcmd("$CMD command", # {{{
83 <<'END',
84 [expected stdout]
85 END
86 '',
88 'description',
91 # }}}
93 =cut
95 diag('Testing -h (--help) option...');
96 likecmd("$CMD -h", # {{{
97 '/ Show this help/i',
98 '/^$/',
100 'Option -h prints help screen',
103 # }}}
104 diag('Testing -v (--verbose) option...');
105 likecmd("$CMD -h -v", # {{{
106 '/^\n\S+ \d+\.\d+\.\d+/s',
107 '/^$/',
109 'Option -v with -h returns version number and help screen',
112 # }}}
113 diag('Testing --version option...');
114 likecmd("$CMD --version", # {{{
115 '/^\S+ \d+\.\d+\.\d+/',
116 '/^$/',
118 'Option --version returns version number',
121 # }}}
122 if (!-r $ucfile) {
123 diag("$ucfile not found, skipping tests");
124 return 0;
126 testcmd("echo -n Boring. | $CMD", # {{{
127 <<'END',
128 0042;LATIN CAPITAL LETTER B;Lu;0;L;;;;;N;;;;0062;
129 006F;LATIN SMALL LETTER O;Ll;0;L;;;;;N;;;004F;;004F
130 0072;LATIN SMALL LETTER R;Ll;0;L;;;;;N;;;0052;;0052
131 0069;LATIN SMALL LETTER I;Ll;0;L;;;;;N;;;0049;;0049
132 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
133 0067;LATIN SMALL LETTER G;Ll;0;L;;;;;N;;;0047;;0047
134 002E;FULL STOP;Po;0;CS;;;;;N;PERIOD;;;;
138 'Convert ASCII',
141 # }}}
142 testcmd("echo Rock on. 🤘 | $CMD", # {{{
143 <<'END',
144 0052;LATIN CAPITAL LETTER R;Lu;0;L;;;;;N;;;;0072;
145 006F;LATIN SMALL LETTER O;Ll;0;L;;;;;N;;;004F;;004F
146 0063;LATIN SMALL LETTER C;Ll;0;L;;;;;N;;;0043;;0043
147 006B;LATIN SMALL LETTER K;Ll;0;L;;;;;N;;;004B;;004B
148 0020;SPACE;Zs;0;WS;;;;;N;;;;;
149 006F;LATIN SMALL LETTER O;Ll;0;L;;;;;N;;;004F;;004F
150 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
151 002E;FULL STOP;Po;0;CS;;;;;N;PERIOD;;;;
152 0020;SPACE;Zs;0;WS;;;;;N;;;;;
153 1F918;SIGN OF THE HORNS;So;0;ON;;;;;N;;;;;
154 000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;;
158 'Use char from Unicode 8.0',
161 # }}}
162 testcmd("echo 🥓 FTW 🕺 | $CMD", # {{{
163 <<'END',
164 1F953;BACON;So;0;ON;;;;;N;;;;;
165 0020;SPACE;Zs;0;WS;;;;;N;;;;;
166 0046;LATIN CAPITAL LETTER F;Lu;0;L;;;;;N;;;;0066;
167 0054;LATIN CAPITAL LETTER T;Lu;0;L;;;;;N;;;;0074;
168 0057;LATIN CAPITAL LETTER W;Lu;0;L;;;;;N;;;;0077;
169 0020;SPACE;Zs;0;WS;;;;;N;;;;;
170 1F57A;MAN DANCING;So;0;ON;;;;;N;;;;;
171 000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;;
175 'Use chars from Unicode 9.0',
178 # }}}
179 testcmd("echo The 🧟 wants 🧠, not 🥟 or ₿ | $CMD", # {{{
180 <<'END',
181 0054;LATIN CAPITAL LETTER T;Lu;0;L;;;;;N;;;;0074;
182 0068;LATIN SMALL LETTER H;Ll;0;L;;;;;N;;;0048;;0048
183 0065;LATIN SMALL LETTER E;Ll;0;L;;;;;N;;;0045;;0045
184 0020;SPACE;Zs;0;WS;;;;;N;;;;;
185 1F9DF;ZOMBIE;So;0;ON;;;;;N;;;;;
186 0020;SPACE;Zs;0;WS;;;;;N;;;;;
187 0077;LATIN SMALL LETTER W;Ll;0;L;;;;;N;;;0057;;0057
188 0061;LATIN SMALL LETTER A;Ll;0;L;;;;;N;;;0041;;0041
189 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
190 0074;LATIN SMALL LETTER T;Ll;0;L;;;;;N;;;0054;;0054
191 0073;LATIN SMALL LETTER S;Ll;0;L;;;;;N;;;0053;;0053
192 0020;SPACE;Zs;0;WS;;;;;N;;;;;
193 1F9E0;BRAIN;So;0;ON;;;;;N;;;;;
194 002C;COMMA;Po;0;CS;;;;;N;;;;;
195 0020;SPACE;Zs;0;WS;;;;;N;;;;;
196 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
197 006F;LATIN SMALL LETTER O;Ll;0;L;;;;;N;;;004F;;004F
198 0074;LATIN SMALL LETTER T;Ll;0;L;;;;;N;;;0054;;0054
199 0020;SPACE;Zs;0;WS;;;;;N;;;;;
200 1F95F;DUMPLING;So;0;ON;;;;;N;;;;;
201 0020;SPACE;Zs;0;WS;;;;;N;;;;;
202 006F;LATIN SMALL LETTER O;Ll;0;L;;;;;N;;;004F;;004F
203 0072;LATIN SMALL LETTER R;Ll;0;L;;;;;N;;;0052;;0052
204 0020;SPACE;Zs;0;WS;;;;;N;;;;;
205 20BF;BITCOIN SIGN;Sc;0;ET;;;;;N;;;;;
206 000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;;
210 'Use chars from Unicode 10.0',
213 # }}}
214 testcmd("echo U̲l̲i̲n̲e̲ and s̶t̶r̶i̶k̶e̶. | $CMD", # {{{
215 <<'END',
216 0055;LATIN CAPITAL LETTER U;Lu;0;L;;;;;N;;;;0075;
217 0332;COMBINING LOW LINE;Mn;220;NSM;;;;;N;NON-SPACING UNDERSCORE;;;;
218 006C;LATIN SMALL LETTER L;Ll;0;L;;;;;N;;;004C;;004C
219 0332;COMBINING LOW LINE;Mn;220;NSM;;;;;N;NON-SPACING UNDERSCORE;;;;
220 0069;LATIN SMALL LETTER I;Ll;0;L;;;;;N;;;0049;;0049
221 0332;COMBINING LOW LINE;Mn;220;NSM;;;;;N;NON-SPACING UNDERSCORE;;;;
222 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
223 0332;COMBINING LOW LINE;Mn;220;NSM;;;;;N;NON-SPACING UNDERSCORE;;;;
224 0065;LATIN SMALL LETTER E;Ll;0;L;;;;;N;;;0045;;0045
225 0332;COMBINING LOW LINE;Mn;220;NSM;;;;;N;NON-SPACING UNDERSCORE;;;;
226 0020;SPACE;Zs;0;WS;;;;;N;;;;;
227 0061;LATIN SMALL LETTER A;Ll;0;L;;;;;N;;;0041;;0041
228 006E;LATIN SMALL LETTER N;Ll;0;L;;;;;N;;;004E;;004E
229 0064;LATIN SMALL LETTER D;Ll;0;L;;;;;N;;;0044;;0044
230 0020;SPACE;Zs;0;WS;;;;;N;;;;;
231 0073;LATIN SMALL LETTER S;Ll;0;L;;;;;N;;;0053;;0053
232 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
233 0074;LATIN SMALL LETTER T;Ll;0;L;;;;;N;;;0054;;0054
234 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
235 0072;LATIN SMALL LETTER R;Ll;0;L;;;;;N;;;0052;;0052
236 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
237 0069;LATIN SMALL LETTER I;Ll;0;L;;;;;N;;;0049;;0049
238 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
239 006B;LATIN SMALL LETTER K;Ll;0;L;;;;;N;;;004B;;004B
240 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
241 0065;LATIN SMALL LETTER E;Ll;0;L;;;;;N;;;0045;;0045
242 0336;COMBINING LONG STROKE OVERLAY;Mn;1;NSM;;;;;N;NON-SPACING LONG BAR OVERLAY;;;;
243 002E;FULL STOP;Po;0;CS;;;;;N;PERIOD;;;;
244 000A;<control>;Cc;0;B;;;;;N;LINE FEED (LF);;;;
248 'Display combining chars',
251 # }}}
252 testcmd("echo feff 48 61 74 65 2e | fromhex -u | $CMD", # {{{
253 <<'END',
254 FEFF;ZERO WIDTH NO-BREAK SPACE;Cf;0;BN;;;;;N;BYTE ORDER MARK;;;;
255 0048;LATIN CAPITAL LETTER H;Lu;0;L;;;;;N;;;;0068;
256 0061;LATIN SMALL LETTER A;Ll;0;L;;;;;N;;;0041;;0041
257 0074;LATIN SMALL LETTER T;Ll;0;L;;;;;N;;;0054;;0054
258 0065;LATIN SMALL LETTER E;Ll;0;L;;;;;N;;;0045;;0045
259 002E;FULL STOP;Po;0;CS;;;;;N;PERIOD;;;;
263 'Display bloody BOM',
266 # }}}
268 todo_section:
271 if ($Opt{'all'} || $Opt{'todo'}) {
272 diag('Running TODO tests...'); # {{{
274 TODO: {
276 local $TODO = '';
277 # Insert TODO tests here.
280 # TODO tests }}}
283 diag('Testing finished.');
284 return $Retval;
285 # }}}
286 } # main()
288 sub testcmd {
289 # {{{
290 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
291 defined($descriptions{$Desc}) &&
292 BAIL_OUT("testcmd(): '$Desc' description is used twice");
293 $descriptions{$Desc} = 1;
294 my $stderr_cmd = '';
295 my $cmd_outp_str = $Opt{'verbose'} >= 1 ? "\"$Cmd\" - " : '';
296 my $Txt = join('', $cmd_outp_str, defined($Desc) ? $Desc : '');
297 my $TMP_STDERR = "$CMDB-stderr.tmp";
298 my $retval = 1;
300 if (defined($Exp_stderr)) {
301 $stderr_cmd = " 2>$TMP_STDERR";
303 $retval &= is(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
304 my $ret_val = $?;
305 if (defined($Exp_stderr)) {
306 $retval &= is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
307 unlink($TMP_STDERR);
308 } else {
309 diag("Warning: stderr not defined for '$Txt'");
311 $retval &= is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
313 return $retval;
314 # }}}
315 } # testcmd()
317 sub likecmd {
318 # {{{
319 my ($Cmd, $Exp_stdout, $Exp_stderr, $Exp_retval, $Desc) = @_;
320 defined($descriptions{$Desc}) &&
321 BAIL_OUT("likecmd(): '$Desc' description is used twice");
322 $descriptions{$Desc} = 1;
323 my $stderr_cmd = '';
324 my $cmd_outp_str = $Opt{'verbose'} >= 1 ? "\"$Cmd\" - " : '';
325 my $Txt = join('', $cmd_outp_str, defined($Desc) ? $Desc : '');
326 my $TMP_STDERR = "$CMDB-stderr.tmp";
327 my $retval = 1;
329 if (defined($Exp_stderr)) {
330 $stderr_cmd = " 2>$TMP_STDERR";
332 $retval &= like(`$Cmd$stderr_cmd`, $Exp_stdout, "$Txt (stdout)");
333 my $ret_val = $?;
334 if (defined($Exp_stderr)) {
335 $retval &= like(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
336 unlink($TMP_STDERR);
337 } else {
338 diag("Warning: stderr not defined for '$Txt'");
340 $retval &= is($ret_val >> 8, $Exp_retval, "$Txt (retval)");
342 return $retval;
343 # }}}
344 } # likecmd()
346 sub file_data {
347 # Return file content as a string {{{
348 my $File = shift;
349 my $Txt;
351 open(my $fp, '<', $File) or return undef;
352 local $/ = undef;
353 $Txt = <$fp>;
354 close($fp);
355 return $Txt;
356 # }}}
357 } # file_data()
359 sub print_version {
360 # Print program version {{{
361 print("$progname $VERSION\n");
362 return;
363 # }}}
364 } # print_version()
366 sub usage {
367 # Send the help message to stdout {{{
368 my $Retval = shift;
370 if ($Opt{'verbose'}) {
371 print("\n");
372 print_version();
374 print(<<"END");
376 Usage: $progname [options]
378 Contains tests for the $CMDB(1) program.
380 Options:
382 -a, --all
383 Run all tests, also TODOs.
384 -h, --help
385 Show this help.
386 -q, --quiet
387 Be more quiet. Can be repeated to increase silence.
388 -t, --todo
389 Run only the TODO tests.
390 -v, --verbose
391 Increase level of verbosity. Can be repeated.
392 --version
393 Print version information.
396 exit($Retval);
397 # }}}
398 } # usage()
400 sub msg {
401 # Print a status message to stderr based on verbosity level {{{
402 my ($verbose_level, $Txt) = @_;
404 $verbose_level > $Opt{'verbose'} && return;
405 print(STDERR "$progname: $Txt\n");
406 return;
407 # }}}
408 } # msg()
410 __END__
412 # This program is free software; you can redistribute it and/or modify
413 # it under the terms of the GNU General Public License as published by
414 # the Free Software Foundation; either version 2 of the License, or (at
415 # your option) any later version.
417 # This program is distributed in the hope that it will be useful, but
418 # WITHOUT ANY WARRANTY; without even the implied warranty of
419 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
420 # See the GNU General Public License for more details.
422 # You should have received a copy of the GNU General Public License
423 # along with this program.
424 # If not, see L<http://www.gnu.org/licenses/>.
426 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :