]> git.donarmstrong.com Git - liborg-parser-perl.git/blob - t/setting.t
Import original source of Org-Parser 0.23
[liborg-parser-perl.git] / t / setting.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 => 'non-setting (missing +)',
16     filter_elements => 'Org::Element::Setting',
17     doc  => <<'_',
18 #TODO: A B | C
19 _
20     num => 0,
21 );
22
23 test_parse(
24     name => 'non-setting (not on first column)',
25     filter_elements => 'Org::Element::Setting',
26     doc  => <<'_',
27  #+TODO: A B | C
28 _
29     num => 0,
30 );
31
32 test_parse(
33     name => 'syntax error (missing colon, becomes comment)',
34     filter_elements => 'Org::Element::Setting',
35     doc  => <<'_',
36 #+TODO A B | C
37 _
38     dies => 0,
39     num => 0,
40 );
41
42 test_parse(
43     name => 'unknown setting',
44     filter_elements => 'Org::Element::Setting',
45     doc  => <<'_',
46 #+FOO: bar
47 _
48     dies => 1,
49 );
50
51 test_parse(
52     name => 'FILETAGS: argument syntax error',
53     filter_elements => 'Org::Element::Setting',
54     doc  => <<'_',
55 #+FILETAGS: a:
56 _
57     dies => 1,
58 );
59
60 test_parse(
61     name => 'FILETAGS: basic tests',
62     filter_elements => 'Org::Element::Setting',
63     doc  => <<'_',
64 #+FILETAGS:  :tag1:tag2:tag3:
65 _
66     num  => 1,
67     test_after_parse => sub {
68         my %args = @_;
69         my $doc = $args{result};
70         my $elems = $args{elements};
71         is($elems->[0]->name, "FILETAGS", "name");
72         is($elems->[0]->args->[0], ":tag1:tag2:tag3:", "args[0]");
73     },
74 );
75
76 test_parse(
77     name => 'PRIORITIES: basic tests',
78     filter_elements => 'Org::Element::Setting',
79     doc  => <<'_',
80 #+PRIORITIES: A1 A2 B1 B2 C1 C2
81 _
82     num  => 1,
83     test_after_parse => sub {
84         my %args = @_;
85         my $doc = $args{result};
86         my $elems = $args{elements};
87         is($elems->[0]->name, "PRIORITIES", "name");
88         is_deeply($elems->[0]->args, [qw/A1 A2 B1 B2 C1 C2/],
89                   "args");
90         is_deeply($doc->priorities, [qw/A1 A2 B1 B2 C1 C2/],
91                   "document's priorities attribute");
92     },
93 );
94
95 test_parse(
96     name => 'DRAWERS: basic tests',
97     filter_elements => 'Org::Element::Setting',
98     doc  => <<'_',
99 #+DRAWERS: D1 D2
100 _
101     num  => 1,
102     test_after_parse => sub {
103         my %args = @_;
104         my $doc = $args{result};
105         my $elems = $args{elements};
106         is($elems->[0]->name, "DRAWERS", "name");
107         ok("D1"    ~~ @{$doc->drawer_names},
108            "D1 added to list of known drawers");
109         ok("D2"    ~~ @{$doc->drawer_names},
110            "D2 added to list of known drawers");
111         ok("CLOCK" ~~ @{$doc->drawer_names},
112            "default drawers still known");
113     },
114 );
115
116 test_parse(
117     name => 'indentable_elements (not indentable)',
118     filter_elements => 'Org::Element::Setting',
119     doc => <<'_',
120 #+TODO: A | B C
121  #+TODO: D E | F
122 _
123     num => 1,
124 );
125 test_parse(
126     name => 'indentable_elements (not indentable, test text)',
127     filter_elements => 'Org::Element::Text',
128     doc => <<'_',
129 #+TODO: A | B C
130  #+TODO: D E | F
131 _
132     num => 1,
133     test_after_parse => sub {
134         my (%args) = @_;
135         my $elems = $args{elements};
136         is($elems->[0]->as_string, " #+TODO: D E | F\n", "text");
137     },
138 );
139
140 test_parse(
141     name => 'indentable_elements (indentable)',
142     filter_elements => 'Org::Element::Setting',
143     doc => <<'_',
144 #+TBLFM: @2$1=@1$1
145  #+tblfm: @3$1=@1$1
146 _
147     num => 2,
148     test_after_parse => sub {
149         my (%args) = @_;
150         my $elems = $args{elements};
151         is($elems->[1]->indent, " ", "indent attribute");
152     },
153 );
154
155 done_testing();