diff --git a/modules/simple-rules-test.pl b/modules/simple-rules-test.pl new file mode 100644 index 00000000..d497d3ee --- /dev/null +++ b/modules/simple-rules-test.pl @@ -0,0 +1,70 @@ +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", "

test

"); +test("test\n----\n", "

test

"); +test("foo\nbar\n\ntest\n----\n\nfoo\nbar\n", "

foo\nbar

test

foo\nbar

"); +test("* foo\n* bar\n* baz\n", ""); +test("1. foo\n2. bar\n3. baz\n", "
  1. foo
  2. bar
  3. baz
"); +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("_test_ foo", "

test foo

"); +test("http://www.oddmuse.org/", + "

http://www.oddmuse.org/

"); +print "---> Expect link on next line:\n" if $opt_v; +test("[[foo]]", "[[foo]]"); # dirty block! +print "---> Expect

this is link.

on next line:\n" if $opt_v; +test("this is [[foo]].", "

this is ${FS}[[foo]]${FS}.

"); # dirty block! +print "---> Expect

link and link

on next line:\n" if $opt_v; +test("[[foo]] and [[bar]]", "

${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", + ""); +warn "$count/$total passed.\n";