Skip to content

Commit

Permalink
Item1699: Fix unit tests, and replaced some s/^_*(.*?)_*$/$1/ with 2 …
Browse files Browse the repository at this point in the history
…replacements. It's faster (yes, i benchmarked it), more readable, and more

git-svn-id: http://svn.foswiki.org/trunk@4085 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed Jun 10, 2009
1 parent 3427534 commit 66d6946
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/FormattingTests.pm
Expand Up @@ -567,7 +567,7 @@ sub test_USInHeader {
$Foswiki::cfg{RequireCompatibleAnchors} = 0;

my $expected = <<EXPECTED;
<nop><h3><a name="ATest_32with_32link_32in_32header:_32Underscore_95topic"></a>Test with link in header: Underscore_topic</h3>
<nop><h3><a name="Test_with_link_in_header:_Underscore_topic"></a>Test with link in header: Underscore_topic</h3>
EXPECTED

my $actual = <<ACTUAL;
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/RenderFormTests.pm
Expand Up @@ -361,7 +361,7 @@ sub test_render_for_edit {
<tr><th align="right">Issue Name</th><td align="left"><input type="text" name="IssueName" value="_An issue_" size="40" class="foswikiInputField" /></td></tr>
<tr><th align="right">State</th><td align="left"><table><tr><td><label><input type="radio" name="State" value="none" label="none" class="foswikiRadioButton"/>none</label></td></tr></table></td></tr>
<tr><th align="right">Issue Description</th><td align="left"><input type="hidden" name="IssueDescription" value="---+ Example problem" /><div><nop><h1>
<a name="AExample_32problem"> </a> Example problem </h1></div></td></tr>
<a name="Example_problem"> </a> Example problem </h1></div></td></tr>
<tr><th align="right">Issue 1</th><td align="left"><select name="Issue1" class="foswikiSelect" size="1"></select></td></tr>
<tr><th align="right">Issue 2EXTRA</th><td align="left">SWEET</td></tr>
<tr><th align="right">Issue 3</th><td align="left"><table></table><input type="hidden" name="Issue3" value="" /></td></tr>
Expand Down
4 changes: 2 additions & 2 deletions core/data/TestCases/TestCaseAutoFormatting.txt
Expand Up @@ -28,8 +28,8 @@ Designed by: Crawford Currie
---++ Headings
---+++ Expected
<!-- expected HEADS -->
<h2><a name="ASushi"></a>Sushi</h2>
<h3><a name="AMaguro"></a>Maguro</h3>
<h2><a name="Sushi_AN1"></a>Sushi</h2>
<h3><a name="Maguro_AN1"></a>Maguro</h3>
<!-- /expected -->
---+++ Actual
<!-- actual -->
Expand Down
2 changes: 1 addition & 1 deletion core/data/TestCases/TestCaseAutoIncludeAttachment.txt
Expand Up @@ -10,7 +10,7 @@ Designed by: Crawford Currie
---+ Existing attachment
---++ Expected
<!-- expected -->
<h1><a name="Aheading_321"></a>heading 1</h1>
<h1><a name="heading_1_AN1"></a>heading 1</h1>
<!-- /expected -->
---++ Actual
<!-- actual -->
Expand Down
26 changes: 13 additions & 13 deletions core/data/TestCases/TestCaseAutoTOC.txt
Expand Up @@ -15,15 +15,15 @@ Designed by: Crawford Currie
<a name=foswikiTOC />
<div class="foswikiToc">
<ul>
<li> <a href="%SCRIPTURLPATH{"view"}%/%WEB%/TocFixture?@URLPARAMS#ANonsense">Nonsense</a>
<li> <a href="%SCRIPTURLPATH{"view"}%/%WEB%/TocFixture?@URLPARAMS#Nonsense">Nonsense</a>
<ul>
<li> <a href="%SCRIPTURLPATH{"view"}%/%WEB%/TocFixture?@URLPARAMS#AMakes">Makes</a>
<li> <a href="%SCRIPTURLPATH{"view"}%/%WEB%/TocFixture?@URLPARAMS#Makes">Makes</a>
<ul>
<li> <a href="%SCRIPTURLPATH{"view"}%/%WEB%/TocFixture?@URLPARAMS#AContent">Content</a>
<li> <a href="%SCRIPTURLPATH{"view"}%/%WEB%/TocFixture?@URLPARAMS#Content">Content</a>
</li>
</ul>
</li>
<li> <a href="%SCRIPTURLPATH{"view"}%/%WEB%/TocFixture?@URLPARAMS#ATests">Tests</a>
<li> <a href="%SCRIPTURLPATH{"view"}%/%WEB%/TocFixture?@URLPARAMS#Tests">Tests</a>
</li>
</ul>
</li>
Expand All @@ -40,35 +40,35 @@ Designed by: Crawford Currie
<div class="foswikiToc">
<span class="foswikiTocTitle">The Top</span>
<ul>
<li> <a href="?@URLPARAMS#AH1_32_60_33_45_451_45_45_62">H1 <!--1--></a>
<li> <a href="?@URLPARAMS#H1_60_33_45_451_45_45_62">H1 <!--1--></a>
<ul>
<li> <a href="?@URLPARAMS#AH2">H2</a>
<li> <a href="?@URLPARAMS#H2">H2</a>
</li>
</ul>
</li>
<li> <a href="?@URLPARAMS#AH1_32_60_33_45_452_45_45_62">H1 <!--2--></a>
<li> <a href="?@URLPARAMS#H1_60_33_45_452_45_45_62">H1 <!--2--></a>
<ul>
<li> <a href="?@URLPARAMS#AH2_AN1">H2</a>
<li> <a href="?@URLPARAMS#H2_AN1">H2</a>
<ul>
<li>
<ul>
<li> <a href="?@URLPARAMS#ADon_39t_32ignore_32_32except_32this">Don't ignore</a>
<li> <a href="?@URLPARAMS#Don_39t_ignore_except_this">Don't ignore</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li> <a href="?@URLPARAMS#Ahash_32H1">hash H1</a>
<li> <a href="?@URLPARAMS#hash_H1">hash H1</a>
<ul>
<li> <a href="?@URLPARAMS#AH2_AN2">H2</a>
<li> <a href="?@URLPARAMS#H2_AN2">H2</a>
</li>
</ul>
</li>
<li> <a href="?@URLPARAMS#Ahash_32H1_AN1">hash H1</a>
<li> <a href="?@URLPARAMS#hash_H1_AN1">hash H1</a>
<ul>
<li> <a href="?@URLPARAMS#Anormal_32H2">normal H2</a>
<li> <a href="?@URLPARAMS#normal_H2">normal H2</a>
</li>
</ul>
</li>
Expand Down
6 changes: 4 additions & 2 deletions core/lib/Foswiki/Render.pm
Expand Up @@ -474,7 +474,8 @@ sub _makeAnchorName {

# clean up a bit
$text =~ s/__/_/g;
$text =~ s/^_*(.*?)_*$/$1/;
$text =~ s/^_*//;
$text =~ s/_*$//;

# Ensure the anchor always starts with an [A-Za-z]
$text = 'A_'.$text unless $text =~ /^[A-Za-z]/;
Expand Down Expand Up @@ -2120,7 +2121,8 @@ sub renderTOC {

# c.f. _makeAnchorHeading
my ( $level, $text ) = ( $1, $2 );
$text =~ s/^\s*(.*?)\s*$/$1/;
$text =~ s/^\s*//;
$text =~ s/\s*$//;

my $atext = $text;
$text =~ s/\s*$Foswiki::regex{headerPatternNoTOC}.*//o;
Expand Down

0 comments on commit 66d6946

Please sign in to comment.