Skip to content

Commit

Permalink
Add tests for search with valued tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Dec 15, 2016
1 parent cca2e46 commit 1654f4b
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions t/06search.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,52 @@ is_deeply( search_tags( 'foo', 'file[foo].txt', 'test[bar].txt' ),
is_deeply( search_tags( 'bar || foo', 'file[foo].txt', 'test[bar].txt' ),
[ 'file[foo].txt', 'test[bar].txt' ] );

is_deeply( search_tags( 'year', 'file[year=2009].txt' ),
['file[year=2009].txt'] );
is_deeply( search_tags( 'year=2009', 'file[year=2009].txt' ),
['file[year=2009].txt'] );
is_deeply( search_tags( 'year=2008', 'file[year=2009].txt' ), [] );
is_deeply( search_tags( 'year>2008', 'file[year=2009].txt' ),
['file[year=2009].txt'] );
is_deeply( search_tags( 'year<2010', 'file[year=2009].txt' ),
['file[year=2009].txt'] );
is_deeply( search_tags( 'year>2010', 'file[year=2009].txt' ), [] );
is_deeply( search_tags( 'year>2010', 'file[foo].txt' ), [] );
is_deeply( search_tags( 'author=mdom', 'file[author=mdom].txt' ),
['file[author=mdom].txt'] );
is_deeply( search_tags( '!author=mdom', 'file[author=mdom].txt' ), [] );

BEGIN {
*CORE::GLOBAL::exit = sub (;$) { }
}

sub capture {
my $code = shift;
my $got;
local *STDOUT;
open STDOUT, '>', \$got;
local *STDERR;
open STDERR, '>', \$got;
eval { $code->(); };
if ($@) {
$got .= $@;
}
return $got;
}

is capture( sub { search_tags( 'author < mdom', 'file[author=mdom].txt' ) } ), <<EOF;
Operand mdom isn't numeric in numerical comparison.
EOF
is capture( sub { search_tags( 'author > mdom', 'file[author=mdom].txt' ) } ), <<EOF;
Operand mdom isn't numeric in numerical comparison.
EOF

is capture( sub { search_tags( 'author > ', 'file[author=mdom].txt' ) } ), <<EOF;
No operand on right side of author.
EOF

is capture( sub { search_tags( 'author > &&', 'file[author=mdom].txt' ) } ), <<EOF;
No operand on right side of author.
EOF

done_testing;

0 comments on commit 1654f4b

Please sign in to comment.