• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1use strict;
2use Test::More;
3BEGIN { plan tests => 7 };
4
5BEGIN { $ENV{PERL_JSON_BACKEND} = 1; }
6
7use JSON -support_by_pp;
8
9SKIP: {
10    skip "can't use JSON::XS.", 7, unless( JSON->backend->is_xs );
11
12my $json = new JSON;
13
14
15is($json->indent_length(2)->encode([1,{foo => 'bar'}, "1", "/"]), qq|[1,{"foo":"bar"},"1","/"]|);
16
17is($json->indent->encode([1,{foo => 'bar'}, "1", "/"]), qq|[
18  1,
19  {
20    "foo":"bar"
21  },
22  "1",
23  "/"
24]
25|);
26
27
28is($json->escape_slash(1)->pretty->indent_length(2)->encode([1,{foo => 'bar'}, "1", "/"]), qq|[
29  1,
30  {
31    "foo" : "bar"
32  },
33  "1",
34  "\\/"
35]
36|);
37
38
39is($json->escape_slash(1)->pretty->indent_length(3)->encode([1,{foo => 'bar'}, "1", "/"]), qq|[
40   1,
41   {
42      "foo" : "bar"
43   },
44   "1",
45   "\\/"
46]
47|);
48
49is($json->escape_slash(1)->pretty->indent_length(15)->encode([1,{foo => 'bar'}, "1", "/"]), qq|[
50               1,
51               {
52                              "foo" : "bar"
53               },
54               "1",
55               "\\/"
56]
57|);
58
59
60is($json->indent_length(0)->encode([1,{foo => 'bar'}, "1", "/"]), qq|[
611,
62{
63"foo" : "bar"
64},
65"1",
66"\\/"
67]
68|);
69
70is($json->indent(0)->space_before(0)->space_after(0)->escape_slash(0)
71        ->encode([1,{foo => 'bar'}, "1", "/"]), qq|[1,{"foo":"bar"},"1","/"]|);
72
73
74}
75
76
77