diff options
Diffstat (limited to 't')
-rw-r--r-- | t/msgmap.t | 14 | ||||
-rw-r--r-- | t/nntp.t | 64 |
2 files changed, 76 insertions, 2 deletions
@@ -12,6 +12,8 @@ my $d = PublicInbox::Msgmap->new($tmpdir, 1); my %mid2num; my %num2mid; my @mids = qw(a@b c@d e@f g@h aa@bb aa@cc); +is_deeply([$d->minmax], [undef,undef], "empty min max on new DB"); + foreach my $mid (@mids) { my $n = $d->mid_insert($mid); ok($n, "mid $mid inserted"); @@ -23,6 +25,7 @@ $@ = undef; eval { $d->mid_insert('a@b') }; ok($@, 'error raised when attempting duplicate message ID'); + foreach my $n (keys %num2mid) { is($d->mid_for($n), $num2mid{$n}, "num:$n maps correctly"); } @@ -47,7 +50,14 @@ is($d->mid_delete('a@b') + 0, 0, 'delete again returns zero'); is(undef, $d->num_for('a@b'), 'num_for fails on deleted msg'); $d = undef; -# idempotent -ok(PublicInbox::Msgmap->new($tmpdir, 1), 'idempotent DB creation'); +ok($d = PublicInbox::Msgmap->new($tmpdir, 1), 'idempotent DB creation'); +my ($min, $max) = $d->minmax; +ok($min > 0, "article min OK"); +ok($max > 0 && $max < 10, "article max OK"); +ok($min < $max, "article counts OK"); + +my $orig = $d->mid_insert('spam@1'); +$d->mid_delete('spam@1'); +is($d->mid_insert('spam@2'), 1 + $orig, "last number not recycled"); done_testing(); diff --git a/t/nntp.t b/t/nntp.t new file mode 100644 index 00000000..82918ff5 --- /dev/null +++ b/t/nntp.t @@ -0,0 +1,64 @@ +# Copyright (C) 2015 all contributors <meta@public-inbox.org> +# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) +use strict; +use warnings; +use Test::More; +use Data::Dumper; + +use_ok 'PublicInbox::NNTP'; + +{ + sub quote_str { + my (undef, $s) = split(/ = /, Dumper($_[0]), 2); + $s =~ s/;\n//; + $s; + } + + sub wm_prepare { + my ($wm) = @_; + my $orig = qq{'$wm'}; + PublicInbox::NNTP::wildmat2re($_[0]); + my $new = quote_str($_[0]); + ($orig, $new); + } + + sub wildmat_like { + my ($str, $wm) = @_; + my ($orig, $new) = wm_prepare($wm); + like($str, $wm, "$orig matches '$str' using $new"); + } + + sub wildmat_unlike { + my ($str, $wm, $check_ex) = @_; + if ($check_ex) { + use re 'eval'; + my $re = qr/$wm/; + like($str, $re, "normal re with $wm matches, but ..."); + } + my ($orig, $new) = wm_prepare($wm); + unlike($str, $wm, "$orig does not match '$str' using $new"); + } + + wildmat_like('[foo]', '[\[foo\]]'); + wildmat_like('any', '*'); + wildmat_unlike('bar.foo.bar', 'foo.*'); + + # no code execution + wildmat_unlike('HI', '(?{"HI"})', 1); + wildmat_unlike('HI', '[(?{"HI"})]', 1); +} + +{ + sub ngpat_like { + my ($str, $pat) = @_; + my $orig = $pat; + PublicInbox::NNTP::ngpat2re($pat); + like($str, $pat, "'$orig' matches '$str' using $pat"); + } + + ngpat_like('any', '*'); + ngpat_like('a.s.r', 'a.t,a.s.r'); + ngpat_like('a.s.r', 'a.t,a.s.*'); +} + +done_testing(); |