Skip to content

Commit

Permalink
Switch to subtest()s so that we can easily count our tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Jul 27, 2012
1 parent 329fd26 commit 032711f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
37 changes: 18 additions & 19 deletions t/query.t
@@ -1,19 +1,19 @@
use Test::More 'no_plan';
use Test::More tests => 7;

use strict;
use warnings;

use WebService::Solr::Query;

{ # (un)escape
subtest 'Unescapes' => sub {
is( WebService::Solr::Query->escape( '(1+1):2' ),
'\(1\+1\)\:2', 'escape' );
is( WebService::Solr::Query->unescape( '\(1\+1\)\:2' ),
'(1+1):2', 'unescape' );
}
};

{ # basic queries
# default field
subtest 'Basic queries' => sub {
# default field
_check( query => { -default => 'space' }, expect => '("space")' );
_check(
query => { -default => [ 'star trek', 'star wars' ] },
Expand Down Expand Up @@ -53,18 +53,18 @@ use WebService::Solr::Query;
expect =>
'(("star trek" OR "star wars") AND (first:"Roger" OR first:"Dodger"))'
);
}
};

{ # basic query with escape
subtest 'Basic query with escape' => sub {
_check( query => { -default => 'sp(a)ce' }, expect => '("sp\(a\)ce")' );
_check(
query => { title => 'Spaceb(a)lls' },
expect => '(title:"Spaceb\(a\)lls")'
);
}
};

{ # simple ops
# range (inc)
subtest 'Simple ops' => sub {
# range (inc)
_check(
query => { title => { -range => [ 'a', 'z' ] } },
expect => '(title:[a TO z])'
Expand Down Expand Up @@ -129,10 +129,9 @@ use WebService::Solr::Query;
},
expect => '((first:"Roger" OR first:"Dodger") AND title:space~0.8)'
);
};

}

{ # ops with escape
subtest 'Ops with escape' => sub {
_check(
query => { title => { -boost => [ 'Sp(a)ce', '2.0' ] } },
expect => '(title:"Sp\(a\)ce"^2.0)'
Expand All @@ -145,9 +144,9 @@ use WebService::Solr::Query;
query => { title => { -fuzzy => [ 'sp(a)ce', '0.8' ] } },
expect => '(title:sp\(a\)ce~0.8)'
);
}
};

{ # require and prohibit
subtest 'Require and prohibit' => sub {
_check(
query => { title => { -require => 'star' } },
expect => '(+title:"star")'
Expand Down Expand Up @@ -176,10 +175,9 @@ use WebService::Solr::Query;
},
expect => '((first:"Roger" OR first:"Dodger") AND -title:"star")'
);
}
};

### nested and/or operators
{
subtest 'Nested and/or operators' => sub {
_check(
query => {
title =>
Expand All @@ -197,8 +195,9 @@ use WebService::Solr::Query;
},
expect => q[(((title:{a TO c}) OR (title:{e TO k})))],
);
};

}
done_testing();

sub _check {
my %t = @_;
Expand Down
37 changes: 17 additions & 20 deletions t/response.t
Expand Up @@ -2,7 +2,7 @@ use strict;
use warnings;

### XXX Whitebox tests!
use Test::More 'no_plan';
use Test::More tests => 5;

use HTTP::Headers;
use HTTP::Response;
Expand All @@ -19,18 +19,16 @@ my $SolrResponse = HTTP::Response->new(
);

my $Obj;
### create tests
{
ok( $SolrResponse, "Created dummy Solr response" );
subtest 'Create tests' => sub {
ok( $SolrResponse, 'Created dummy Solr response' );

$Obj = $Class->new( $SolrResponse );
ok( $Obj, " Created $Class object from $SolrResponse" );
isa_ok( $Obj, $Class, " Object" );
}
isa_ok( $Obj, $Class );
};

### check accessors
{
ok( $Obj, "Testing accessors" );
subtest 'Check accessors' => sub {
ok( $Obj, 'Testing accessors' );

for my $acc (
qw[status_code status_message is_success is_error content docs pager pageset]
Expand All @@ -39,21 +37,19 @@ my $Obj;
ok( $Obj->can( $acc ), " Obj->can( $acc )" );
ok( defined $Obj->$acc, " Value = " . $Obj->$acc );
}
}
};

### check docs
{
subtest 'Check docs' => sub {
for my $doc ( $Obj->docs ) {
ok( $doc, "Testing $doc" );
isa_ok( $doc, 'WebService::Solr::Document', " Object" );
isa_ok( $doc, 'WebService::Solr::Document' );

like( $doc->value_for( 'name' ),
qr/foo/, " Name = " . $doc->value_for( 'name' ) );
}
}
};

### check pagers
{
subtest 'Check pagers' => sub {
for my $pager ( $Obj->pager, $Obj->pageset,
$Obj->pageset( mode => 'fixed' ) )
{
Expand All @@ -64,10 +60,9 @@ my $Obj;
is( $pager->last_page, 5, " Last page = 5" );
is( $pager->current_page, 3, " Current page = 2" );
}
}
};

### special case: 0 rows
{
subtest 'Special case: 0 rows' => sub {
my $http_response = HTTP::Response->new(
200 => 'OK',
HTTP::Headers->new,
Expand All @@ -77,4 +72,6 @@ my $Obj;
my $solr_response = $Class->new( $http_response );
ok( !defined $solr_response->pager, '0 rows, undef pager' );
ok( !defined $solr_response->pageset, '0 rows, undef pageset' );
}
};

done_testing();

0 comments on commit 032711f

Please sign in to comment.