OSDN Git Service

* -s is now alias of Windows-31J.
[nkf/nkf.git] / NKF.mod / 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:03:28 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 $diff = 1;
26
27 &library_test0();
28 sub test  {
29     use NKF;
30     &library_test(@_);
31 }
32
33 sub library_test {
34     local ($nkf,$in,@ans) = @_;
35     local ($result);
36
37
38     # $nkf =~ s/^[^_]* //;
39     local (@nkf) = split(/ /,$nkf);
40     shift(@nkf);
41     print "\nINPUT:\n",$in  if ($detail || $detail_all);
42     print "\nEXPECT:\n", $ans if ($detail || $detail_all);
43     $result = NKF::nkf(@nkf,$in);
44     print "\nGOT:\n",$result if ($detail || $detail_all);
45
46     if( $nkf =~ /-\S*m/) {
47         $result =~ s/ //g;
48     }
49     $i = -1;
50     foreach $ans (@ans) {
51         $i++;
52         if( $nkf =~ /-\S*m/) {
53             $ans =~ s/ //g;
54         }
55         if ($result eq $ans){
56             print "Ok\n";
57             return $result;
58         }
59     }
60     $ans = @ans[$i];
61
62     print "Fail\n";
63     if ($diff) {
64         open(R,"|od -c >tmp.result.bad"); binmode R; print R $result; close(R);
65         open(R,"|od -c >tmp.expect.bad"); binmode R; print R $ans; close(R);
66         print"$i\n;$result\n;$ans\n" if $nkf[0] eq'-w16B';
67         system "diff -c tmp.result.bad tmp.expect.bad";
68     }
69     return $result;
70 }
71
72 sub library_test0 {
73 BEGIN { $| = 1; print "1..3\n"; }
74 END {print "not ok 1\n" unless $loaded;}
75     use NKF;
76     $loaded = 1;
77     print "ok 1\n";
78
79     ######################### End of black magic.
80
81     # Insert your test code below (better if it prints "ok 13"
82     # (correspondingly "not ok 13") depending on the success of chunk 13
83     # of the test code):
84
85     if ( nkf("-m","-e","1") ) {
86         print "ok 2\n";
87     } else {
88         print "no 2\n";
89     }
90
91     $output = nkf("\033\$@#1#3#2%B");
92     if ($output) {
93     # print $output,"\n";
94         print "ok 3\n";
95     } else {
96         print "no 3\n";
97     }
98
99     $output = nkf("-Zj","\033\$@#1#3#2%B");
100     if ($output) {
101     # print $output,"\n";
102         print "ok 4\n";
103     } else {
104         print "no 4\n";
105     }
106
107     # conversion makes strings longer
108     $output = "\244\306 " x 1024;
109         $old =  length($output);
110     $output = nkf("-j",$output);
111     if ($output) {
112     # print $output,"\n";
113         print "ok 5 $old ",length($output),"\n";
114     } else {
115         print "no 5\n";
116     }
117
118
119 }
120
121 do "../nkf_test.pl";