File: 7-nested-compat.t

package info (click to toggle)
libdata-javascript-perl 1.15-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 288 kB
  • sloc: perl: 319; makefile: 5
file content (40 lines) | stat: -rw-r--r-- 789 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env perl

use Modern::Perl;

use Test2::V0;

use Data::JavaScript qw(:all);

my $input = {
  a => {
    a1 => [qw/a1i a1ii a1iii/]
  },
  b => {
    b1 => "b1i",
  },
  c => "c1",
  d => [qw/d1 d2 d3/],
};

my $expected =
    qq/var output = new Object;\n/
  . qq/output["a"] = new Object;\n/
  . qq/output["a"]["a1"] = new Array;\n/
  . qq/output["a"]["a1"][0] = "a1i";\n/
  . qq/output["a"]["a1"][1] = "a1ii";\n/
  . qq/output["a"]["a1"][2] = "a1iii";\n/
  . qq/output["b"] = new Object;\n/
  . qq/output["b"]["b1"] = "b1i";\n/
  . qq/output["c"] = "c1";\n/
  . qq/output["d"] = new Array;\n/
  . qq/output["d"][0] = "d1";\n/
  . qq/output["d"][1] = "d2";\n/
  . qq/output["d"][2] = "d3";\n/;

is
  jsdump( 'output', $input ),
  $expected,
  'Nested jsdump()';

done_testing;