From d8ed7931f0cfb7f4068aa9e4f0a4770951103a77 Mon Sep 17 00:00:00 2001 From: Zubrikhin Alexey Date: Fri, 26 Jun 2015 18:04:15 +1000 Subject: [PATCH] * add tests --- t/regexps-blocks.t | 87 ++++++++++++++++++++++++++++++++++++++++++++++ t/regexps-list.t | 61 ++++++++++++++++++++++++++++++++ t/regexps-table.t | 50 ++++++++++++++++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 t/regexps-blocks.t create mode 100644 t/regexps-list.t create mode 100644 t/regexps-table.t diff --git a/t/regexps-blocks.t b/t/regexps-blocks.t new file mode 100644 index 0000000..74e0d5a --- /dev/null +++ b/t/regexps-blocks.t @@ -0,0 +1,87 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; + +use Test::More tests => 30; +use Text::Dokuwiki::Regexps; + +my $rx = $Text::Dokuwiki::Regexps::regexps; +my $text = <<'TEXT'; + +>> are you ok? + > sure! + > not matched + +TEXT + +my $matched = <<'TEXT'; +>> are you ok? + > sure! +TEXT +my @matches = ($text =~ $rx->{blockquote}); +is(scalar @matches, 1); +is($matches[0], $matched); +is($+{block}, $matched); + +$text = <<'TEXT'; + + some code here + +TEXT +$matched = <<'TEXT'; + some code here +TEXT +@matches = ($text =~ $rx->{codeblock}); +is(scalar @matches, 4); +is($matches[0], 'code'); # tag name +is($matches[1], undef); # syntax (missing) +is($matches[2], undef); # filename (missing) +is($matches[3], $matched); +is($+{tag}, 'code'); +is($+{block}, $matched); +is($+{syntax}, undef); +is($+{filename}, undef); + +$text = <<'TEXT'; + +--- pgp block start --- +0YXRg9C5 +--- pgp block end --- + +TEXT +$matched = <<'TEXT'; +--- pgp block start --- +0YXRg9C5 +--- pgp block end --- +TEXT +@matches = ($text =~ $rx->{codeblock}); +is(scalar @matches, 4); +is($matches[0], 'file'); # tag name +is($matches[1], undef); # syntax (missing) +is($matches[2], 'pubkey.asc'); # filename +is($matches[3], $matched); +is($+{tag}, 'file'); +is($+{block}, $matched); +is($+{syntax}, undef); +is($+{filename}, 'pubkey.asc'); + +$text = <<'TEXT'; + +int main() { return 0; } + +TEXT +$ matched = "int main() { return 0; }\n"; +@matches = ($text =~ $rx->{codeblock}); +is(scalar @matches, 4); +is($matches[0], 'code'); # tag name +is($matches[1], 'c'); # syntax +is($matches[2], 'main.c'); # filename +is($matches[3], $matched); +is($+{tag}, 'code'); +is($+{block}, $matched); +is($+{syntax}, 'c'); +is($+{filename}, 'main.c'); + +exit 0; diff --git a/t/regexps-list.t b/t/regexps-list.t new file mode 100644 index 0000000..9c8c3a0 --- /dev/null +++ b/t/regexps-list.t @@ -0,0 +1,61 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; + +use Test::More tests => 8; +use Text::Dokuwiki::Regexps; + +my $rx = $Text::Dokuwiki::Regexps::regexps; +my $text = <<'TEXT'; + + - item 1 + - item 2 + * item 1 level 2 + * item 2 level 2 + - item 3 + +TEXT + +my $matched = <<'TEXT'; + - item 1 + - item 2 + * item 1 level 2 + * item 2 level 2 + - item 3 +TEXT + +my @matches = $text =~ m/$rx->{list}/; +is($+{list}, $matched); +is(scalar @matches, 1); + +$text = <<'TEXT'; + + - not enough identation + +TEXT +@matches = $text =~ m/$rx->{list}/; +is(scalar @matches, 0); + +$text = <<'TEXT'; + - item + * item +TEXT +@matches = $text =~ m/$rx->{list}/; +is(scalar @matches, 1); +is($matches[0], $text); + +$text = <<'TEXT'; + + wrong item marker + +TEXT +@matches = $text =~ m/$rx->{list}/; +is(scalar @matches, 0); + +$text = ' * missing newline'; +@matches = $text =~ m/$rx->{list}/; +is(scalar @matches, 1); +is($matches[0], $text); + +exit 0; diff --git a/t/regexps-table.t b/t/regexps-table.t new file mode 100644 index 0000000..735781b --- /dev/null +++ b/t/regexps-table.t @@ -0,0 +1,50 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; + +use Test::More tests => 8; +use Text::Dokuwiki::Regexps; + +my $rx = $Text::Dokuwiki::Regexps::regexps; +my $text = <<'TEXT'; + +^ header ^ header ^ + | data | data | + +TEXT + +my $matched = <<'TEXT'; +^ header ^ header ^ + | data | data | +TEXT + +my @matches = $text =~ m/$rx->{table}/; +is(scalar @matches, 1); +is($+{table}, $matched); +is($matches[0], $matched); + +$text = <<'TEXT'; +^ header ^ header ^ + | data | data | missing trailing border +TEXT +@matches = $text =~ m/$rx->{table}/; +is(scalar @matches, 1); +is($matches[0], "^ header ^ header ^\n"); + +$text = <<'TEXT'; +^ header ^ header ^ + missing leading border | data | data | +TEXT +@matches = $text =~ m/$rx->{table}/; +is(scalar @matches, 1); +is($matches[0], "^ header ^ header ^\n"); + +$text = <<'TEXT'; + ^ not match, two leading spaces | +TEXT +@matches = $text =~ m/$rx->{table}/; +is(scalar @matches, 0); + +exit 0;