# MediaWiki Parser test cases # Some taken from http://meta.wikimedia.org/wiki/Parser_testing # All (C) their respective authors and released under the GPL # # The syntax should be fairly self-explanatory. # # Currently supported test options: # (default) generate HTML output # pst apply pre-save transform # msg apply message transform # # Tests can be disabled with the '!!disabled' flag. # # For testing purposes, temporary articles can created: # !!article / NAMESPACE:TITLE / !!text / ARTICLE TEXT / !!endarticle # where '/' denotes a newline. ### ### Basic tests ### !! test Blank input !! input !! result !! end !! test Simple paragraph !! input This is a simple paragraph. !! result

This is a simple paragraph.

!! end !! test Simple list !! input * Item 1 * Item 2 !! result !! end !! test Italics and bold !! input * plain * plain''italic''plain * plain''italic''plain''italic''plain * plain'''bold'''plain * plain'''bold'''plain'''bold'''plain * plain''italic''plain'''bold'''plain * plain'''bold'''plain''italic''plain * plain''italic'''bold-italic'''italic''plain * plain'''bold''bold-italic''bold'''plain * plain'''''bold-italic'''italic''plain * plain'''''bold-italic''bold'''plain * plain''italic'''bold-italic'''''plain * plain'''bold''bold-italic'''''plain * plain l'''italic''plain !! result !! end ### ### test cases ### !! test unordered list !! input * This is not an unordered list item. !! result

* This is not an unordered list item.

!! end !! test spacing !! input Lorem ipsum dolor sed abit. sed nullum. :and a colon !! result

Lorem ipsum dolor sed abit. sed nullum. :and a colon

!! end !! test nowiki 3 !! input :There is not nowiki. :There is nowiki. #There is not nowiki. #There is nowiki. *There is not nowiki. *There is nowiki. !! result
There is not nowiki.
There is nowiki.
  1. There is not nowiki.
  2. There is nowiki.
  • There is not nowiki.
  • There is nowiki.
!! end ### ### comment test cases ### !! test comment test 1 !! input asdf !! result
asdf
!! end !! test comment test 2 !! input asdf jkl !! result

asdf jkl

!! end !! test comment test 3 !! input asdf jkl !! result

asdf jkl

!! end !! test comment test 4 !! input asdfjkl !! result

asdfjkl

!! end ### ### External links ### !! test External links: non-bracketed !! input Non-bracketed: http://example.com !! result

Non-bracketed: http://example.com

!! end !! test External links: numbered !! input Numbered: [http://example.com] !! result

Numbered: [1] (http://example.com)

!!end !! test External links: specified text !! input Specified text: [http://example.com link] !! result

Specified text: link (http://example.com)

!!end !! test External links: trail !! input Trail (not sure if this is meant to work): [http://example.com link]s !! result

Trail (not sure if this is meant to work): links (http://example.com)

!! end !! test External links: dollar sign in URL !! input http://example.com/1$2345 !! result

http://example.com/1$2345

!! end !! test External links: dollar sign in URL (named) !! input [http://example.com/1$2345] !! result

[1] (http://example.com/1$2345)

!!end !! test External image !! input External image: http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png !! result

External image: Ncwikicol.png

!! end !! test External image from https !! input External image from https: https://meta.wikimedia.org/upload/f/f1/Ncwikicol.png !! result

External image from https: Ncwikicol.png

!! end !! test Link to non-http image, no img tag !! input Link to non-http image, no img tag: ftp://example.com/test.jpg !! result

Link to non-http image, no img tag: ftp://example.com/test.jpg

!! end !! test External links: terminating separator !! input Terminating separator: http://example.com/thing, !! result

Terminating separator: http://example.com/thing,

!! end !! test External links: intervening separator !! input Intervening separator: http://example.com/1,2,3 !! result

Intervening separator: http://example.com/1,2,3

!! end !! test External links: old bug with URL in query !! input Old bug with URL in query: [http://example.com/thing?url=http://example.com link] !! result

Old bug with URL in query: link (http://example.com/thing?url=http://example.com)

!! end !! test External links: old URL-in-URL bug, mixed protocols !! input And again with mixed protocols: [ftp://example.com?url=http://example.com link] !! result

And again with mixed protocols: link (ftp://example.com?url=http://example.com)

!!end !! test External links: URL in text !! input URL in text: [http://example.com http://example.com] !! result

URL in text: http://example.com

!! end !! test External links: Clickable images !! input ja-style clickable images: [http://example.com http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png] !! result

ja-style clickable images: Ncwikicol.png (http://example.com)

!!end !! test External links: raw ampersand !! input Old & use: http://x&y !! result

Old & use: http://x&y

!! end !! test External links: www.jpeg.org (bug 554) !! input http://www.jpeg.org !!result

http://www.jpeg.org

!! end ### ### Quotes ### !! test Quotes !! input Normal text. '''Bold text.''' Normal text. ''Italic text.'' Normal text. '''''Bold italic text.''''' Normal text. !!result

Normal text. Bold text. Normal text. Italic text.

Normal text. Bold italic text. Normal text.

!! end !! test Unclosed and unmatched quotes !! input '''''Bold italic text '''with bold deactivated''' in between.''''' '''''Bold italic text ''with italic deactivated'' in between.''''' '''Bold text.. ..spanning two paragraphs (should not work).''' '''Bold tag left open ''Italic tag left open Normal text. '''This year''''s election ''should'' beat '''last year''''s. ''Tom'''s car is bigger than ''Susan'''s. !! result

Bold italic text with bold deactivated in between.

Bold italic text with italic deactivated in between.

Bold text..

..spanning two paragraphs (should not work).

Bold tag left open

Italic tag left open

Normal text.

This year's election should beat last year's.

Toms car is bigger than Susans.

!! end ### ### Tables ### ### content taken from http://meta.wikimedia.org/wiki/MediaWiki_User%27s_Guide:_Using_tables ### !! test Simple table !! input {| | 1 || 2 |- | 3 || 4 |} !! result
1 2
3 4
!! end !! test Multiplication table !! input {| border="1" cellpadding="2" |+Multiplication table |- ! × !! 1 !! 2 !! 3 |- ! 1 | 1 || 2 || 3 |- ! 2 | 2 || 4 || 6 |- ! 3 | 3 || 6 || 9 |- ! 4 | 4 || 8 || 12 |- ! 5 | 5 || 10 || 15 |} !! result
Multiplication table
× 1 2 3
1 1 2 3
2 2 4 6
3 3 6 9
4 4 8 12
5 5 10 15
!! end !! test Table rowspan !! input {| align=right border=1 | Cell 1, row 1 |rowspan=2| Cell 2, row 1 (and 2) | Cell 3, row 1 |- | Cell 1, row 2 | Cell 3, row 2 |} !! result
Cell 1, row 1 Cell 2, row 1 (and 2) Cell 3, row 1
Cell 1, row 2 Cell 3, row 2
!! end !! test Nested table !! input {| border=1 | α | {| bgcolor=#ABCDEF border=2 |nested |- |table |} |the original table again |} !! result
α
nested
table
the original table again
!! end ### ### Internal links ### !! article Main Page !! text blah blah !! endarticle !! test Plain link, capitalized !! input [[Main Page]] !! result

Main Page

!! end !! test Plain link, uncapitalized !! input [[main Page]] !! result

main Page

!! end !! test Piped link !! input [[Main Page|The Main Page]] !! result

The Main Page

!! end !! test Broken link !! input [[Zigzagzogzagzig]] !! result

Zigzagzogzagzig

!! end !! test Link with prefix !! input xxx[[main Page]], xxx[[Main Page]], Xxx[[main Page]] XXX[[main Page]], XXX[[Main Page]] !! result

xxxmain Page, xxxMain Page, Xxxmain Page XXXmain Page, XXXMain Page

!! end !! test Link with suffix !! input [[Main Page]]xxx, [[Main Page]]XXX !! result

Main Pagexxx, Main PageXXX

!! end !! test Link with 3 brackets !! input [[[main page]]] !! result

[[[main page]]]

!! end !! test Piped link with 3 brackets !! input [[[main page|the main page]]] !! result

[[[main page|the main page]]]

!! end !! test Link to namespaces !! input [[Talk:Parser testing]], [[Meta:Disclaimers]] !! result

Talk:Parser testing, Meta:Disclaimers

!! end !! test Piped link to namespace !! input [[Meta:Disclaimers|The disclaimers]] !! result

The disclaimers

!! end !! article Category:MediaWiki User's Guide !! text blah !! endarticle !! test Link to category !! input [[:Category:MediaWiki User's Guide]] !! result

Category:MediaWiki User's Guide

!! end !! test Link to image page !! input [[:Image:Ncwikicol.png]] !! result

Image:Ncwikicol.png

!! end !! test Plain link to URL !! input [[http://www.example.org]] !! result

[[1] (http://www.example.org)]

!! end # I'm fairly sure the expected result here is wrong. # We want these to be URL links, not pseudo-pages with URLs for titles.... # However the current output is also pretty screwy. # # ---- # I'm changing it to match the current output--it arguably makes more # sense in the light of the test above. Old expected result was: #

Piped link to URL: an example URL #

# But I think this test is bordering on "garbage in, garbage out" anyway. # -- wtm !! test Piped link to URL !! input Piped link to URL: [[http://www.example.org|an example URL]] !! result

Piped link to URL: [example URL (http://www.example.org|an)]

!! end !! test BUG 2: [[page|http://url/]] should link to page, not http://url/ !! input [[Main Page|http://url/]] !! result

http://url/

!! end ### ### Interwiki links ### !! test Inline interwiki link !! input [[MeatBall:SoftSecurity]] !! result

MeatBall:SoftSecurity

!! end ### ### Images ### !! test [[ ## ## XHTML tidiness ### !! test
to
!! input 1
2
3 !! result

1
2
3

!! end ### ### Block-level elements ### !! test Common list !! input *Common list * item 2 *item 3 !! result
  • Common list
  • item 2
  • item 3
!! end !! test Numbered list !! input #Numbered list #item 2 # item 3 !! result
  1. Numbered list
  2. item 2
  3. item 3
!! end !! test Mixed list !! input *Mixed list *# with numbers ** and bullets *# and numbers *bullets again **bullet level 2 ***bullet level 3 ***#Number on level 4 **bullet level 2 **#Number on level 3 **#Number on level 3 *#number level 2 *Level 1 !! result
  • Mixed list
    1. with numbers
    • and bullets
    1. and numbers
  • bullets again
    • bullet level 2
      • bullet level 3
        1. Number on level 4
    • bullet level 2
      1. Number on level 3
      2. Number on level 3
    1. number level 2
  • Level 1
!! end ### ### Magic variables ### !! test Magic variables !! input {{SITENAME}} !! result

MediaWiki

!! end ### ### Magic links ### !! test Magic links: internal link to RFC !! input [[RFC 123]] !! result

RFC 123

!! end !! test Magic links: ISBN !! input ISBN 0-306-40615-2 !! result

ISBN 0-306-40615-2

!! end ### ### Nonexistant template ### !! test Nonexistant template !! input {{thistemplatedoesnotexist}} !! result

Template:Thistemplatedoesnotexist

!! end ### ### Templates #### !! article Template:test !! text This is a test template !! endarticle !! test Simple template !! input {{test}} !! result

This is a test template

!! end !! test Template with explicit namespace !! input {{Template:test}} !! result

This is a test template

!! end !! article Template:paramtest !! text This is a test template with parameter {{{param}}} !! endarticle !! test Template parameter !! input {{paramtest|param=foo}} !! result

This is a test template with parameter foo

!! end !! test Magic variable as template parameter !! input {{paramtest|param={{SITENAME}}}} !! result

This is a test template with parameter MediaWiki

!! end !! article Template:linktest !! text [[{{{param}}}|link]] !! endarticle !! test Template parameter as link source !! input {{linktest|param=Main Page}} !! result

link

!! end !! article Template:Linktest2 !! text Main Page !! endarticle !! test Template as link source !! input [[{{linktest2}}]] !! result

Main Page

!! end !! article Template:loop1 !! text {{loop2}} !! endarticle !! article Template:loop2 !! text {{loop1}} !! endarticle !! test Template infinite loop !! input {{loop1}} !! result

{{loop2}}

!! end ### ### Pre-save transform tests ### !! test pre-save transform: subst: !! options PST !! input {{subst:test}} !! result This is a test template !! end !! test pre-save transform: normal template !! options PST !! input {{test}} !! result {{test}} !! end !! test pre-save transform: nonexistant template !! options PST !! input {{thistemplatedoesnotexist}} !! result {{thistemplatedoesnotexist}} !! end !! test pre-save transform: subst magic variables !! options PST !! input {{subst:SITENAME}} !! result MediaWiki !! end ### ### Message transform tests ### !! test message transform: magic variables !! options msg !! input {{SITENAME}} !! result MediaWiki !! end !! test message transform: should not transform wiki markup !! options msg !! input ''test'' !! result ''test'' !! end TODO: more templates tables images subpages character entities and much more