Skip to content

Commit

Permalink
Item14237: More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed Apr 27, 2017
1 parent f9aa0d6 commit db291f8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
44 changes: 43 additions & 1 deletion UnitTestContrib/test/unit/ConfigTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ sub test_expand {

Exps => {
Exp1 => 'Expanding ExpTest.Key2.Key2_1: ${ExpTest.Key2.Key2_1}',
NoExp1 => 'Must not expand \${ExpTest.Key2.Key2_1}',
NoExp1 => 'Must not expand ${$}{ExpTest.Key2.Key2_1}',
NoExp2 => 'Must not expand too: ${ExpTest.Key2.Key2_1${}} -',
ExpUndef => 'Undef: "${ExpTest.Key2.Key2_2}"',
},
};
Expand Down Expand Up @@ -666,6 +667,11 @@ sub test_expand {
"Single-valued str and key"
);

@estrs = $cfg->expandStr( key => 'ExpTest.Exps.NoExp2', );
$this->assert_deep_equals(
['Must not expand too: ${ExpTest.Key2.Key2_1} -'],
\@estrs, "Quoted finishing } must prevent expanding" );

@estrs =
$cfg->expandStr( key => [ 'ExpTest.Exps.Exp1', 'ExpTest.Exps.NoExp1', ],
);
Expand Down Expand Up @@ -708,6 +714,42 @@ qr/Failed to expand string '.*?': key ExpTest.Key1.UndefKey value is undefined/,
};
}

sub test_expandAll {
my $this = shift;

my $data = {
IntKey => 0,
SomeVal => "!!!",
Undef => undef,
List => [
'This is with IntKey=${IntKey}.',
{
A => 'A complex structure${SomeVal}',
U => 'With ${Undef} value',
},
],
};

$this->app->cfg->expandAll( data => $data, );

$this->assert_deep_equals(
{
'IntKey' => 0,
'List' => [
'This is with IntKey=0.',
{
'A' => 'A complex structure!!!',
'U' => 'With undef value'
}
],
'Undef' => undef,
'SomeVal' => '!!!'
},
$data,
"Expanded structure doesn't match"
);
}

sub test_ReadWriteLSC {
my $this = shift;

Expand Down
22 changes: 19 additions & 3 deletions UnitTestContrib/test/unit/FoswikiPmFunctionsTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package FoswikiPmFunctionsTests;
use v5.14;

use diagnostics -verbose;
use Foswiki();
use Foswiki ();
use File::Spec ();

use Moo;
use namespace::clean;
use Foswiki::Class;
extends qw( FoswikiFnTestCase );

sub TRACE { return 0; }
Expand Down Expand Up @@ -59,4 +59,20 @@ sub test_isValidTopicName_Aa_onlywikiname {
return;
}

sub test_guessLibDir {
my $this = shift;

local $ENV{FOSWIKI_LIBS};

my ( $v, $d, $f ) = File::Spec->splitpath(__FILE__);
my $updir = File::Spec->updir;
my @d = File::Spec->splitdir($d);
splice( @d, -3, 2, 'lib' );
my $myguess =
File::Spec->canonpath(
File::Spec->catpath( $v, File::Spec->catdir(@d), '' ) );
my $libDir = Foswiki::guessLibDir;
$this->assert_equals( $myguess, $libDir );
}

1;

0 comments on commit db291f8

Please sign in to comment.