/[webpac2]/trunk/t/5-output-json.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/5-output-json.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 881 by dpavlin, Thu Aug 23 20:28:09 2007 UTC revision 883 by dpavlin, Thu Aug 23 20:56:59 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use Test::More tests => 7;  use Test::More tests => 14;
4  use Test::Exception;  use Test::Exception;
5  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
6    use JSON;
7    use File::Slurp;
8    use Data::Dump qw/dump/;
9  use blib;  use blib;
10  use strict;  use strict;
11    
# Line 10  BEGIN { Line 13  BEGIN {
13  use_ok( 'WebPAC::Output::JSON' );  use_ok( 'WebPAC::Output::JSON' );
14  }  }
15    
16    my $debug = shift @ARGV;
17    
18  ok(my $abs_path = abs_path($0), "abs_path");  ok(my $abs_path = abs_path($0), "abs_path");
19  $abs_path =~ s#/[^/]*$#/#; #  $abs_path =~ s#/[^/]*$#/#; #
20  diag "abs_path: $abs_path";  diag "abs_path: $abs_path";
21    my $path = "$abs_path/out/test.js";
22    
23  ok(my $out = new WebPAC::Output::JSON({  ok(my $out = new WebPAC::Output::JSON({ path => $path }), "new");
         path => "$abs_path/out/test.js",  
 }), "new");  
24    
25  ok( $out->init, 'init' );  ok( $out->init, 'init' );
26    
27  my $ds = {  my $ds = {
28          'Source' => {          'Source' => {
29                  'name' => 'Izvor: ',                  'name' => 'Izvor: ',
                 'tag' => 'Source',  
30                  'display' => [ 'foo' ]                  'display' => [ 'foo' ]
31                  },          },
32          'ID' => {          'ID' => {
33                  'name' => 'ID',                  'display' => 'id',
34                  'tag' => 'IDths',          },
35                  'search' => [ 'bar' ],          'Array' => {
36                  'lookup_key' => [ 'bar' ]                  'display' => [ qw/a1 a2 s3 a4 a5/ ],
37                  },          },
         'filename' => [ 'out/thes/001.html' ],  
         'name' => 'filename',  
         'tag' => 'filename'  
38  };  };
39    
40  throws_ok { $out->add( ) } qr/need id/, 'add without params';  throws_ok { $out->add( ) } qr/need id/, 'add without params';
# Line 42  throws_ok { $out->add( 42 ) } qr/need ds Line 42  throws_ok { $out->add( 42 ) } qr/need ds
42    
43  ok( $out->add( 42, $ds ), 'add' );  ok( $out->add( 42, $ds ), 'add' );
44    
45    ok( $out->add( 99, { foo => { display => 'foo' } } ), 'add another' );
46    
47    ok( $out->finish );
48    
49    ok( -e $out->path, "created $path" );
50    
51    cmp_ok( $out->path, 'eq', $path, 'path' );
52    
53    ok( my $items = read_file( $path ), 'read_file' );
54    
55    ok( $items = jsonToObj( $items ), 'parse JSON' );
56    
57    diag dump( $items ) if $debug;
58    
59    is_deeply( $items, {
60            items => [
61                    { array => ["a1", "a2", "s3", "a4", "a5"], id => "id", source => ["foo"] },
62                    { foo => "foo" },
63            ],
64    }, 'same' );

Legend:
Removed from v.881  
changed lines
  Added in v.883

  ViewVC Help
Powered by ViewVC 1.1.26