Browse Source

* add tests

master
Zubrikhin Alexey 10 years ago
parent
commit
d8ed7931f0
  1. 87
      t/regexps-blocks.t
  2. 61
      t/regexps-list.t
  3. 50
      t/regexps-table.t

87
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';
<code>
some code here
</code>
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';
<file pubkey.asc>
--- pgp block start ---
0YXRg9C5
--- pgp block end ---
</file>
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';
<code c main.c>
int main() { return 0; }
</code>
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;

61
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;

50
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;
Loading…
Cancel
Save