|
From: <jgr...@us...> - 2003-10-28 19:44:51
|
Update of /cvsroot/popfile/engine/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv17979/tests
Modified Files:
TestBayes.tst
Log Message:
Fix bug 826765
@ and $ inside magnets were not being handled properly.
Classifer/Bayes.pm:
Factor most of magnet_match__ into magnet_match_helper__ so
that there is no duplicated code. Remove use of regexps for
magnet match and replace with simple 'eq' matching, thus
eliminating all the complexities around special characters
in regexps and the fact that @ and $ are illegal in \Q \E
quoted regexps.
tests/TestBayes.tst:
Added tests for magnet_match__ with specific emphasis on
handling of $ and @.
Made Japanese tests detect whether Text::Kakasi is present
on the machine and ignore them (with a warning if it is
not present).
Index: TestBayes.tst
===================================================================
RCS file: /cvsroot/popfile/engine/tests/TestBayes.tst,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** TestBayes.tst 28 Oct 2003 17:32:36 -0000 1.32
--- TestBayes.tst 28 Oct 2003 19:39:48 -0000 1.33
***************
*** 350,353 ****
--- 350,388 ----
test_assert_equal( $magnets[0], 'bar' );
+ # magnet_match__
+
+ test_assert( $b->magnet_match__( 'foo', 'personal', 'from' ) );
+ test_assert( $b->magnet_match__( 'barfoo', 'personal', 'from' ) );
+ test_assert( $b->magnet_match__( 'foobar', 'personal', 'from' ) );
+ test_assert( $b->magnet_match__( 'oldstylemagnet', 'personal', 'from' ) );
+ test_assert( !$b->magnet_match__( 'fo', 'personal', 'from' ) );
+ test_assert( !$b->magnet_match__( 'fobar', 'personal', 'from' ) );
+ test_assert( !$b->magnet_match__( 'oldstylmagnet', 'personal', 'from' ) );
+
+ test_assert( $b->magnet_match__( 'ba...@ba...', 'personal', 'to' ) );
+ test_assert( $b->magnet_match__( 'do...@ba...', 'personal', 'to' ) );
+ test_assert( $b->magnet_match__( 'do...@ba...', 'personal', 'to' ) );
+ test_assert( !$b->magnet_match__( 'ba...@ba...', 'personal', 'to' ) );
+ test_assert( !$b->magnet_match__( 'do...@ba...', 'personal', 'to' ) );
+ test_assert( !$b->magnet_match__( 'do...@ba...', 'personal', 'to' ) );
+
+ $b->create_magnet( 'zeotrope', 'from', '@yahoo.com' );
+ test_assert( $b->magnet_match__( 'ba...@ya...', 'zeotrope', 'from' ) );
+ test_assert( $b->magnet_match__( 'fo...@ya...', 'zeotrope', 'from' ) );
+ test_assert( !$b->magnet_match__( 'fo...@ya...', 'zeotrope', 'from' ) );
+ $b->delete_magnet( 'zeotrope', 'from', '@yahoo.com' );
+
+ $b->create_magnet( 'zeotrope', 'from', '__r' );
+ test_assert( !$b->magnet_match__( 'ba...@ra...', 'zeotrope', 'from' ) );
+ test_assert( $b->magnet_match__( '@__r', 'zeotrope', 'from' ) );
+ $b->delete_magnet( 'zeotrope', 'from', '__r' );
+
+ $b->create_magnet( 'zeotrope', 'from', 'foo$bar' );
+ test_assert( !$b->magnet_match__( 'foo@bar', 'zeotrope', 'from' ) );
+ test_assert( !$b->magnet_match__( 'foo$baz', 'zeotrope', 'from' ) );
+ test_assert( $b->magnet_match__( 'foo$bar', 'zeotrope', 'from' ) );
+ test_assert( $b->magnet_match__( 'foo$barum', 'zeotrope', 'from' ) );
+ $b->delete_magnet( 'zeotrope', 'from', 'foo$bar' );
+
# get_magnet_types
***************
*** 748,791 ****
test_assert_equal( $magnet, '' );
- # TODO Check that magnet_match__ does what we expect in the presence of @
- # and $
-
# TODO test that stop writes the parameters to disk
# Test Japanese mode
! $b->module_config_( 'html', 'language', 'Nihongo' );
! # Test Japanese magnet. GOMI means "trash" in Japanese.
! $b->create_bucket( 'gomi' );
! # create_magnet
! $b->clear_magnets();
! $b->create_magnet( 'gomi', 'subject', chr(0xcc) . chr(0xa4) );
! test_assert_equal( $b->classify( 'TestMailParse026.msg' ), 'gomi' );
! test_assert_equal( $b->magnet_count(), 1 );
! $b->create_magnet( 'gomi', 'subject', chr(0xa5) . chr(0xc6) . chr(0xa5) . chr(0xb9) . chr(0xa5) . chr(0xc8));
! test_assert_equal( $b->magnet_count(), 2 );
! # get_magnets
! my @magnets = $b->get_magnets( 'gomi', 'subject' );
! test_assert_equal( $#magnets, 1 );
! test_assert_equal( $magnets[0], chr(0xa5) . chr(0xc6) . chr(0xa5) . chr(0xb9) . chr(0xa5) . chr(0xc8) );
! test_assert_equal( $magnets[1], chr(0xcc) . chr(0xa4) );
! # Test whether Japanese mail are splitted into words by Kakasi filter
! open CLIENT, ">temp.tmp";
! open MAIL, "<TestMailParse026.msg";
! my ( $class, $nopath ) = $b->classify_and_modify( \*MAIL, \*CLIENT, 0, 0, 0, '', 1 );
! close CLIENT;
! close MAIL;
! open MSG, "<messages/popfile0=0.msg";
! open KKS, "<TestMailParse026.kks";
! while ( <MSG> ) {
my $msg = $_;
my $kks = <KKS>;
--- 783,836 ----
test_assert_equal( $magnet, '' );
# TODO test that stop writes the parameters to disk
+
# Test Japanese mode
! my $have_text_kakasi = 0;
! foreach my $prefix (@INC) {
! my $realfilename = "$prefix/Text/Kakasi.pm";
! if (-f $realfilename) {
! $have_text_kakasi = 1;
! last;
! }
! }
! if ( $have_text_kakasi ) {
! $b->module_config_( 'html', 'language', 'Nihongo' );
! # Test Japanese magnet. GOMI means "trash" in Japanese.
! $b->create_bucket( 'gomi' );
! # create_magnet
! $b->clear_magnets();
! $b->create_magnet( 'gomi', 'subject', chr(0xcc) . chr(0xa4) );
! test_assert_equal( $b->classify( 'TestMailParse026.msg' ), 'gomi' );
! test_assert_equal( $b->magnet_count(), 1 );
! $b->create_magnet( 'gomi', 'subject', chr(0xa5) . chr(0xc6) . chr(0xa5) . chr(0xb9) . chr(0xa5) . chr(0xc8));
! test_assert_equal( $b->magnet_count(), 2 );
! # get_magnets
! my @magnets = $b->get_magnets( 'gomi', 'subject' );
! test_assert_equal( $#magnets, 1 );
! test_assert_equal( $magnets[0], chr(0xa5) . chr(0xc6) . chr(0xa5) . chr(0xb9) . chr(0xa5) . chr(0xc8) );
! test_assert_equal( $magnets[1], chr(0xcc) . chr(0xa4) );
!
! # Test whether Japanese mail are splitted into words by Kakasi filter
!
! open CLIENT, ">temp.tmp";
! open MAIL, "<TestMailParse026.msg";
! my ( $class, $nopath ) = $b->classify_and_modify( \*MAIL, \*CLIENT, 0, 0, 0, '', 1 );
! close CLIENT;
! close MAIL;
!
! open MSG, "<messages/popfile0=0.msg";
! open KKS, "<TestMailParse026.kks";
! while ( <MSG> ) {
my $msg = $_;
my $kks = <KKS>;
***************
*** 793,834 ****
$kks =~ s/[\r\n]//g;
test_assert_equal( $msg, $kks );
! }
! close MSG;
! close KKS;
! unlink( 'messages/popfile0=0.msg' );
! unlink( 'messages/popfile0=0.cls' );
! unlink( 'temp.out' );
! # add_message_to_bucket
! my %words;
! open WORDS, "<TestMailParse026.wrd";
! while ( <WORDS> ) {
if ( /(.+) (\d+)/ ) {
! $words{$1} = $2;
}
! }
! close WORDS;
! test_assert( $b->add_message_to_bucket( 'gomi', 'TestMailParse026.kks' ) );
! foreach my $word (keys %words) {
test_assert_equal( $b->get_base_value_( 'gomi', $word ), $words{$word}, "gomi: $word $words{$word}" );
! }
!
! # get_bucket_word_prefixes
! my @words = $b->get_bucket_word_prefixes( 'gomi' );
! test_assert_equal( $#words, 19 );
! test_assert_equal( $words[17], chr(0xa4) . chr(0xb3) );
! test_assert_equal( $words[18], chr(0xa4) . chr(0xc7) );
! test_assert_equal( $words[19], chr(0xa5) . chr(0xb9) );
! # remove_message_from_bucket
! test_assert( $b->remove_message_from_bucket( 'gomi', 'TestMailParse026.kks' ) );
! test_assert_equal( $b->get_bucket_word_count( 'gomi' ), 0 );
$b->stop();
--- 838,881 ----
$kks =~ s/[\r\n]//g;
test_assert_equal( $msg, $kks );
! }
! close MSG;
! close KKS;
! unlink( 'messages/popfile0=0.msg' );
! unlink( 'messages/popfile0=0.cls' );
! unlink( 'temp.out' );
! # add_message_to_bucket
! my %words;
! open WORDS, "<TestMailParse026.wrd";
! while ( <WORDS> ) {
if ( /(.+) (\d+)/ ) {
! $words{$1} = $2;
}
! }
! close WORDS;
! test_assert( $b->add_message_to_bucket( 'gomi', 'TestMailParse026.kks' ) );
! foreach my $word (keys %words) {
test_assert_equal( $b->get_base_value_( 'gomi', $word ), $words{$word}, "gomi: $word $words{$word}" );
! }
! # get_bucket_word_prefixes
! my @words = $b->get_bucket_word_prefixes( 'gomi' );
! test_assert_equal( $#words, 19 );
! test_assert_equal( $words[17], chr(0xa4) . chr(0xb3) );
! test_assert_equal( $words[18], chr(0xa4) . chr(0xc7) );
! test_assert_equal( $words[19], chr(0xa5) . chr(0xb9) );
! # remove_message_from_bucket
+ test_assert( $b->remove_message_from_bucket( 'gomi', 'TestMailParse026.kks' ) );
+ test_assert_equal( $b->get_bucket_word_count( 'gomi' ), 0 );
+ } else {
+ print "Warning: Japanese tests skipped because Text::Kakasi was not found\n";
+ }
$b->stop();
|