]> git.donarmstrong.com Git - liborg-parser-perl.git/blob - t/text.t
Import original source of Org-Parser 0.23
[liborg-parser-perl.git] / t / text.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 => 'text basic tests',
16     filter_elements => 'Org::Element::Text',
17     doc  => <<'_',
18 * just some heading, not bold*
19 0) this is normal.
20 *1) this /is/ bold.*
21 /3) this *is* italic./
22 _5) this is underline._
23 +7) this is strike-through.+
24 =9) this is code.=
25 ~11) this is verbatim.~
26
27 unparsed: *ends with spaces *, / start with space/, =no ending. no starting.~
28 _
29     num => 13,
30     test_after_parse => sub {
31         my %args = @_;
32         my $doc = $args{result};
33         my $elems = $args{elements};
34         #diag(explain [map {$_->as_string} @$elems]);
35         ok(!$elems->[ 0]->style,      "elem 0 normal");
36         is( $elems->[ 1]->style, "B", "elem 2 bold");
37         is( $elems->[ 3]->style, "I", "elem 2 italic");
38         is( $elems->[ 5]->style, "U", "elem 2 underline");
39         is( $elems->[ 7]->style, "S", "elem 2 strike-through");
40         is( $elems->[ 9]->style, "C", "elem 2 code");
41         is( $elems->[11]->style, "V", "elem 2 verbatim");
42         ok(!$elems->[12]->style,      "elem 13 normal");
43
44         is( $elems->[ 0]->as_string, "0) this is normal.\n",
45             "normal as_string");
46         is( $elems->[ 1]->as_string, "*1) this /is/ bold.*",
47             "bold as_string");
48         is( $elems->[ 3]->as_string, "/3) this *is* italic./",
49             "italic as string");
50         is( $elems->[ 5]->as_string, "_5) this is underline._",
51             "underline as_string");
52         is( $elems->[ 7]->as_string, "+7) this is strike-through.+",
53             "strike-through as_string");
54         is( $elems->[ 9]->as_string, "=9) this is code.=",
55             "code as_string");
56         is( $elems->[11]->as_string, "~11) this is verbatim.~",
57             "verbatim as_string");
58     },
59 );
60
61 # emacs only allows a single newline in markup
62 test_parse(
63     name => 'max newlines',
64     filter_elements => 'Org::Element::Text',
65     doc  => <<'_',
66 =this is
67 still code=
68
69 =this is
70 no longer
71 code=
72 _
73     num => 2,
74     test_after_parse => sub {
75         my %args = @_;
76         my $doc = $args{result};
77         my $elems = $args{elements};
78         #diag(explain [map {$_->as_string} @$elems]);
79         is( $elems->[0]->style, "C", "elem 0 code");
80         ok(!$elems->[1]->style,      "elem 1 normal");
81
82         is( $elems->[0]->as_string, "=this is\nstill code=",
83             "elem 0 as_string");
84         is( $elems->[1]->as_string, "\n\n=this is\nno longer\ncode=\n",
85             "elem 1 as_string");
86     },
87 );
88
89 # markup can contain links, even *[[link][description with * in it]]*. also
90 # timestamp, etc.
91 test_parse(
92     name => 'link inside markup',
93     filter_elements => 'Org::Element::Text',
94     doc  => <<'_',
95 *bolded [[link]]*
96 _
97     test_after_parse => sub {
98         my %args = @_;
99         my $doc = $args{result};
100         my $elems = $args{elements};
101         is($elems->[0]->style, "B", "elem 0 bold");
102         is($elems->[0]->children->[0]->as_string, "bolded ",
103            "bolded text");
104         is(ref($elems->[0]->children->[1]), "Org::Element::Link",
105            "link inside bolded");
106     },
107 );
108
109 done_testing();
110