]> git.donarmstrong.com Git - liborg-parser-perl.git/blob - t/timerange.t
Import original source of Org-Parser 0.23
[liborg-parser-perl.git] / t / timerange.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 DateTime;
11 use Org::Parser;
12 use Test::More 0.96;
13 require "testlib.pl";
14
15 test_parse(
16     name => 'timerange basic tests',
17     filter_elements => sub {
18         $_[0]->isa('Org::Element::TimeRange') },
19     doc  => <<'_',
20 * TODO active timeranges
21 <2011-03-23 Wed>--<2011-03-24 Thu>
22 <2011-03-23 >--<2011-03-24 >
23 <2011-03-23 Wed 01:23>--<2011-03-23 Wed 03:59>
24
25 * inactive timeranges
26 [2011-03-23 Wed]--[2011-03-24 Thu]
27 [2011-03-23 ]--[2011-03-24 ]
28 [2011-03-23 Wed 01:23]--[2011-03-23 Wed 03:59]
29
30 * non-timeranges
31 [2011-03-22 ]--<2011-03-23 > # mixed active & inactive timestamp
32 <2011-03-22 >--[2011-03-23 ] # mixed active & inactive timestamp
33
34 _
35     num => 6,
36     test_after_parse => sub {
37         my %args = @_;
38         my $doc = $args{result};
39         my $elems = $args{elements};
40         ok( $elems->[0]->ts1->is_active, "tr[0] is_active");
41         ok(!$elems->[3]->ts1->is_active, "tr[3] !is_active");
42     },
43 );
44
45 test_parse(
46     name => 'event duration not allowed in timerange',
47     filter_elements => sub {
48         $_[0]->isa('Org::Element::TimeRange') },
49     doc  => <<'_',
50 <2011-03-23 Wed 11:28-12:00>--<2011-03-24 Thu>
51 _
52     dies => 1,
53 );
54
55 test_parse(
56     name => 'repeater not allowed in timerange',
57     filter_elements => sub {
58         $_[0]->isa('Org::Element::TimeRange') },
59     doc  => <<'_',
60 <2011-03-23 Wed +1w>--<2011-03-24 Thu>
61 _
62     dies => 1,
63 );
64
65 done_testing();