]> git.donarmstrong.com Git - liborg-parser-perl.git/blob - t/block.t
Import original source of Org-Parser 0.23
[liborg-parser-perl.git] / t / block.t
1 #!perl
2
3 use 5.010;
4 use strict;
5 use warnings;
6
7 use FindBin '$Bin';
8 use lib $Bin, "$Bin/t";
9
10 use Org::Parser;
11 use Test::More 0.96;
12 require "testlib.pl";
13
14 test_parse(
15     name => 'unknown block',
16     filter_elements => 'Org::Element::Block',
17     doc  => <<'_',
18 #+BEGIN_FOO
19 bar
20 #+END_FOO
21 _
22     dies => 1,
23 );
24
25 test_parse(
26     name => 'EXAMPLE: undetected (no END, becomes comment)',
27     filter_elements => 'Org::Element::Block',
28     doc  => <<'_',
29 #+BEGIN_EXAMPLE
30 1
31 2
32 #+xEND_EXAMPLE
33 _
34     dies => 0,
35     num => 0,
36 );
37
38 # also checks case-sensitiveness
39 test_parse(
40     name => 'EXAMPLE: basic tests',
41     filter_elements => 'Org::Element::Block',
42     doc  => <<'_',
43 #+BEGIN_EXAMPLE -t -w 40
44 #+INSIDE
45 line 2
46 #+end_EXAMPLE
47 _
48     num  => 1,
49     test_after_parse => sub {
50         my %args = @_;
51         my $doc = $args{result};
52         my $elems = $args{elements};
53         my $bl = $elems->[0];
54         is($bl->name, "EXAMPLE", "name");
55         is_deeply($bl->args, ["-t", "-w", 40], "args");
56         is($bl->raw_content, "#+INSIDE\nline 2", "raw_content");
57     },
58 );
59
60 test_parse(
61     name => 'block is indentable',
62     filter_elements => 'Org::Element::Block',
63     doc => <<'_',
64    #+BEGIN_EXAMPLE
65 foo
66  #+END_EXAMPLE
67 _
68     num => 1,
69     test_after_parse => sub {
70         my %args = @_;
71         my $elems = $args{elements};
72         is($elems->[0]->begin_indent, "   ", "begin_indent attribute");
73         is($elems->[0]->end_indent, " ", "end_indent attribute");
74     },
75 );
76
77 done_testing();