OSDN Git Service

自動判別の状態を保持したまま変換を続ける nkf_continue を追加
[nkf/nkf.git] / test.pl
1 #!/usr/bin/perl
2 #
3 # nkf test program for nkf 2.0
4 #    Shinji KONO <kono@ie.u-ryukyu.ac.jp>
5 # Sun Aug 18 12:25:40 JST 1996
6 # Sun Nov  8 00:16:06 JST 1998
7 # Sun Sep  8 14:04:02 JST 2002
8 #
9 # This is useful when you add new patch on nkf.
10 # Since this test is too strict, faileurs may not mean
11 # wrong conversion. 
12 #
13 # nkf 2.0 utf8
14 # nkf 1.5 differs on MIME decoding
15 # nkf 1.4 passes Basic Conversion tests
16 # nkf PDS version passes Basic Conversion tests  using "nkf -iB -oB "
17 #
18
19 $nkf = "./nkf";
20 # $nkf = "doscmd nkf.exe";
21
22 # If you want to see the testing process, set next flag.
23
24 $detail_all = 0;
25 $error_count=1;
26 $diff=1;
27
28 # &library_test0();
29 sub test {
30     &command_test(@_);
31 }
32
33 sub command_test {
34     local ($nkf,$in,@ans) = @_;
35     local ($result);
36
37     $result = '';
38     open(OUT,"> nkf.in");
39     print OUT $in;
40     close(OUT);
41     system("$nkf <nkf.in >nkf.out");   # easy
42     open(IN,"< nkf.out");
43     while(<IN>) {
44         $result .= $_;
45     }
46     if( $nkf =~ /-m/) {
47         $result =~ s/ //g;
48     }
49     $i = 0;
50     foreach $ans (@ans) {
51         if( $nkf =~ /-m/) {
52             $ans =~ s/ //g;
53         }
54         if ($result eq $ans) {
55             print "Ok\n";
56             return $result;
57         }
58         $i++;
59     }
60     $ans = $ans[0];
61     print "Fail\n";
62     system "mv nkf.in nkf.in.$error_count.bad";
63     system "mv nkf.out nkf.out.$error_count.bad";
64     open(OUT,"> nkf.expect.$error_count.bad");
65     print OUT $ans;
66     close(OUT);
67     $error_count++;
68     if ($diff) {
69         open(R,"|od -c >tmp.result.bad"); print R $result; close(R);
70         open(R,"|od -c >tmp.expect.bad"); print R $ans; close(R);
71         system "diff -c tmp.result.bad tmp.expect.bad";
72     }
73     return $result;
74 }
75
76 do "nkf_test.pl";
77
78 unlink "nkf.in";
79 unlink "nkf.out";