use CGI; use Getopt::Std; use vars qw($FS $FreeLinkPattern $UrlProtocols $UrlChars $EndChars $UrlPattern $q); $FS = "\x1e"; $FreeLinkPattern = "([-,.()' _0-9A-Za-z\x80-\xff]+)"; $UrlProtocols = 'http|https|ftp|afs|news|nntp|mid|cid|mailto|wais|prospero|telnet|gopher|irc'; $UrlChars = '[-a-zA-Z0-9/@=+$_~*.,;:?!\'"()%]'; # see RFC 2396 $EndChars = '[-a-zA-Z0-9/@=+$_~*]'; # no punctuation at the end of the url. $UrlPattern = "((?:$UrlProtocols):$UrlChars+$EndChars)"; $q = new CGI; getopts('v'); do "simple-rules.pl"; open(STDOUT,'> /dev/null') unless $opt_v; $| = 1; my $count = 0; my $total = 0; sub test { my ($input, $output) = @_; my @result = NewSimpleRulesApplyRules($input, 1); my $result = shift(@result); print " - @result\n" if $opt_v; if ($output ne $result) { $input .= "\n" unless substr($input,-1,1) eq "\n"; warn "$input -> $result\n != $output\n"; } else { $count++; } $total++; } sub GetPageOrEditLink { return "link<" . shift() . ">"; } test("test", "
test
"); test("foo\n\nbar", "foo
bar
"); test("test\n====\n", "foo\nbar
foo\nbar
"); test("* foo\n* bar\n* baz\n", "test foo
"); test("**test foo**", "test foo
"); test("//test foo//", "test foo
"); test("__test foo__", "test foo
"); test("*test* foo", "test foo
"); test("/test/ foo", "test foo
"); test("_test_ foo", "test foo
"); test("http://www.oddmuse.org/", ""); print "---> Expect linkthis is link
this is ${FS}[[foo]]${FS}.
"); # dirty block! print "---> Expectlink
${FS}[[foo]]${FS} and ${FS}[[bar]]${FS}
"); # dirty block! test("/test/ _test_ *test*", "test test test
"); test("[[foo]] /test/ _test_ *test*", "${FS}[[foo]]${FS} test test test
"); test("* some [[foo]]\n* [[bar]] and [[baz]]\n", "