/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 883 - (hide annotations)
Thu Aug 23 20:56:59 2007 UTC (16 years, 9 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1264 byte(s)
 r1315@llin:  dpavlin | 2007-08-23 22:52:10 +0200
 create on-disk JSON file

1 dpavlin 881 #!/usr/bin/perl -w
2    
3 dpavlin 883 use Test::More tests => 14;
4 dpavlin 881 use Test::Exception;
5     use Cwd qw/abs_path/;
6 dpavlin 883 use JSON;
7     use File::Slurp;
8     use Data::Dump qw/dump/;
9 dpavlin 881 use blib;
10     use strict;
11    
12     BEGIN {
13     use_ok( 'WebPAC::Output::JSON' );
14     }
15    
16 dpavlin 883 my $debug = shift @ARGV;
17    
18 dpavlin 881 ok(my $abs_path = abs_path($0), "abs_path");
19     $abs_path =~ s#/[^/]*$#/#; #
20     diag "abs_path: $abs_path";
21 dpavlin 883 my $path = "$abs_path/out/test.js";
22 dpavlin 881
23 dpavlin 883 ok(my $out = new WebPAC::Output::JSON({ path => $path }), "new");
24 dpavlin 881
25     ok( $out->init, 'init' );
26    
27     my $ds = {
28     'Source' => {
29     'name' => 'Izvor: ',
30     'display' => [ 'foo' ]
31 dpavlin 883 },
32 dpavlin 881 'ID' => {
33 dpavlin 883 'display' => 'id',
34     },
35     'Array' => {
36     'display' => [ qw/a1 a2 s3 a4 a5/ ],
37     },
38 dpavlin 881 };
39    
40     throws_ok { $out->add( ) } qr/need id/, 'add without params';
41     throws_ok { $out->add( 42 ) } qr/need ds/, 'add without ds';
42    
43     ok( $out->add( 42, $ds ), 'add' );
44    
45 dpavlin 883 ok( $out->add( 99, { foo => { display => 'foo' } } ), 'add another' );
46 dpavlin 881
47 dpavlin 883 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' );

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26