File: 34_loop_context_vars.t

package info (click to toggle)
libhtml-template-compiled-perl 1.003-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 772 kB
  • sloc: perl: 4,759; makefile: 5
file content (78 lines) | stat: -rw-r--r-- 2,297 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

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t'

use Test::More tests => 17;
BEGIN { use_ok('HTML::Template::Compiled') };
use lib 't';
use HTC_Utils qw($cache $tdir &cdir);
use strict;
use warnings;
my $short_tmpl = 'file_debug.html';
my $long_tmpl = cdir('subdir', 'file_debug.html');
my $short_path = cdir($tdir, $short_tmpl);
my $long_path = cdir($tdir, $long_tmpl);

{
    my $htc = HTML::Template::Compiled->new(
        path => $tdir,
        filename => $short_tmpl,
        cache => 0,
        loop_context_vars => 1,
        search_path_on_include => 1,
        debug => 0,
    );

    my $out = $htc->output;
    #print $out, $/;
    $out =~ s/\s+/ /g;
    cmp_ok($out, "=~", qr#^test \Q$short_path $short_tmpl\E end#,
        "filename debug 1");
}
{
    my $htc = HTML::Template::Compiled->new(
        path => $tdir,
        filename => $long_tmpl,
        loop_context_vars => 1,
        search_path_on_include => 1,
        cache => 0,
        debug => 0,
    );

    my $out = $htc->output;
    #print $out, $/;
    $out =~ s/\s+/ /g;
    cmp_ok($out, "=~", qr#^test \Q$long_path $long_tmpl\E end#,
        "filename debug 2");
}
for my $debug (qw/ start end /, 'start,end') {
    for my $short (0, 1) {
        my $debug_string = $debug;
        $debug_string .= ',short' if $short;
        my $htc = HTML::Template::Compiled->new(
            path => $tdir,
            filename => $long_tmpl,
            loop_context_vars => 1,
            search_path_on_include => 1,
            debug => 0,
            cache => 0,
            debug_file => $debug_string,
        );

        my $out = $htc->output;
        #print $out, $/;
        $out =~ s/\s+/ /g;
        cmp_ok($out, "=~", qr#test \Q$long_path\E \Q$long_tmpl\E end#,
            "filename debug '$debug_string'");
        my $testpath = $short ? $long_tmpl : $long_path;
        if ($debug =~ m/start/) {
            cmp_ok($out, "=~", qr#<!-- start \Q$testpath\E -->#,
                "filename debug '$debug_string' start");
        }
        if ($debug =~ m/end/) {
            cmp_ok($out, "=~", qr#<!-- end \Q$testpath\E -->#,
                "filename debug '$debug_string' end");
        }
    }
}