+ for (my $i = 0; $i <= $#tests; $i += 3){
+ my $nkf = $tests[$i];
+ $in = $tests[$i+1];
+ $ans = $tests[$i+2];
+ $out = '';
+ open(OUT, "> nkf.in");
+ binmode OUT;
+ print OUT $in;
+ close(OUT);
+ system("$nkf <nkf.in >nkf.out"); # easy
+ open(IN,"< nkf.out");
+ binmode IN;
+ while (<IN>) {
+ $out .= $_;
+ }
+ close(IN);
+ $out =~ s/ //g if $nkf =~ /-\w+m[NS]/o;
+ $ans =~ s/ //g if $nkf =~ /-\w+m[NS]/o;
+ if ($out ne $ans) {
+ last;
+ }
+ }
+ if ($out eq $ans) {
+ print "Ok\n";
+ return;
+ }
+ print "Fail\n";
+ system "mv nkf.in nkf.in.$error_count.bad";
+ system "mv nkf.out nkf.out.$error_count.bad";
+ open(OUT,"> nkf.expect.$error_count.bad");
+ binmode OUT;
+ print OUT $ans;
+ close(OUT);
+ $error_count++;
+ if ($diff) {
+ open(R,"|od -c >tmp.result.bad"); binmode R; print R $out; close(R);
+ open(R,"|od -c >tmp.expect.bad"); binmode R; print R $ans; close(R);
+ system "diff -c tmp.result.bad tmp.expect.bad";
+ }
+ return;
+}
+
+do "nkf_test.pl";