File: 31_recurse.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,293 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
use warnings;
use strict;
use lib 't';
use Test::More tests => 4;
use_ok('HTML::Template::Compiled');
use HTC_Utils qw($cache $tdir &cdir);
$HTML::Template::Compiled::MAX_RECURSE = 10; # default

{
    my $htc = HTML::Template::Compiled->new(
        path => $tdir,
        filename => "recurse.html",
        debug    => 0,
    );


    $htc->param(
        content => "1",
        child => { content => "2",
            child => { content => "3",
                child => { content => "4",
                    child => { content => "5",
                        child => { content => "6",
                            child => { content => "7",
                                child => { content => "8",
                                    child => { content => "9",
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    );
    my $out = $htc->output;
    cmp_ok($out, '=~', qr#((content: (?:\d+)).*){9}#s, "recursive ok");
    for my $max (9, 15) {
    my $out;
    eval {
    $HTML::Template::Compiled::MAX_RECURSE = $max;
    $htc->clear_params;
    $htc->param(
        content => "1",
        child => { content => "2",
            child => { content => "3",
                child => { content => "4",
                    child => { content => "5",
                        child => { content => "6",
                            child => { content => "7",
                                child => { content => "8",
                                    child => { content => "9",
                                        child => { content => "10",
                                            child => { content => "11" },
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    );
    $out = $htc->output;
    };
    #print "error: $@\n";
    #print "out: $out\n";
    if ($max == 9) {
        ok($@ && $@ =~ m/recu/, "max recursion 10 > $max");
    }
    else {
        cmp_ok($out, '=~', qr#((content: (?:\d+)).*){11}#s, "max recursion 10 < $max");
    }
    }
}