File: 91-template_path.t

package info (click to toggle)
libtext-micromason-perl 2.13-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 624 kB
  • ctags: 180
  • sloc: perl: 3,222; makefile: 23
file content (57 lines) | stat: -rw-r--r-- 1,842 bytes parent folder | download | duplicates (8)
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
#!/usr/bin/perl -w

use strict;
use Test::More tests => 12;

# Test TemplatePath
use_ok 'Text::MicroMason';

######################################################################

my $m1 = Text::MicroMason->new( -TemplatePath, template_path => [ qw(samples/subdir/ samples/) ]);

# If we execute a template in subdir/ we should get it (and not the
# samples/ version).

SUBDIR: {
    ok (my $output = $m1->execute( file => 'test.msn', name => 'Sam', hour => 14));
    like ($output, qr/\QGuten Tag, Sam!\E/);
    
    ok ($output = $m1->execute( file => 'test.msn', name=>'Sam', hour=>10));
    like ($output, qr/\QGuten Morgen, Sam!\E/);
}

# If we call a template that only exists in samples/ then that should
# work as well.  But the referred template 

SAMPLE: {
    ok (my $scr_hello = $m1->execute( file => 'test-relative.msn', name => 'Dave'));
    ok (my $res_hello = "Test greeting:\nGuten Tag, Dave!\n");
    like ($scr_hello, qr/\Q$res_hello\E/);
    like ($m1->execute(text => $scr_hello), qr/\Q$res_hello\E/);
}


######################################################################
# With the reverse path we should get opposite results.

my $m2 = Text::MicroMason->new( -TemplatePath, template_path => [ qw(samples/ samples/subdir/) ]);

SUBDIR: {
    my $output = $m2->execute( file=>'test.msn', name=>'Sam', hour=>14);
    like ($output, qr/\QGood afternoon, Sam!\E/ );
    
    $output = $m2->execute( file=>'test.msn', name=>'Sam', hour=>10);
    like ($output, qr/\QGood morning, Sam!\E/ );
}

# If we call a template that only exists in samples/ then that should
# work as well.  But the referred template 

SAMPLE: {
    my $scr_hello = $m2->execute( file => 'test-relative.msn', name => 'Dave');
    my $res_hello = "Test greeting:\nGood afternoon, Dave!\n";
    is ($m2->execute(text=>$scr_hello), $res_hello);
}