Commit 29d90718 authored by Xavier Guimard's avatar Xavier Guimard

More tests (#1151)

parent 09906399
......@@ -73,7 +73,7 @@ sub parseAnd {
my ( $self, $moduleList, $expr ) = @_;
if ( $expr =~ /\]\s*and\s*\[/ ) {
my @mod = ( [], [] );
foreach my $part ( split /\]\s*and\s*\[/, $expr ) {
foreach my $part ( split /\s*and\s*/, $expr ) {
my $tmp = $self->parseBlock( $moduleList, $part );
push @{ $mod[0] }, $tmp->[0];
push @{ $mod[1] }, $tmp->[1];
......
use Test::More tests => 27;
use Test::More tests => 32;
use strict;
my $m = 'Lemonldap::NG::Common::Combination::Parser';
......@@ -21,8 +21,8 @@ ok( ref( $m->parse( $authMods, '[A]' )->()->[0]->[0] ) eq 'CODE',
'Fourth level is a sub' );
my @tests = (
'[A]' => 'A' => 'A',
'[A,B]' => 'A' => 'B',
'[A]', 'A', 'A',
'[A,B]', 'A', 'B',
'if(1) then [A,B] else [B,C]', 'A', 'B',
'if(0) then [A,B] else [B,C]', 'B', 'C',
'if(0) then [A,B] else if(1) then [B,C] else [B,A]', 'B', 'C',
......@@ -42,6 +42,7 @@ while ( my $expr = shift @tests ) {
or print STDERR "Expect $udb, get " . userDBName($expr) . "\n";
}
# Test "or"
ok(
_call( '[A,B] or [B,C]', 'name', 0, 1 ) eq 'B',
'"[A,B] or [B,C]" returns 2 elements'
......@@ -52,6 +53,34 @@ ok(
'"if(1) then [A,B] or [C,A] else [B,C]" returns 2 elements'
);
# Test "and"
@tests = (
'[A and B, A]',
'[A,B] and [B,C]',
'if(0) then [A,B] else [A,B] and [B,C]'
);
while ( my $expr = shift @tests ) {
ok( getok($expr) == 0, qq{"$expr" returns PE_OK as auth result} )
or print STDERR "Expect 0, get " . getok($expr) . "\n";
}
# Test bad expr
@tests = (
'if(1) then {if(1) then [A] else [B]} else [C]',
'[A,B or C]',
);
foreach(@tests) {
ok(!eval{authName($_)}, qq'Bad expr "$_"');
}
sub getok {
my ( $expr, $ind ) = @_;
return _call( $expr, 'ok', 0, 0 );
}
sub authName {
my ( $expr, $ind ) = @_;
return _call( $expr, 'name', 0, 0 );
......@@ -78,3 +107,7 @@ sub new {
sub name {
$_[0]->{name};
}
sub ok {
return 0; # PE_OK
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment