!! Version 2

# Force the test runner to ensure the extension is loaded
!! hooks
section
!! endhooks

!! functionhooks
lst
lstx
!! endfunctionhooks

# This is the standard article assumed to exist.
!! article
Sections
!! text
1 <section begin=1/>sec 1<section end=1/>

2 <section begin="2"/>sec 2<section end='2'/>

3 <section begin="3" />sec 3<section end="3" />

a <section begin=a/>sec a<section end=a/>

<section begin=a/>...<section end=a/>
!! endarticle

!! article
Sections in German
!! text
1 <Abschnitt Anfang=1/>sec 1<Abschnitt Ende=1/>

2 <Abschnitt Anfang="2"/>sec 2<Abschnitt Ende='2'/>

3 <Abschnitt Anfang="3" />sec 3<Abschnitt Ende="3" />

a <Abschnitt Anfang=a/>sec a<Abschnitt Ende=a/>

<Abschnitt Anfang=a/>...<Abschnitt Ende=a/>
!! endarticle

#test to see what happens when we don't use LST.
!! test
LST: Normal rendering
!! wikitext
begin <section begin=test/>middle<section end=test/> end
!! html
<p>begin middle end
</p>
!! end

!! test
LST: Normal (non-labelled) transclusion
!! wikitext
{{:sections}}
!! html
<p>1 sec 1
</p><p>2 sec 2
</p><p>3 sec 3
</p><p>a sec a
</p><p>...
</p>
!! end

