File: 09-regression.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 (187 lines) | stat: -rw-r--r-- 4,885 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/perl -w

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

use_ok 'Text::MicroMason';

ok my $m = Text::MicroMason->new();

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

MINIMAL_CASES: {
    is $m->execute( text => ''), '';
    is $m->execute( text => ' '), ' ';
    is $m->execute( text => "0"), "0";
    is $m->execute( text => "\n"), "\n";
}

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

COMMENT_EXPR: {
    my $scr_re = 'Hello <% # foo %> World!';
    my $res_re = "Hello  World!";
    is $m->execute( text => $scr_re), $res_re;
}

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

EMPTY_PERL_LINE: {
    my $scr_re = "x\n%\nx";
    my $res_re = "x\nx";
    is $m->execute( text => $scr_re), $res_re;
}

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

COMMENT_PERL_LINE: {
    my $scr_re = "x\n% # \nx";
    my $res_re = "x\nx";
    is $m->execute( text => $scr_re), $res_re;
}

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

SINGLE_PERL_LINE: {
    my $scr_re = '% $_out->("Potato"); ';
    my $res_re = "Potato";
    is $m->execute( text => $scr_re), $res_re;
}

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

EMPTY_PERL_BLOCK: {
    my $scr_re = '<%perl></%perl>';
    is $m->execute( text => $scr_re), '';
}

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

SINGLE_PERL_BLOCK: {
    my $scr_re = '<%perl> my $x = time(); </%perl>';
    is $m->execute( text => $scr_re), '';
}

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

MULTISTATEMENT_EXPR_BLOCK: {
    my $scr_re = '<% my $x = time(); $x %>';
    is $m->execute( text => $scr_re), time();
}

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

MULTIPLE_PERL_BLOCKS: {
    my $scr_re = '<%perl> my $x = time(); if (0) { </%perl> <%perl> } </%perl>';
    is $m->execute( text => $scr_re), '';
}

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

SINGLE_PERL_LINE_NEWLINES: {
    my $scr_re = "\n" . '% $_out->("Potato"); ' . "\n\n";
    my $res_re = "\nPotato\n";
    is $m->execute( text => $scr_re), $res_re;
}

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

NEWLINES_AND_PERL_LINES: {
    my $scr_hello = <<'ENDSCRIPT';
% if (1) {
<% "Does this work" %>
% }
correctly?
ENDSCRIPT

    my $res_hello = <<'ENDSCRIPT';
Does this work
correctly?
ENDSCRIPT

    is $m->execute( text => $scr_hello), $res_hello;
}

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

NEWLINES_AND_PERL_LINES: {
    my $scr_hello = <<'ENDSCRIPT';

% if ( $ARGS{name} eq 'Dave' ){
  I'm sorry <% $ARGS{name} %>, I'm afraid I can't do that right now.
% } else {
  Good afternoon, <% $ARGS{name} %>!
% }

ENDSCRIPT

    my $res_hello = <<'ENDSCRIPT';

  Good afternoon, Bob!

ENDSCRIPT

    is $m->execute( text => $scr_hello, name => 'Bob'), $res_hello;
    is $m->compile( text => $scr_hello)->( name => 'Bob' ), $res_hello;
}

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

PERL_BLOCK_AT_EOF: {
    my $scr_hello = 'Hello World<%perl>my $x = time();</%perl>';
    my $res_hello = 'Hello World';

    is $m->execute( text => $scr_hello), $res_hello;
}

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

ANGLE_PERCENT_BLOCK_AT_EOF: {
    my $scr_hello = '% my $noun = "World";' . "\n" . 'Hello <% $noun %>';
    my $res_hello = 'Hello World';

    is $m->execute( text => $scr_hello), $res_hello;
}

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

FILE_BLOCK_AT_EOF: {
    my $scr_hello = "<& 'samples/test-recur.msn', name => 'Dave' &>";
    my $res_hello = "Test greeting:\n" . 'Good afternoon, Dave!' . "\n";

    is $m->execute( text => $scr_hello), $res_hello;
}

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

LOOKS_LIKE_HTML: {
    my $scr_hello = '<TABLE border="1" width="100%"><tr><td>Hi</td></tr></table>';

    is $m->execute( text => $scr_hello), $scr_hello;
}

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

STRICT_VARS: {
    my $scr_re = '% $foo ++; ';
    is eval { $m->execute( text => $scr_re); 1 }, undef;
}

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

FILE_BLOCK_MULTILINE: {
    my $scr_hello = "<& \n 'samples/test-recur.msn', name => 'Dave' \n &>";
    my $res_hello = "Test greeting:\n" . 'Good afternoon, Dave!' . "\n";

    is $m->execute( text => $scr_hello), $res_hello;
}

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

TEXT_CONTAINS_OUT: {
    my $scr_inout = 'IN <% "and" %> OUT burger';
    my $res_inout = 'IN and OUT burger';
    is $m->execute( text => $scr_inout), $res_inout;
}

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