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

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

  ViewVC Help
Powered by ViewVC 1.1.26