!! test
LST: Transclude a section (#lst)
!! wikitext
{{#lst:sections|1}}
!! html
<p>sec 1
</p>
!! end

!! test
LST: Transclude a section in German (#lst)
!! options
language=de
!! wikitext
{{#lst:sections in German|1}}
!! html
<p>sec 1
</p>
!! end

!! test
LST: Transclude a section (#section)
!! wikitext
{{#section:sections|1}}
!! html
<p>sec 1
</p>
!! end

!! test
LST: Substitute a section
!! options
pst
!! wikitext
{{subst:#lst:sections|1}}
!! html
sec 1
!! end


!! test
LST: Substitute a section with quoted attributes
!! wikitext
{{#lst:sections|2}}
!! html
<p>sec 2
</p>
!! end

!! test
LST: Substitute a section with an optional /
!! wikitext
{{#lst:sections|3}}
!! html
<p>sec 3
</p>
!! end

!! test
LST: multiple sections with the same name
!! wikitext
{{#lst:sections|a}}
!! html
<p>sec a...
</p>
!! end

!! test
LST: Transclude range of sections
!! wikitext
{{#lst:sections|1|3}}
!! html
<p>sec 1
</p><p>2 sec 2
</p><p>3 sec 3
</p>
!! end

!! test
LST: Exclude a section
!! wikitext
{{#lstx:sections|1}}
!! html
<p>1 
</p><p>2 sec 2
</p><p>3 sec 3
</p><p>a sec a
</p><p>...
</p>
!! end

!! test
LST: Exclude a range
!! wikitext
{{#lstx:sections|1||3}}
!! html
<p>1 
</p><p>a sec a
</p><p>...
</p>
!! end

!! test
LST: Replace a section
!! wikitext
{{#lstx:sections|1|one}}
!! html
<p>1 one
</p><p>2 sec 2
</p><p>3 sec 3
</p><p>a sec a
</p><p>...
</p>
!! end

!! test
LST: Replace multiple sections
!! wikitext
{{#lstx:sections|a|A}}
!! html
<p>1 sec 1
</p><p>2 sec 2
</p><p>3 sec 3
</p><p>a A
</p><p>A
</p>
!! end

!! test
LST: Replace a range
!! wikitext
{{#lstx:sections|1|test|3}}
!! html
<p>1 test
</p><p>a sec a
</p><p>...
</p>
!! end

!! article
template:lst-sub
!! text
<<includeonly>section {{{1}}}=test</includeonly>/>
!! endarticle

!! test
LST: Substitute a tag from a template
!! options
pst noxml
!! wikitext
{{subst:lst-sub|begin}}
!! html
<section begin=test/>
!! end

!! article
lst-nest
!! text
<section begin=outer/>
I am outer
<section begin=inner/>
inner
<section end=inner/>
<section end=outer/>
!! endarticle

!! test
LST: Nested sections - inner section marks removed by tag hook.
!! wikitext
{{#lst:lst-nest|outer}}
!! html
<p>I am outer
</p><p>inner
</p><p><br />
</p>
!! end

!! test
LST: red link from nonexistent article
!! wikitext
{{#lst:no such article|anything}}
!! html
<p><a href="/index.php?title=No_such_article&amp;action=edit&amp;redlink=1" class="new" title="No such article (page does not exist)">No such article</a>
</p>
!! end

# Note: MW <= 1.8 uses a different section header format. In these versions, the header out will look like this instead:
# <div class="editsection" style="float:right;margin-left:5px;">[<a href="/index.php?title=Headings&amp;action=edit&amp;section=T-1" title="Headings">edit</a>]</div><a name="section"></a><h2>section</h2>
!! article
headings
!! text
<section begin=head/>
==section==
blah
<section end=head/>
<section begin=head2/>
==section2==
blah
<section end=head2/>
!! endarticle

!! test
LST: Transcluded section headings create edit link to template
!! wikitext
{{#lst:headings|head}}
!! html
<h2><span class="mw-headline" id="section">section</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Headings&amp;action=edit&amp;section=T-1" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>blah
</p>
!! end

!! test
LST: Transcluded section headings create edit link to right section (mw 1.9r18218)
!! wikitext
{{#lst:headings|head2}}
!! html
<h2><span class="mw-headline" id="section2">section2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Headings&amp;action=edit&amp;section=T-2" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>blah
</p>
!! end

!! article
lst_head_bounds
!! text
===
=2=
<section begin=s/>
=3=
hi
=4=
<section end=s/>
=head4=
!! endarticle

!! test
LST: more sensitive test for heading count boundaries.
!! wikitext
{{#lst:lst_head_bounds|s}}
!! html
<h1><span class="mw-headline" id="3">3</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Lst_head_bounds&amp;action=edit&amp;section=T-3" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<p>hi
</p>
<h1><span class="mw-headline" id="4">4</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Lst_head_bounds&amp;action=edit&amp;section=T-4" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
!! end


!! test
LST: Nick's bogus input
!! wikitext
{{#lstx:</
includeonly>
{|}}
!! html
!! end

!! article
lst_javascript
!! text
<section begin=ownage />
<script>alert("Ownage!");</script>
<section end=ownage />
!! endarticle

!! test
LST: javascript
!! wikitext
{{#lst:lst javascript|ownage}}
!! html
<p>&lt;script&gt;alert("Ownage!");&lt;/script&gt;
</p>
!! end

!! article
lst-slash
!! text
<section begin="/"/>slash<section end="/"/>
!! endarticle

!! test
LST: regexp special chars in section name
!! wikitext
{{#lst:lst-slash|/}}
!! html
<p>slash
</p>
!! end

# We can't use the simplest case where the article transcludes itself
# from a regression test (bug 8158).  This test will segv if the cycle
# detection code in the extension fails.
!! article
lst-cycle
!! text
<section begin=cycle/>{{#lst:lst-cycle|cycle}}<section end=cycle/>
!! endarticle

!! test
LST: cycle detection
!! options
!! wikitext
{{#lst:lst-cycle|cycle}}
!! html
<p><span class="error">Template loop detected: <a href="/wiki/Lst-cycle" title="Lst-cycle">Lst-cycle</a></span>
</p>
!! end

#make sure we can still multiply-transclude (that is, path is cleared)
!! test
LST: multiple transclude
!! wikitext
{{#lst:sections|1}}
{{#lst:sections|1}}
!! html
<p>sec 1
sec 1
</p>
!! end

!! test
LST: transclude nonexistent section
!! wikitext
{{#lst:sections|9999}}
!! html
!! end

!! article
LST-alt
!! text
<section Begin=1/>caps<section END=1/>
<section com=test begin=2 ent=test />junk<section x=y end=2 boo=hoo/>
!! endarticle
!! test
LST: alternate caps
!! wikitext
{{#section:LST-alt|1}}
!! html
<p>caps
</p>
!! end

!! test
LST: useless options
!! wikitext
{{#section:LST-alt|2}}
!! html
<p>junk
</p>
!! end

!! article
lst-fromsection
!! text
Before...
<section begin="A"/>SectionA<section end="A"/>
<section begin="B"/>SectionB<section end="B"/>
<section begin="C"/>SectionC<section end="C"/>
...After
!! endarticle

!! test
LST: inclusion starting at a specified section till the end of article
!! options
!! wikitext
{{#lst:lst-fromsection|B|}}
!! html
<p>SectionB
SectionC
...After
</p>
!! end

!! article
lst-tosection
!! text
Before...
<section begin="A"/>SectionA<section end="A"/>
<section begin="B"/>SectionB<section end="B"/>
<section begin="C"/>SectionC<section end="C"/>
...After
!! endarticle

!! test
LST: inclusion from beginning of article to a specified section
!! options
!! wikitext
{{#lst:lst-tosection||B}}
!! html
<p>Before...
SectionA
SectionB
</p>
!! end

!! article
lst-status
!! text
<section begin="latest" />c<section end="latest" />
<section begin="a" />sec a<section end="a" />
<section begin="b" />sec b<section end="b" />
<section begin="c" />sec c<section end="c" />
!! endarticle

!! test
LST: Allow subtransclusion in lst argument (bug 42481)
!! wikitext
{{#lst:lst-status|latest}}: {{#lst:lst-status|{{#lst:lst-status|latest}}}}
!! html
<p>c: sec c
</p>
!! end

!! article
lst-selfinclusion1
!! text
<section begin="A"/>
Section A begin
{{#lst:lst-selfinclusion2|B}}
Section A end
<section end="A"/>
!! endarticle

!! article
lst-selfinclusion2
!! text
<section begin="B"/>
Section B begin
{{#lst:lst-selfinclusion1|A}}
Section B end
<section end="B"/>
!! endarticle

!! test
LST: verify self-inclusion fails
!! options
!! wikitext
{{#lst:lst-selfinclusion1|A}}
!! html
<p>Section A begin
</p><p>Section B begin
<span class="error">Template loop detected: <a href="/wiki/Lst-selfinclusion1" title="Lst-selfinclusion1">Lst-selfinclusion1</a></span>
Section B end
</p><p>Section A end
</p>
!! end

!! article
lst-redirected
!! text
#REDIRECT[[Sections]]
!! endarticle

!! test
LST: Transclude a section via a redirect
!! wikitext
{{#lst:lst-redirected|1}}
!! html
<p>sec 1
</p>
!! end

!! article
lst-noinclude
!! text
<noinclude>before</noinclude>
<section begin="a" />sec a<section end="a" />
<noinclude>after</noinclude>
!! endarticle

!! test
LST: Noinclude tags should not be included - start at section
!! wikitext
{{#lst:lst-noinclude|a|}}
!! html
<p>sec a
</p>
!! end

!! test
LST: Noinclude tags should not be included - end at section
!! wikitext
{{#lst:lst-noinclude||a}}
!! html
<p>sec a
</p>
!! end

!! article
User:DifferentNamespace/subpage
!! text
<section begin="a" />sec a<section end="a" />
!! endarticle

!! test
LST: Transclusion from subpage in a non-standard namespace
!! wikitext
{{#lst:User:DifferentNamespace/subpage|a}}
!! html
<p>sec a
</p>
!! end