ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/06_pc_pretty.t
Revision: 1.2
Committed: Tue Sep 8 00:37:43 2009 UTC (14 years, 9 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_0, rel-3_0, rel-4_01, rel-4_03, rel-4_02, rel-2_3, rel-4_0_00, rel-2_34, rel-2_32, rel-2_33, rel-2_31, rel-3_01, rel-3_02, rel-3_03, rel-3_04, rel-2_29, rel-2_28, rel-2_27, rel-2_26, HEAD
Changes since 1.1: +8 -6 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 # copied over from JSON::PC and modified to use JSON::XS
4
5 use strict;
6 use Test::More;
7 BEGIN { plan tests => 9 };
8
9 use JSON::XS;
10
11 my ($js,$obj,$json);
12 my $pc = new JSON::XS;
13
14 $obj = {foo => "bar"};
15 $js = $pc->encode($obj);
16 is($js,q|{"foo":"bar"}|);
17
18 $obj = [10, "hoge", {foo => "bar"}];
19 $pc->pretty (1);
20 $js = $pc->encode($obj);
21 is($js,q|[
22 10,
23 "hoge",
24 {
25 "foo" : "bar"
26 }
27 ]
28 |);
29
30 $obj = { foo => [ {a=>"b"}, 0, 1, 2 ] };
31 $pc->pretty(0);
32 $js = $pc->encode($obj);
33 is($js,q|{"foo":[{"a":"b"},0,1,2]}|);
34
35
36 $obj = { foo => [ {a=>"b"}, 0, 1, 2 ] };
37 $pc->pretty(1);
38 $js = $pc->encode($obj);
39 is($js,q|{
40 "foo" : [
41 {
42 "a" : "b"
43 },
44 0,
45 1,
46 2
47 ]
48 }
49 |);
50
51 $obj = { foo => [ {a=>"b"}, 0, 1, 2 ] };
52 $pc->pretty(0);
53 $js = $pc->encode($obj);
54 is($js,q|{"foo":[{"a":"b"},0,1,2]}|);
55
56
57 $obj = {foo => "bar"};
58 $pc->indent(1);
59 is($pc->encode($obj), qq|{\n "foo":"bar"\n}\n|, "nospace");
60 $pc->space_after(1);
61 is($pc->encode($obj), qq|{\n "foo": "bar"\n}\n|, "after");
62 $pc->space_before(1);
63 is($pc->encode($obj), qq|{\n "foo" : "bar"\n}\n|, "both");
64 $pc->space_after(0);
65 is($pc->encode($obj), qq|{\n "foo" :"bar"\n}\n|, "before");
66