File: 01parse.t

package info (click to toggle)
libhtml-template-expr-perl 0.07-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 248 kB
  • sloc: perl: 285; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,396 bytes parent folder | download | duplicates (4)
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
use Test::More qw(no_plan);
use Parse::RecDescent;

use constant DEBUG => 0;
$::RD_HINT = DEBUG;
# $::RD_TRACE = 1;

use HTML::Template::Expr;
use Data::Dumper;



# test grammar directly

my @tests = (
             "(foo > 10)",
             "((foo < 10) != (bar > 10))",
             "('foo' eq 'bar')",
             "((foo + 10.1) > 100)",
             "(((foo > 10) || (200 < bar)) + 10.5)",
             "(call(foo, 10, 20, 30))",
             "(call(foo, 10) > 10)",
             "(first( foo, 10 ))",
             "(call(foo, \"baz\", 10) eq 'string val')", 
             "((foo < 10) != (bar > 10))",
             "(((call(foo, 10) + 100) > 10) || (foo eq \"barf\"))",
             "((foo > bar))",
	     "call(call2(call3()))",
	     "call(foo > bar)",
             "(foo || bar || baz || bif)",
             "((foo || bar || baz) && bif)",
             "((foo || bar || baz) && (bif || 10))",
	    );

foreach my $test (@tests) {
    print STDERR "TRYING TO PARSE $test\n" if DEBUG;
    my $tree = $HTML::Template::Expr::PARSER->expression($test);
    ok($tree, "parsing \"$test\"");
    if (DEBUG) {
        local $Data::Dumper::Indent = 1;
        local $Data::Dumper::Purity = 0;
        local $Data::Dumper::Deepcopy = 1;
        print STDERR Data::Dumper->Dump([\$tree],['$tree']);
        print STDERR "vars: ", join(',', HTML::Template::Expr::_expr_vars($tree)), "\n\n";
    }
}