diff options
author | Eric Wong <e@80x24.org> | 2021-03-23 11:02:17 +0600 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-03-24 01:33:26 +0000 |
commit | 5be0cb101bab44167a78af7a2d167f254c95bdb3 (patch) | |
tree | 133ed291d5caca9819d95217b0b512990257d225 /t | |
parent | e7d13d7bc4a7b1e990602e796b7c2acbddb99a7b (diff) | |
download | public-inbox-5be0cb101bab44167a78af7a2d167f254c95bdb3.tar.gz |
Only tested for keywords and labels with file inputs, so far; but it seems to do what it needs to do. There's a bit more redundant code than I'd like, and more opportunities for code sharing in the future "lei import" will be expanded to support +kw:$KEYWORD and +L:$LABEL in the future.
Diffstat (limited to 't')
-rw-r--r-- | t/lei-mark.t | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/t/lei-mark.t b/t/lei-mark.t new file mode 100644 index 00000000..ddf5634c --- /dev/null +++ b/t/lei-mark.t @@ -0,0 +1,47 @@ +#!perl -w +# Copyright (C) 2021 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +use strict; use v5.10.1; use PublicInbox::TestCommon; +require_git 2.6; +require_mods(qw(json DBD::SQLite Search::Xapian)); +my $check_kw = sub { + my ($exp, %opt) = @_; + my $mid = $opt{mid} // 'testmessage@example.com'; + lei_ok('q', "m:$mid"); + my $res = json_utf8->decode($lei_out); + is($res->[1], undef, 'only got one result'); + my $msg = $opt{msg} ? " $opt{msg}" : ''; + ($exp ? is_deeply($res->[0]->{kw}, $exp, "got @$exp$msg") + : is($res->[0]->{kw}, undef, "got undef$msg")) or + diag explain($res); +}; + +test_lei(sub { + lei_ok(qw(import -F eml t/utf8.eml)); + lei_ok(qw(mark -F eml t/utf8.eml +kw:flagged)); + $check_kw->(['flagged']); + ok(!lei(qw(mark -F eml t/utf8.eml +kw:seeen)), 'bad kw rejected'); + like($lei_err, qr/`seeen' is not one of/, 'got helpful error'); + ok(!lei(qw(mark -F eml t/utf8.eml +k:seen)), 'bad prefix rejected'); + ok(!lei(qw(mark -F eml t/utf8.eml)), 'no keywords'); + my $mb = "$ENV{HOME}/mb"; + my $md = "$ENV{HOME}/md"; + lei_ok(qw(q m:testmessage@example.com -o), "mboxrd:$mb"); + ok(-s $mb, 'wrote mbox result'); + lei_ok(qw(q m:testmessage@example.com -o), $md); + my @fn = glob("$md/cur/*"); + scalar(@fn) == 1 or BAIL_OUT 'no mail '.explain(\@fn); + rename($fn[0], "$fn[0]S") or BAIL_OUT "rename $!"; + $check_kw->(['flagged'], msg => 'after bad request'); + lei_ok(qw(mark -F eml t/utf8.eml -kw:flagged)); + $check_kw->(undef, msg => 'keyword cleared'); + lei_ok(qw(mark -F mboxrd +kw:seen), $mb); + $check_kw->(['seen'], msg => 'mbox Status ignored'); + lei_ok(qw(mark -kw:seen +kw:answered), $md); + $check_kw->(['answered'], msg => 'Maildir Status ignored'); + + open my $in, '<', 't/utf8.eml' or BAIL_OUT $!; + lei_ok([qw(mark -F eml - +kw:seen)], undef, { %$lei_opt, 0 => $in }); + $check_kw->(['answered', 'seen'], msg => 'stdin works'); +}); +done_testing; |