File: synopsis_text_hogan_compiler.t

package info (click to toggle)
libtext-hogan-perl 2.01-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 240 kB
  • sloc: perl: 826; sh: 4; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 988 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;

use Text::Hogan::Compiler;

my $compiler = Text::Hogan::Compiler->new;

my $text = "Hello, {{name}}!";

my $tokens   = $compiler->scan($text);
my $tree     = $compiler->parse($tokens, $text);
my $template = $compiler->generate($tree, $text);

is $template->render({ name => "Alex" }), "Hello, Alex!", "Text::Hogan::Compiler synopsis works";

# whitespace testing
my $ws_template = '{{ # foo }}do not render if whitespace allowed{{ / foo }}';
my $ws_data = { foo => 0 };

my $ws_compiler = Text::Hogan::Compiler->new();

is $ws_compiler->compile( $ws_template, { 'allow_whitespace_before_hashmark' => 0 } )->render($ws_data),
  "do not render if whitespace allowed",
  "Text::Hogan::Compiler doesn't allow whitespace between delimeters and tag type ...";
is $ws_compiler->compile( $ws_template, { 'allow_whitespace_before_hashmark' => 1 } )->render($ws_data),
  "",
  "... unless specified in the options";

done_testing();