Skip to content

Commit

Permalink
Item12185: Deal with precompiled regular exp.
Browse files Browse the repository at this point in the history
The regular expressions for wikiword / acronym linking are precompiled
with the /o option.  The only way I've found to actually change the
acronym length for this test is to unload Render.pm and then
re-initialize it.

If Class::Unload is not available, the test is skipped.

git-svn-id: http://svn.foswiki.org/trunk@15700 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Oct 24, 2012
1 parent 7ed1a09 commit 4f62b92
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions UnitTestContrib/test/unit/FormattingTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ sub skip {
tests => {
'FormattingTests::test_lists' =>
'Post-Foswiki 1.1.x TML syntax',
'FormattingTests::test_shortAcronyms' =>
'Post-Foswiki 1.1.x TML syntax',
},
condition => { without_dep => 'Class::Unload' },
tests => {
'FormattingTests::test_shortAcronyms' =>
'Missing Class::Unload',
}
}
);
Expand Down Expand Up @@ -947,14 +954,8 @@ ACTUAL
sub test_Acronyms {
my $this = shift;

# SMELL: These are built in BEGIN block of Foswiki.pm
# Need to re-initialize them here to change the length
my $abbrevLength = 3;
$Foswiki::regex{abbrevRegex} =
qr/[$Foswiki::regex{upperAlpha}]{$abbrevLength,}s?\b/o;

my $expected = <<EXPECTED;
<strong><em>text with <a href="/$this->{test_web}/ABC">ABC</a> link</em></strong>
<strong><em>text with <a href="$this->{sup}/$this->{test_web}/ABC">ABC</a> link</em></strong>
EXPECTED

my $actual = <<ACTUAL;
Expand All @@ -975,14 +976,22 @@ ACTUAL
sub test_shortAcronyms {
my $this = shift;

# SMELL: These are built in BEGIN block of Foswiki.pm
# SMELL: The regexes built in BEGIN block of Foswiki.pm
# Need to re-initialize them here to change the length
# Also, they are used and pre-compiled when Foswiki::Render
# is loaded. So Render has to be reloaded to recomplile the
# regular expressions.
my $abbrevLength = 2;
$Foswiki::regex{abbrevRegex} =
qr/[$Foswiki::regex{upperAlpha}]{$abbrevLength,}s?\b/o;
qr/[$Foswiki::regex{upperAlpha}]{$abbrevLength,}s?\b/;
require Class::Unload;
$this->{session}->renderer->finish();
Class::Unload->unload('Foswiki::Render');
require Foswiki::Render;
$this->{session}->{renderer} = new Foswiki::Render( $this->{session} );

my $expected = <<EXPECTED;
<strong><em>text with <a href="/$this->{test_web}/ABC">ABC</a> link</em></strong>
<strong><em>text with <a href="$this->{sup}/$this->{test_web}/ABC">ABC</a> link</em></strong>
EXPECTED

my $actual = <<ACTUAL;
Expand All @@ -992,14 +1001,25 @@ ACTUAL

# Try a shorter length
$expected = <<EXPECTED;
<strong><em>text with <a href="/$this->{test_web}/AB">AB</a> link</em></strong>
<strong><em>text with <a href="$this->{sup}/$this->{test_web}/AB">AB</a> link</em></strong>
EXPECTED

$actual = <<ACTUAL;
__text with AB link__
ACTUAL
$this->do_test( $expected, $actual );

# SMELL: Reset the regular expressions back to default
# and compile render again so subsequent tests don't fail.
$abbrevLength = $Foswiki::cfg{AcronymLength} || 3;
$Foswiki::regex{abbrevRegex} =
qr/[$Foswiki::regex{upperAlpha}]{$abbrevLength,}s?\b/;
require Class::Unload;
$this->{session}->renderer->finish();
Class::Unload->unload('Foswiki::Render');
require Foswiki::Render;
$this->{session}->{renderer} = new Foswiki::Render( $this->{session} );

}

sub test_squabbedEmmedTopic {
Expand Down

0 comments on commit 4f62b92

Please sign in to comment.