/[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 949 - (hide annotations)
Thu Nov 1 00:16:48 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1085 byte(s)
 r1433@llin:  dpavlin | 2007-10-31 22:48:02 +0100
 HUGE swiping changes to implement new testing architecture
 based on all new WebPAC::Test module which makes
 test writing a joy

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26