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

!! test
Simple <ref>, no <references/>
!! input
Wikipedia rocks!<ref>Proceeds of Rockology, vol. XXI</ref>
!! result
Wikipedia rocks![1]
- ↑ Proceeds of Rockology, vol. XXI

!! end

!! test
Simple <ref>, with <references/>
!! input
Wikipedia rocks!<ref>Proceeds of Rockology, vol. XXI</ref>

<references/>
!! result

Wikipedia rocks![1]

- ↑ Proceeds of Rockology, vol. XXI

!! end

!! article
Template:Simple template
!! text
A ''simple'' template.
!! endarticle

!! test
<ref> with a simple template
!! input
Templating<ref>{{simple template}}</ref>

<references/>
!! result

Templating[1]

- ↑ A simple template.

!! end

!! test
<ref> with a <nowiki>
!! input
Templating<ref><nowiki>{{simple template}}</nowiki></ref>

<references/>
!! result

Templating[1]

- ↑ {{simple template}}

!! end

!! test
<ref> in a <nowiki>
!! input
Templating<nowiki><ref>{{simple template}}</ref></nowiki>

<references/>
!! result

Templating<ref>{{simple template}}</ref>

!! end

!! test
<ref> in a 
!! input
Templating

<references/>
!! result

Templating

!! end

!! test
 in a <ref> (bug 5384)
!! input
Templating<ref>Text</ref>

<references/>
!! result

Templating[1]

- ↑ Text

!! end

!! test
<references> after <gallery> (bug 6164)
!! input
<ref>one</ref>

<gallery>Image:Foobar.jpg</gallery>

<references/>
!! result

[1]

- 

- ↑ one

!! end

!! test
{{REVISIONID}} on page with <ref> (bug 6299)
!! input
{{REVISIONID}}<ref>elite</ref>
!! result
1337[1]
- ↑ elite

!! end

!! test
{{REVISIONID}} on page without <ref> (bug 6299 sanity check)
!! input
{{REVISIONID}}
!! result

1337

!! end

!! test
Ref with content followed by blank ref
!! input
<ref name="blank">content</ref>

<ref name="blank"/>

<references/>
!! result

[1]

[1]

- ↑ 1.0 1.1 content

!! end

!! test
Blank ref followed by ref with content
!! input
<ref name="blank"/>

<ref name="blank">content</ref>

<references/>
!! result

[1]

[1]

- ↑ 1.0 1.1 content

!! end

!! test
Regression: non-blank ref "0" followed by ref with content
!! input
<ref name="blank">0</ref>

<ref name="blank">content</ref>

<references/>
!! result

[1]

[1]

- ↑ 1.0 1.1 0 Cite error: Invalid <ref> tag; name "blank" defined multiple times with different content

!! end

!! test
Regression sanity check: non-blank ref "1" followed by ref with content
!! input
<ref name="blank">1</ref>

<ref name="blank">content</ref>

<references/>
!! result

[1]

[1]

- ↑ 1.0 1.1 1 Cite error: Invalid <ref> tag; name "blank" defined multiple times with different content

!! end

!! test
Ref names containing a number
!! input
<ref name="test123test">One</ref>
<ref name="123test">Two</ref>
<ref name="test123">Three</ref>

<references />
!! result

[1]
[2]
[3]

- ↑ One

- ↑ Two

- ↑ Three

!! end

!! test
Erroneous refs
!! input
<ref name="0">Zero</ref>

<ref>Also zero, but differently! (Normal ref)</ref>

<ref />

<ref name="foo" name="bar" />

<ref name="blankwithnoreference" />

<references name="quasit" />

<references />
!! result

Cite error: Invalid <ref> tag;
name cannot be a simple integer. Use a descriptive title

[1]

Cite error: The opening <ref> tag is malformed or has a bad name

[2]

[3]

Cite error: Invalid <references> tag;
parameter "group" is allowed only.
Use <references />, or <references group="..." />

- ↑ Also zero, but differently! (Normal ref)

- ↑ Cite error: Invalid <ref> tag;
no text was provided for refs named bar
- ↑ Cite error: Invalid <ref> tag;
no text was provided for refs named blankwithnoreference

!! end

!! test
Simple <ref>, with <references/> in group
!! input
Wikipedia rocks!<ref>Proceeds of Rockology, vol. XXI</ref>
Wikipedia rocks!<ref group=note>Proceeds of Rockology, vol. XXI</ref>

<references/>
<references group=note/>
!! result

Wikipedia rocks![1]
Wikipedia rocks![note 1]

- ↑ Proceeds of Rockology, vol. XXI

- ↑ Proceeds of Rockology, vol. XXI

!! end

