File: synopsis.t

package info (click to toggle)
libpandoc-elements-perl 0.38-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 732 kB
  • sloc: perl: 1,630; makefile: 15; sh: 1
file content (50 lines) | stat: -rw-r--r-- 1,433 bytes parent folder | download | duplicates (3)
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
41
42
43
44
45
46
47
48
49
50
use strict;
use Test::More;
use Pandoc::Elements;
use JSON;

# Use Test::Deep because it handles blessed structures
# with overloaded stringification correctly.

BEGIN {
    plan skip_all => 'Test::Deep not available' unless eval 'require Test::Deep; 1;';
    Test::Deep->import( qw[cmp_deeply noclass] );
}

my $ast = Document {
        title => MetaInlines [ Str 'Greeting' ]
    }, [
        Header( 1, attributes { id => 'de' }, [ Str 'Gruß' ] ),
        Para [ Str 'hello, world!' ],
    ], api_version => '1.17.0.4';

# note explain $ast->TO_JSON;

cmp_deeply $ast, noclass {   'blocks' => [
        {   'c' => [ 1, [ 'de', [], [] ], [ { 'c' => 'Gruß', 't' => 'Str' } ] ],
            't' => 'Header'
        },
        { 'c' => [ { 'c' => 'hello, world!', 't' => 'Str' } ], 't' => 'Para' }
    ],
    'meta' => {
        'title' =>
          { 'c' => [ { 'c' => 'Greeting', 't' => 'Str' } ], 't' => 'MetaInlines' }
    },
    'pandoc-api-version' => [ 1, 17, 0, 4 ]
};

my $json = JSON->new->utf8->convert_blessed->encode($ast);
cmp_deeply decode_json($json), noclass($ast), 'encode/decode JSON';
cmp_deeply Pandoc::Elements::pandoc_json($json), noclass($ast), 'pandoc_json';
$json = $ast->to_json;
cmp_deeply decode_json($json), noclass($ast), 'to_json';

eval { Pandoc::Elements->pandoc_json(".") };
like $@, qr{.+at.+synopsis.*\.t}, 'error in pandoc_json';

done_testing;

__DATA__
% Greeting
# Gruß {.de}
hello, world!