#!/usr/bin/perl use strict; use warnings; use Test::More; use lib 'lib'; use helper; BEGIN { use_ok( 'SugarTrail::Template::Condition' ); } require_ok( 'SugarTrail::Template::Condition' ); my $params = { os => "wxx", proto => "imap" }; my $c; my $test; $test = "normal condition:"; $c = SugarTrail::Template::Condition->new('proto==imap'); ok($c, "$test: c is true"); ok($c->match($params), "$test: params match"); my @badsyn = ("", "==", "pop imap", "==imap", "pop=="); for my $bad (@badsyn) { $test = "syntax: '$bad' "; $c = SugarTrail::Template::Condition->new($bad); ok($c, "$test: c true (late parsing)"); ok(!($c->{error}), "$test: c has no error before match attempt"); ok(!($c->match($params)), "$test: c does not match"); ok($c->{error}, "$test: c has error after match attempt"); like($c->{error}, qr/^syntax error\W/, "$test: error content"); } done_testing();