File: options.t

package info (click to toggle)
libcatmandu-template-perl 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 160 kB
  • sloc: perl: 363; makefile: 2; sh: 1
file content (91 lines) | stat: -rw-r--r-- 1,926 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use Test::Exception;
use Catmandu::Exporter::Template;

my $file     = "";
my $template = <<EOF;
Author: <% author !>
Title: "<% title !>"
EOF

my $exporter = Catmandu::Exporter::Template->new(
    file      => \$file,
    template  => \$template,
    start_tag => "<%",
    end_tag   => "!>"
);
my $data = {author => "brian d foy", title => "Mastering Perl",};

$exporter->add($data);

my $result = <<EOF;
Author: brian d foy
Title: "Mastering Perl"
EOF

is($file, $result, "Exported Format");

my $template2 = <<EOF;
Author: <? author ?>
Title: "<? title ?>"
EOF

my $exporter2 = Catmandu::Exporter::Template->new(
    file      => \$file,
    template  => \$template2,
    tag_style => "php"
);
$exporter2->add($data);

is($file, $result, "Tag style ok");

# TT caching
$exporter = Catmandu::Exporter::Template->new(
    template  => \$template,
    start_tag => "<%",
    end_tag   => "!>"
);
$exporter2 = Catmandu::Exporter::Template->new(
    template  => \$template,
    start_tag => "<%",
    end_tag   => "!>"
);

ok $exporter->_tt == $exporter2->_tt,
    'tt engines wirth equal arguments get reused';

$exporter2 = Catmandu::Exporter::Template->new(
    template  => \$template,
    start_tag => "<%",
    end_tag   => "%>"
);

ok $exporter->_tt != $exporter2->_tt,
    'tt engines with equal arguments get reused';

$exporter = Catmandu::Exporter::Template->new(
    template     => \$template,
    INCLUDE_PATH => '/tmp/a',
);

$exporter2 = Catmandu::Exporter::Template->new(
    template     => \$template,
    INCLUDE_PATH => '/tmp/a',
);

ok $exporter->_tt == $exporter2->_tt,
    'tt engines wirth equal arguments get reused';

$exporter2 = Catmandu::Exporter::Template->new(
    template     => \$template,
    INCLUDE_PATH => '/tmp/b',
);

ok $exporter->_tt != $exporter2->_tt,
    'tt engines wirth equal arguments get reused';

done_testing;