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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1256 - (show annotations)
Tue Jul 28 12:40:46 2009 UTC (14 years, 9 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1090 byte(s)
use code from lib insted of blib

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26