|
From: <per...@li...> - 2006-02-24 18:42:15
|
Update of /cvsroot/perl-flat/blokhead/t In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27297/t Modified Files: 01-regex.t Log Message: - updates to regex ops (especially handling extended [] characters) - added more regex tests - anchoring option to as_perl_regex - "contains" method for regexes (just pass off regex matching to perl ;)) Index: 01-regex.t =================================================================== RCS file: /cvsroot/perl-flat/blokhead/t/01-regex.t,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** 01-regex.t 12 Nov 2005 23:08:56 -0000 1.3 --- 01-regex.t 24 Feb 2006 18:42:09 -0000 1.4 *************** *** 1,3 **** ! use Test::More 'no_plan'; use FLAT; --- 1,3 ---- ! use Test::More tests => 65; use FLAT; *************** *** 8,32 **** sub regex { FLAT::Regex->new(@_) } ! is( "" . regex( "(((a)bc)def)ghi" ), "abcdefghi", "Collapse parens for concatenation" ); ! is( "" . regex( "(((a)+b+c)+d+e+f)+g+h+i" ), "a+b+c+d+e+f+g+h+i", "Collapse parens for alternation" ); ! is( "" . regex( "(a+(b+(cd)))*" ), ! "(a+b+cd)*", "Parens kept for precedence" ); ! is( "". regex("#"), "#", "Null regex" ); ! is( "". regex("[]"), "[]", "epsilon" ); ! for ( ")ab", "a(bc(d)", "ab)cd(ef", "a+b+", "a++b", "+a", "h**", "a+*" ) { eval { regex($_) }; ok( $@, --- 8,40 ---- sub regex { FLAT::Regex->new(@_) } ! is( regex( "(((a)bc)def)ghi" )->as_string, "abcdefghi", "Collapse parens for concatenation" ); ! is( regex( "(((a)+b+c)+d+e+f)+g+h+i" )->as_string, "a+b+c+d+e+f+g+h+i", "Collapse parens for alternation" ); ! is( regex( "((a+(b+(cd)))*)+e" )->as_string, ! "(a+b+cd)*+e", "Parens kept for precedence" ); ! is( regex("#")->as_string, "#", "Null regex" ); ! is( regex("[]")->as_string, "[]", "epsilon" ); ! is( regex("[#][ ][foo][*][a][1][23]")->as_string, ! "[#][ ][foo][*]a1[23]", ! "special [] characters as string" ); ! ! is( regex(" a\tb\nc \n\t d")->as_string, ! "abcd", ! "whitespace ignored" ); ! ! for ( ")ab", "a(bc(d)", "ab)cd(ef", "a+b+", "a++b", "+a", "h**", "a+*", "" ) { eval { regex($_) }; ok( $@, *************** *** 34,42 **** } - - $reg = regex( "abc+def+ghi*+(a+b)*" ); ! is( "" . $reg, ! "" . $reg->reverse->reverse, "Reversal operation idempotent" ); --- 42,48 ---- } $reg = regex( "abc+def+ghi*+(a+b)*" ); ! is( $reg->as_string, ! $reg->reverse->reverse->as_string, "Reversal operation idempotent" ); *************** *** 45,48 **** --- 51,66 ---- ok( regex("#")->is_empty, "is_empty (atomic)" ); + + ok( ! regex("[#]")->is_empty, + "is_empty (atomic)" ); + + ok( ! regex("[foo]")->is_empty, + "is_empty (atomic)" ); + + ok( ! regex("[]")->is_empty, + "is_empty (atomic)" ); + + ok( ! regex("[ ]")->is_empty, + "is_empty (atomic)" ); ok( regex("a#a")->is_empty, *************** *** 55,58 **** --- 73,79 ---- "is_empty (star)" ); + ok( ! regex("[#]*")->is_empty, + "is_empty (star)" ); + ok( ! regex("#+b")->is_empty, "is_empty (alternation)" ); *************** *** 62,65 **** --- 83,87 ---- + ok( regex("a")->is_finite, "is_finite (atomic)" ); *************** *** 71,74 **** --- 93,99 ---- "is_finite (star)" ); + ok( ! regex("[#]*")->is_finite, + "is_finite (star)" ); + ok( regex("[]*")->is_finite, "is_finite (star)" ); *************** *** 91,92 **** --- 116,138 ---- ok( ! regex("a*a")->is_finite, "is_finite (concatenation)" ); + + #### + + $reg = regex("ab(c|de|f*)(g|[])"); + my $p = $reg->as_perl_regex(anchored => 1); + + for (qw[ abcg abc abdeg abde ab abg abfffg abff ]) { + ok( /$p/, + "as_perl_regex (positives)" ); + + ok( $reg->contains($_), + "contains (positives)" ); + } + + for (qw[ aabcg ac abcdeg abdef abffgg ]) { + ok( ! /$p/, + "as_perl_regex (negatives)" ); + + ok( ! $reg->contains($_), + "contains (negatives)" ); + } |