| 1 | package Mason::t::Filters; | ||
| 2 | 1 | $Mason::t::Filters::VERSION = '2.24'; | |
| 3 | 1 | ▶ | use Test::Warn; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Test::Class::Most parent => 'Mason::Test::Class'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | sub test_basic : Tests { |
|
Subroutine
test_basic: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 7 | 1 | my $self = shift; | |
| 8 | 1 | $self->test_comp( | |
| 9 | src => ' | ||
| 10 | % sub { ucfirst(shift) } {{ | ||
| 11 | <% "hello world?" %> | ||
| 12 | % }} | ||
| 13 | ', | ||
| 14 | expect => ' | ||
| 15 | Hello world? | ||
| 16 | ', | ||
| 17 | ); | ||
| 18 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | 1 | ▶ | sub test_filters : Tests { |
|
Subroutine
test_filters: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 21 | 1 | my $self = shift; | |
| 22 | 1 | $self->test_comp( | |
| 23 | src => ' | ||
| 24 | <%class> | ||
| 25 | method Upper () { sub { uc(shift) } } | ||
| 26 | </%class> | ||
| 27 | |||
| 28 | % $.Upper {{ # start Upper | ||
| 29 | Hello World. | ||
| 30 | % }} # end Upper | ||
| 31 | |||
| 32 | % sub { ucfirst(shift) } {{ | ||
| 33 | <% "hello world?" %> | ||
| 34 | % }} | ||
| 35 | |||
| 36 | % sub { tr/A-Z/a-z/; $_ } {{ | ||
| 37 | Hello World! | ||
| 38 | % }} | ||
| 39 | ', | ||
| 40 | expect => ' | ||
| 41 | HELLO WORLD. | ||
| 42 | Hello world? | ||
| 43 | hello world! | ||
| 44 | ', | ||
| 45 | ); | ||
| 46 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 47 | |||
| 48 | 1 | ▶ | sub test_filter_pipe : Tests { |
|
Subroutine
test_filter_pipe: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 49 | 1 | my $self = shift; | |
| 50 | 1 | $self->test_comp( | |
| 51 | src => ' | ||
| 52 | <%class> | ||
| 53 | method Upper () { sub { uc(shift) } } | ||
| 54 | method Lower () { sub { lc(shift) } } | ||
| 55 | method UpFirst () { sub { ucfirst(shift) } } | ||
| 56 | </%class> | ||
| 57 | |||
| 58 | <% "HELLO" | Lower %> | ||
| 59 | <% "hello" | UpFirst %> | ||
| 60 | <% "HELLO" | UpFirst,Lower %> | ||
| 61 | <% "hello" | Lower, UpFirst %> | ||
| 62 | <% "HeLlO" | Lower, Upper %> | ||
| 63 | <% "HeLlO" | Upper, Lower %> | ||
| 64 | ', | ||
| 65 | expect => ' | ||
| 66 | hello | ||
| 67 | Hello | ||
| 68 | Hello | ||
| 69 | hello | ||
| 70 | hello | ||
| 71 | HELLO | ||
| 72 | ', | ||
| 73 | ); | ||
| 74 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 75 | |||
| 76 | 1 | ▶ | sub test_filter_block : Tests { |
|
Subroutine
test_filter_block: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 77 | 1 | my $self = shift; | |
| 78 | 1 | $self->test_comp( | |
| 79 | src => ' | ||
| 80 | <%filter MyRepeat ($count)> | ||
| 81 | % for (my $i=0; $i<$count; $i++) { | ||
| 82 | * <% $yield->() %>\ | ||
| 83 | % } | ||
| 84 | </%filter> | ||
| 85 | |||
| 86 | % my $count = 0; | ||
| 87 | % $.MyRepeat(3) {{ | ||
| 88 | count = <% ++$count %> | ||
| 89 | % }} | ||
| 90 | |||
| 91 | <%perl> | ||
| 92 | my $content = $m->filter($.MyRepeat(2), sub { "count == " . ++$count . "\n" }); | ||
| 93 | print(uc($content)); | ||
| 94 | </%perl> | ||
| 95 | ', | ||
| 96 | expect => ' | ||
| 97 | * count = 1 | ||
| 98 | * count = 2 | ||
| 99 | * count = 3 | ||
| 100 | * COUNT == 4 | ||
| 101 | * COUNT == 5 | ||
| 102 | ', | ||
| 103 | ); | ||
| 104 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 105 | |||
| 106 | 1 | ▶ | sub test_lexical : Tests { |
|
Subroutine
test_lexical: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 107 | 1 | my $self = shift; | |
| 108 | 1 | $self->test_comp( | |
| 109 | src => <<'EOF', | ||
| 110 | % my $msg = "Hello World"; | ||
| 111 | % sub { lc(shift) } {{ | ||
| 112 | <% $msg %> | ||
| 113 | % }} | ||
| 114 | EOF | ||
| 115 | expect => 'hello world', | ||
| 116 | ); | ||
| 117 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 118 | |||
| 119 | 1 | ▶ | sub test_repeat : Tests { |
|
Subroutine
test_repeat: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 120 | 1 | my $self = shift; | |
| 121 | 1 | $self->test_comp( | |
| 122 | src => <<'EOF', | ||
| 123 | % my $i = 1; | ||
| 124 | % $.Repeat(3) {{ | ||
| 125 | i = <% $i++ %> | ||
| 126 | % }} | ||
| 127 | EOF | ||
| 128 | expect => <<'EOF', | ||
| 129 | i = 1 | ||
| 130 | i = 2 | ||
| 131 | i = 3 | ||
| 132 | EOF | ||
| 133 | ); | ||
| 134 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 135 | |||
| 136 | 1 | ▶ | sub test_nested : Tests { |
|
Subroutine
test_nested: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 137 | 1 | my $self = shift; | |
| 138 | 1 | $self->test_comp( | |
| 139 | src => <<'EOF', | ||
| 140 | % sub { ucfirst(shift) } {{ | ||
| 141 | % sub { tr/e/a/; $_ } {{ | ||
| 142 | % sub { lc(shift) } {{ | ||
| 143 | HELLO | ||
| 144 | % }} | ||
| 145 | % }} | ||
| 146 | % }} | ||
| 147 | goodbye | ||
| 148 | |||
| 149 | % sub { ucfirst(shift) }, sub { tr/e/a/; $_ }, sub { lc(shift) } {{ | ||
| 150 | HELLO | ||
| 151 | % }} | ||
| 152 | goodbye | ||
| 153 | EOF | ||
| 154 | expect => <<'EOF', | ||
| 155 | Hallo | ||
| 156 | goodbye | ||
| 157 | |||
| 158 | Hallo | ||
| 159 | goodbye | ||
| 160 | EOF | ||
| 161 | ); | ||
| 162 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 163 | |||
| 164 | 1 | ▶ | sub test_misc_standard_filters : Tests { |
|
Subroutine
test_misc_standard_filters: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 165 | 1 | my $self = shift; | |
| 166 | |||
| 167 | 1 | $self->test_comp( | |
| 168 | src => 'the <% $m->filter($.Trim, " quick brown ") %> fox', | ||
| 169 | expect => 'the quick brown fox' | ||
| 170 | ); | ||
| 171 | 1 | $self->test_comp( | |
| 172 | src => ' | ||
| 173 | % $.Capture(\my $buf) {{ | ||
| 174 | 2 + 2 = <% 2+2 %> | ||
| 175 | % }} | ||
| 176 | <% reverse($buf) %> | ||
| 177 | |||
| 178 | % $.Tee(\my $buf2) {{ | ||
| 179 | 3 + 3 = <% 3+3 %> | ||
| 180 | % }} | ||
| 181 | <% reverse($buf2) %> | ||
| 182 | |||
| 183 | --- | ||
| 184 | % $.NoBlankLines {{ | ||
| 185 | |||
| 186 | one | ||
| 187 | |||
| 188 | |||
| 189 | |||
| 190 | |||
| 191 | two | ||
| 192 | |||
| 193 | % }} | ||
| 194 | --- | ||
| 195 | ', | ||
| 196 | expect => ' | ||
| 197 | 4 = 2 + 2 | ||
| 198 | |||
| 199 | 3 + 3 = 6 | ||
| 200 | |||
| 201 | 6 = 3 + 3 | ||
| 202 | |||
| 203 | --- | ||
| 204 | one | ||
| 205 | two | ||
| 206 | --- | ||
| 207 | |||
| 208 | ', | ||
| 209 | ); | ||
| 210 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 211 | |||
| 212 | 1 | ▶ | sub test_compcall_filter : Tests { |
|
Subroutine
test_compcall_filter: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 213 | 1 | my $self = shift; | |
| 214 | |||
| 215 | 1 | $self->add_comp( | |
| 216 | path => '/list_items.mi', | ||
| 217 | src => ' | ||
| 218 | <%class> | ||
| 219 | has "items"; | ||
| 220 | has "yield"; | ||
| 221 | </%class> | ||
| 222 | |||
| 223 | % foreach my $item (@{$.items}) { | ||
| 224 | <% $.yield->($item) %> | ||
| 225 | % } | ||
| 226 | ', | ||
| 227 | ); | ||
| 228 | 1 | $self->test_comp( | |
| 229 | src => ' | ||
| 230 | % $.CompCall ("list_items.mi", items => [1,2,3]) {{ | ||
| 231 | <li><% $_[0] %></li> | ||
| 232 | % }} | ||
| 233 | ', | ||
| 234 | expect => ' | ||
| 235 | <li>1</li> | ||
| 236 | |||
| 237 | <li>2</li> | ||
| 238 | |||
| 239 | <li>3</li> | ||
| 240 | ', | ||
| 241 | ); | ||
| 242 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 243 | |||
| 244 | 1 | ▶ | sub test_around : Tests { |
|
Subroutine
test_around: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 245 | 1 | my $self = shift; | |
| 246 | 1 | $self->test_comp( | |
| 247 | src => <<'EOF', | ||
| 248 | hello | ||
| 249 | |||
| 250 | <%around main> | ||
| 251 | % sub { uc($_[0]) } {{ | ||
| 252 | % $self->$orig(); | ||
| 253 | % }} | ||
| 254 | </%around> | ||
| 255 | |||
| 256 | EOF | ||
| 257 | expect => <<'EOF', | ||
| 258 | HELLO | ||
| 259 | EOF | ||
| 260 | ); | ||
| 261 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 262 | |||
| 263 | # Test old filter syntax, still currently supported | ||
| 264 | # | ||
| 265 | 1 | ▶ | sub test_old_syntax : Tests { |
|
Subroutine
test_old_syntax: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 266 | 1 | my $self = shift; | |
| 267 | 1 | $self->test_comp( | |
| 268 | src => ' | ||
| 269 | <%class> | ||
| 270 | method Upper () { sub { uc(shift) } } | ||
| 271 | </%class> | ||
| 272 | |||
| 273 | <% $.Upper { %> | ||
| 274 | Hello World. | ||
| 275 | </%> | ||
| 276 | |||
| 277 | <% sub { ucfirst(shift) } { %> | ||
| 278 | <% "hello world?" %> | ||
| 279 | <% } %> | ||
| 280 | |||
| 281 | <% sub { lc(shift) } { %> | ||
| 282 | Hello World! | ||
| 283 | </%> | ||
| 284 | ', | ||
| 285 | expect => ' | ||
| 286 | HELLO WORLD. | ||
| 287 | Hello world? | ||
| 288 | hello world! | ||
| 289 | ', | ||
| 290 | ); | ||
| 291 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 292 | |||
| 293 | 1 | ▶ | sub test_filter_comment : Tests { |
|
Subroutine
test_filter_comment: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 294 | 1 | my $self = shift; | |
| 295 | 1 | $self->test_comp( | |
| 296 | src => ' | ||
| 297 | <%class> | ||
| 298 | method LESSp () { sub { uc(shift) } } | ||
| 299 | </%class> | ||
| 300 | % $.LESSp {{ | ||
| 301 | #header { | ||
| 302 | text-align: left; | ||
| 303 | } | ||
| 304 | % }} | ||
| 305 | #footer { | ||
| 306 | text-align: right; | ||
| 307 | } | ||
| 308 | ', | ||
| 309 | expect => ' | ||
| 310 | #HEADER { | ||
| 311 | TEXT-ALIGN: LEFT; | ||
| 312 | } | ||
| 313 | #footer { | ||
| 314 | text-align: right; | ||
| 315 | } | ||
| 316 | ', | ||
| 317 | ); | ||
| 318 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 319 | |||
| 320 | 1 | ▶ | sub test_no_undef_warning : Tests { |
|
Subroutine
test_no_undef_warning: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 321 | 1 | my $self = shift; | |
| 322 | 1 | ▶ | warnings_are { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 323 | 1 | $self->test_comp( | |
| 324 | src => ' | ||
| 325 | <%class> | ||
| 326 | method Upper () { sub { uc(shift) } } | ||
| 327 | method Upper2 () { | ||
| 328 | return Mason::DynamicFilter->new( | ||
| 329 | filter => sub { | ||
| 330 | my $yield = $_[0]; | ||
| 331 | return uc($yield->()); | ||
| 332 | } | ||
| 333 | ); | ||
| 334 | } | ||
| 335 | </%class> | ||
| 336 | |||
| 337 | <%filter Upper3> | ||
| 338 | <% uc($yield->()) %> | ||
| 339 | </%filter> | ||
| 340 | |||
| 341 | a = <% "a" | Upper %>. | ||
| 342 | undef = <% undef | Upper %>. | ||
| 343 | |||
| 344 | a = <% "a" | Upper2 %>. | ||
| 345 | undef = <% undef | Upper2 %>. | ||
| 346 | |||
| 347 | a = <% "a" | Upper3 %>. | ||
| 348 | undef = <% undef | Upper3 %>. | ||
| 349 | ', | ||
| 350 | expect => ' | ||
| 351 | a = A. | ||
| 352 | undef = . | ||
| 353 | |||
| 354 | a = A. | ||
| 355 | undef = . | ||
| 356 | |||
| 357 | a = A. | ||
| 358 | undef = . | ||
| 359 | ', | ||
| 360 | ); | ||
| 361 | } | ||
| 362 | 1 | [], "no warnings on undef"; | |
| 363 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 364 | |||
| 365 | 1 | 1; | |