[BACK]Return to GET.t CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo-REST-API / t

Annotation of todotxt/Text-Todo-REST-API/t/GET.t, Revision 1.4

1.1       andrew      1: #===============================================================================
                      2: #
                      3: #         FILE:  GET.t
                      4: #
                      5: #  DESCRIPTION:  Test Text::Todo::REST::API
                      6: #
                      7: #       AUTHOR:  Andrew Fresh (AAF), andrew@cpan.org
                      8: #      COMPANY:  Red River Communications
                      9: #      CREATED:  01/07/10 19:11
1.4     ! andrew     10: #     REVISION:  $AFresh1: GET.t,v 1.3 2010/01/17 21:07:26 andrew Exp $
1.1       andrew     11: #===============================================================================
                     12:
                     13: use strict;
                     14: use warnings;
                     15:
1.3       andrew     16: use Test::More tests => 16;
                     17: use Data::Dumper;
1.1       andrew     18:
                     19: my $class;
1.3       andrew     20:
1.1       andrew     21: BEGIN {
                     22:     $class = 'Text::Todo::REST::API';
                     23:     use_ok( $class, "use $class" );
                     24: }
                     25:
                     26: diag("Testing GET $class $Text::Todo::REST::API::VERSION");
                     27:
1.3       andrew     28: my $list_should_be = [
                     29:     {   'text' => '(A) entry 1 @one +uno',
                     30:         'md5'  => '931e0831c31a70928b29de55778dc294',
                     31:         'line' => 1
                     32:     },
                     33:     {   'text' => 'entry 2 @two +dos',
                     34:         'md5'  => 'b38dde8029c047e81379d9de581a6251',
                     35:         'line' => 2
                     36:     },
                     37:     {   'text' => '',
                     38:         'md5'  => 'd41d8cd98f00b204e9800998ecf8427e',
                     39:         'line' => 3
                     40:     },
                     41:     {   'text' => 'x completed entry 4',
                     42:         'md5'  => '8de0a2b65a50d5e30e84ad48af46fa78',
                     43:         'line' => 4
                     44:     },
                     45:     {   'text' => '(B) entry 5 is priority',
                     46:         'md5'  => 'c1692dfbf3b5829b6bce44b1a1614980',
                     47:         'line' => 5
                     48:     },
                     49:     {   'text' => 'entry 6 +delete',
                     50:         'md5'  => 'e1f6bf867f75aa019063782554407d02',
                     51:         'line' => 6
                     52:     }
                     53: ];
                     54:
                     55: my @pass = (
1.4     ! andrew     56:     {   path_info => '',
1.3       andrew     57:         result => ['todo.txt'],
                     58:     },
1.4     ! andrew     59:     {   path_info => '/todo',
1.3       andrew     60:         result => $list_should_be,
                     61:     },
1.4     ! andrew     62:     {   path_info => '/todo/list',
1.3       andrew     63:         result => $list_should_be,
                     64:     },
                     65: );
                     66:
                     67: foreach my $p (@pass) {
                     68:     my $api = new_ok( $class,
1.4     ! andrew     69:         [ { todo_dir => 't/lists', path_info => $p->{path_info} } ] );
1.3       andrew     70:
                     71:     my @result;
                     72:     ok( eval { @result = $api->GET() },
                     73:         'GET method (' . $p->{path_info} . ')'
                     74:     );
                     75:     is_deeply(
                     76:         \@result,
                     77:         $p->{result},
                     78:         'Failed GET as expected'
                     79:     );
                     80: }
                     81:
                     82: my @fail = (
1.4     ! andrew     83:     {   path_info => '/todo/entry',
1.3       andrew     84:         result => '',
                     85:     },
1.4     ! andrew     86:     {   path_info => '/todo/unsupported',
1.3       andrew     87:         result => 'Unable to handle GET \[unsupported\]',
                     88:     },
                     89: );
                     90:
                     91: foreach my $p (@fail) {
                     92:     my $api = new_ok( $class,
1.4     ! andrew     93:         [ { todo_dir => 't/lists', path_info => $p->{path_info} } ] );
1.3       andrew     94:
                     95:     my $result;
                     96:     ok( !eval { $result = $api->GET() },
                     97:         'GET method (' . $p->{path_info} . ')'
                     98:     );
                     99:     like(
                    100:         $@,
                    101:         '/^' . $p->{result} . '/',
                    102:         'Failed GET as expected (' . $p->{result} . ')'
                    103:     );
                    104: }
1.1       andrew    105:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>