3 # Requires perl-Test-Simple installation.
4 use Test::Simple tests => 22;
7 if (-e "../dos2unix.exe") {
10 $DOS2UNIX = "../dos2unix" . $suffix;
11 $MAC2UNIX = "../mac2unix" . $suffix;
12 $UNIX2DOS = "../unix2dos" . $suffix;
13 $UNIX2MAC = "../unix2mac" . $suffix;
15 $ENV{'LC_ALL'} = 'en_US.UTF-8';
17 system("$DOS2UNIX -v -7 -n chardos.txt out_unix.txt; cmp out_unix.txt charu7.txt");
20 system("$DOS2UNIX -v < dos.txt > out_unix.txt; cmp out_unix.txt unix.txt");
21 ok( $? == 0, 'DOS to Unix conversion, stdin/out' );
23 system("$UNIX2DOS -v < unix.txt > out_dos.txt; cmp out_dos.txt dos.txt");
24 ok( $? == 0, 'Unix to DOS conversion, stdin/out' );
26 system("cat utf16le.txt | $DOS2UNIX -v > out_unix.txt; cmp out_unix.txt utf8unix.txt");
27 ok( $? == 0, 'UTF-16LE with BOM to UTF-8, stdin/out' );
29 system("cat utf16u.txt | $UNIX2DOS -v -u > out_dos.txt; cmp out_dos.txt utf16.txt");
30 ok( $? == 0, 'UTF-16LE with BOM to UTF-16LE, stdin/out' );
32 system("$DOS2UNIX -v -n utf16len.txt out_bin.txt");
33 # file out_bin.txt may not exist.
34 if (-e "out_bin.txt") {
39 ok( $exists == 0, 'dos2unix skip binary file.' );
41 system("$UNIX2DOS -v -n utf16len.txt out_bin.txt");
42 # file out_bin.txt may not exist.
43 if (-e "out_bin.txt") {
48 ok( $exists == 0, 'unix2dos skip binary file.' );
50 system("$DOS2UNIX -v < utf16len.txt > out.txt");
52 ok( $result == 1, 'Dos2unix stdio returns error on binary input.' );
54 system("$UNIX2DOS -v < utf16len.txt > out.txt");
56 ok( $result == 1, 'Unix2dos stdio returns error on binary input.' );
58 system("rm -f out_forc.txt");
59 system("$DOS2UNIX -f -v -n utf16len.txt out_forc.txt");
60 # file out_bin.txt may not exist.
61 if (-e "out_forc.txt") {
66 ok( $exists == 1, 'dos2unix force binary file.' );
68 system("rm -f out_forc.txt");
69 system("$UNIX2DOS -f -v -n utf16len.txt out_forc.txt");
70 # file out_bin.txt may not exist.
71 if (-e "out_forc.txt") {
76 ok( $exists == 1, 'unix2dos force binary file.' );
78 system("$DOS2UNIX -v -f -n dos_bin.txt out_unix.txt; cmp out_unix.txt unix_bin.txt");
79 ok( $? == 0, 'Dos2unix, force ASCII file with binary symbols' );
81 system("$UNIX2DOS -v -f -n unix_bin.txt out_dos.txt; cmp out_dos.txt dos_bin.txt");
82 ok( $? == 0, 'Unix2dos, force ASCII file with binary symbols' );
84 system("$DOS2UNIX -v -7 -n utf16le.txt out_unix.txt chardos.txt out_u7.txt; cmp out_unix.txt utf8unix.txt");
85 ok( $? == 0, '7bit disabled for utf16');
87 system("cmp out_u7.txt charu7.txt");
88 ok( $? == 0, '7bit enabled again, dos2unix');
90 system("$UNIX2DOS -v -7 -n utf8unxb.txt out_dos.txt charunix.txt out_d7.txt; cmp out_dos.txt utf8dos.txt");
91 ok( $? == 0, '7bit disabled for utf8 with BOM');
93 system("cmp out_d7.txt chard7.txt");
94 ok( $? == 0, '7bit enabled again, unix2dos');
96 system("$UNIX2DOS -v -u -m -n unix.txt out_dos.txt; cmp out_dos.txt dos_bom.txt");
97 ok( $? == 0, 'Option -u must not disable -m on ASCII input');
99 system("$DOS2UNIX -i dos.txt unix.txt mac.txt mixed.txt utf16le.txt utf16be.txt utf16len.txt utf8unix.txt utf8dos.txt gb18030.txt > outinfo.txt");
100 system("$DOS2UNIX outinfo.txt; diff info.txt outinfo.txt");
101 ok( $? == 0, 'Option -i, --info');
103 system("$DOS2UNIX -ul -i utf16le.txt utf16len.txt utf8unxb.txt gb18030.txt > outinfo.txt");
104 system("$DOS2UNIX outinfo.txt; diff info_ul.txt outinfo.txt");
105 ok( $? == 0, 'Option -i, --info combined with -ul');
107 system("$DOS2UNIX -ub -i utf16be.txt utf16ben.txt utf8unxb.txt gb18030.txt > outinfo.txt");
108 system("$DOS2UNIX outinfo.txt; diff info_ub.txt outinfo.txt");
109 ok( $? == 0, 'Option -i, --info combined with -ub');
111 system("$DOS2UNIX -v -n gb18030.txt out_unix.txt; cmp out_unix.txt gb18030u.txt");
112 ok( $? == 0, 'Remove GB18030 BOM');