ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/t/06_pc_pretty.t
Revision: 1.1
Committed: Fri Mar 23 15:10:56 2007 UTC (17 years, 3 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-2_01, rel-1_11, rel-1_51, rel-1_53, rel-2_222, rel-0_31, rel-2_2, rel-2_0, rel-2_1, rel-0_3, rel-0_5, rel-0_7, rel-0_8, rel-1_1, rel-1_0, rel-1_3, rel-1_2, rel-1_5, rel-1_4, rel-2_2311, rel-1_01, rel-1_24, rel-1_21, rel-1_22, rel-1_23, rel-1_43, rel-1_41, rel-2_232, rel-2_231, rel-2_21, rel-2_2222, rel-2_23, rel-2_22, rel-2_25, rel-2_24
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 $obj = { foo => [ {a=>"b"}, 0, 1, 2 ] };
30 $pc->pretty(0);
31 $js = $pc->encode($obj);
32 is($js,q|{"foo":[{"a":"b"},0,1,2]}|);
33
34
35 $obj = { foo => [ {a=>"b"}, 0, 1, 2 ] };
36 $pc->pretty(1);
37 $js = $pc->encode($obj);
38 is($js,q|{
39 "foo" : [
40 {
41 "a" : "b"
42 },
43 0,
44 1,
45 2
46 ]
47 }|);
48
49 $obj = { foo => [ {a=>"b"}, 0, 1, 2 ] };
50 $pc->pretty(0);
51 $js = $pc->encode($obj);
52 is($js,q|{"foo":[{"a":"b"},0,1,2]}|);
53
54
55 $obj = {foo => "bar"};
56 $pc->indent(1);
57 is($pc->encode($obj), qq|{\n "foo":"bar"\n}|, "nospace");
58 $pc->space_after(1);
59 is($pc->encode($obj), qq|{\n "foo": "bar"\n}|, "after");
60 $pc->space_before(1);
61 is($pc->encode($obj), qq|{\n "foo" : "bar"\n}|, "both");
62 $pc->space_after(0);
63 is($pc->encode($obj), qq|{\n "foo" :"bar"\n}|, "before");
64