!! test
Simple <ref>, with <references/> in group, with groupname in Chinese
!! input
AAA<ref group="参">ref a</ref>BBB<ref group="注">note b</ref>CCC<ref group="参">ref c</ref>

;refs
<references group="参" />
;notes
<references group="注" />
!! result

AAA[参 1]BBB[注 1]CCC[参 2]

refs

- ↑ ref a

- ↑ ref c

notes

- ↑ note b

!! end

!! test
<ref> defined in <references>
!! input
<ref name="foo"/>

<references>
<ref name="foo">BAR</ref>
</references>
!! result

[1]

- ↑ BAR

!! end

!! test
<ref> defined in <references> called with #tag
!! input
<ref name="foo"/>

{{#tag:references|
<ref name="foo">BAR</ref>
}}
!! result

[1]

- ↑ BAR

!! end

!! test
<ref> defined in <references> error conditions
!! input
<ref name="foo" group="2"/>

<references group="2">
<ref name="foo"/>
<ref name="unused">BAR</ref>
<ref name="foo" group="1">bad group</ref>
<ref>BAR BAR</ref>
</references>
!! result

[2 1]

- ↑ Cite error: Invalid <ref> tag;
no text was provided for refs named foo

Cite error: <ref> tag with name "unused" defined in <references> is not used in prior text.
Cite error: <ref> tag in <references> has conflicting group attribute "1".
Cite error: <ref> tag defined in <references> has no name attribute.

!! end

!! article
MediaWiki:cite_link_label_group-klingon
!! text
wa' cha' wej loS vagh jav Soch chorgh Hut wa'maH
!! endarticle

!! test
<ref> with custom group link with number names in Klingon
!! input
Wikipedia rocks!<ref group="klingon">Proceeds of Rockology, vol. XXI</ref>

<references group="klingon"/>
!! result

Wikipedia rocks![wa']

- ↑ Proceeds of Rockology, vol. XXI

!! end

!! test
Bug 31374 regression check: nested strip items
!! input
{{#tag:ref|note<ref>reference</ref>|group=Note}}
<references group=Note />
<references />
!! result

[Note 1]

- ↑ note[1]

- ↑ reference

!! end

!! test
Bug 13073 regression check: wrapped <references>
!! input
<ref>
foo
</ref>

<references />
!! result

[1]

- ↑ 
foo

!! end

!! test
<ref> with no name and no content.
!! input
Bla.<ref></ref>
!! result

Bla.Cite error: Invalid <ref> tag;
refs with no name must have content

!! end

!! test
<ref> with an empty-string name parameter and no content.
!! input
Bla.<ref name=""></ref>
!! result

Bla.Cite error: Invalid <ref> tag;
refs with no name must have content

!! end

!! test
<ref> with a non-empty name parameter and no content.
!! input
Bla.<ref name="void"></ref>
!! result
Bla.[1]
- ↑ Cite error: Invalid <ref> tag;
no text was provided for refs named void

!! end

!! test
<ref>s with the follow parameter
!! input
Page one.<ref name="beginning">First page footnote text.</ref>

Page two.<ref follow="beginning">Second page footnote text.</ref>

== References ==
<references />
!! result

Page one.[1]

Page two.

References[edit]

- ↑ First page footnote text. Second page footnote text.

!! end

!! test
<ref> with both name and follow parameters - invalid
!! input
Page one.<ref name="the-name" follow="the-name">This ref is invalid.</ref>
<references />
!! result

Page one.Cite error: Invalid <ref> tag;
invalid names, e.g. too many

!! end

!! test
Multiple definition (outside <references/>)
!! input
<ref name=a>abc</ref>
<ref name=a>def</ref>
<references />
!! result

[1]
[1]

- ↑ 1.0 1.1 abc Cite error: Invalid <ref> tag; name "a" defined multiple times with different content

!! end

!! test
Multiple definition (inside <references/>)
!! input
<ref name=a />
<references>
<ref name=a>abc</ref>
<ref name=a>def</ref>
</references>
!! result

[1]

- ↑ abc Cite error: Invalid <ref> tag; name "a" defined multiple times with different content

!! end

!! test
Multiple definition (mixed outside/inside)
!! input
<ref name=a>abc</ref>
<references>
<ref name=a>def</ref>
</references>
!! result

[1]

- ↑ abc Cite error: Invalid <ref> tag; name "a" defined multiple times with different content

!! end

!! test
Multiple definition (inside {{#tag:references}})
!! input
<ref name=a />
{{#tag:references|
<ref name=a>abc</ref>
<ref name=a>def</ref>
}}
!! result

[1]

- ↑ abc Cite error: Invalid <ref> tag; name "a" defined multiple times with different content

!! end
