A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

327 lines
11 KiB

  1. name: basic
  2. label: a basic tag with an open and close
  3. input: "<ref></ref>"
  4. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagCloseOpen(padding=""), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  5. ---
  6. name: basic_selfclosing
  7. label: a basic self-closing tag
  8. input: "<ref/>"
  9. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagCloseSelfclose(padding="")]
  10. ---
  11. name: content
  12. label: a tag with some content in the middle
  13. input: "<ref>this is a reference</ref>"
  14. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagCloseOpen(padding=""), Text(text="this is a reference"), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  15. ---
  16. name: padded_open
  17. label: a tag with some padding in the open tag
  18. input: "<ref ></ref>"
  19. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagCloseOpen(padding=" "), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  20. ---
  21. name: padded_close
  22. label: a tag with some padding in the close tag
  23. input: "<ref></ref >"
  24. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagCloseOpen(padding=""), TagOpenClose(), Text(text="ref "), TagCloseClose()]
  25. ---
  26. name: padded_selfclosing
  27. label: a self-closing tag with padding
  28. input: "<ref />"
  29. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagCloseSelfclose(padding=" ")]
  30. ---
  31. name: attribute
  32. label: a tag with a single attribute
  33. input: "<ref name></ref>"
  34. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagCloseOpen(padding=""), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  35. ---
  36. name: attribute_value
  37. label: a tag with a single attribute with a value
  38. input: "<ref name=foo></ref>"
  39. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), Text(text="foo"), TagCloseOpen(padding=""), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  40. ---
  41. name: attribute_quoted
  42. label: a tag with a single quoted attribute
  43. input: "<ref name="foo"></ref>"
  44. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(), Text(text="foo"), TagCloseOpen(padding=""), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  45. ---
  46. name: attribute_hyphen
  47. label: a tag with a single attribute, containing a hyphen
  48. input: "<ref name=foo-bar></ref>"
  49. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), Text(text="foo-bar"), TagCloseOpen(padding=""), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  50. ---
  51. name: attribute_quoted_hyphen
  52. label: a tag with a single quoted attribute, containing a hyphen
  53. input: "<ref name="foo-bar"></ref>"
  54. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(), Text(text="foo-bar"), TagCloseOpen(padding=""), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  55. ---
  56. name: attribute_selfclosing
  57. label: a self-closing tag with a single attribute
  58. input: "<ref name/>"
  59. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagCloseSelfclose(padding="")]
  60. ---
  61. name: attribute_selfclosing_value
  62. label: a self-closing tag with a single attribute with a value
  63. input: "<ref name=foo/>"
  64. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), Text(text="foo"), TagCloseSelfclose(padding="")]
  65. ---
  66. name: attribute_selfclosing_value_quoted
  67. label: a self-closing tag with a single quoted attribute
  68. input: "<ref name="foo"/>"
  69. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), Text(text="name"), TagAttrEquals(), TagAttrQuote(), Text(text="foo"), TagCloseSelfclose(padding="")]
  70. ---
  71. name: invalid_space_begin_open
  72. label: invalid tag: a space at the beginning of the open tag
  73. input: "< ref>test</ref>"
  74. output: [Text(text="< ref>test</ref>")]
  75. ---
  76. name: invalid_space_begin_close
  77. label: invalid tag: a space at the beginning of the close tag
  78. input: "<ref>test</ ref>"
  79. output: [Text(text="<ref>test</ ref>")]
  80. ---
  81. name: valid_space_end
  82. label: valid tag: spaces at the ends of both the open and close tags
  83. input: "<ref >test</ref >"
  84. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagCloseOpen(padding=" "), Text(text="test"), TagOpenClose(), Text(text="ref "), TagCloseClose()]
  85. ---
  86. name: invalid_template_ends
  87. label: invalid tag: a template at the ends of both the open and close tags
  88. input: "<ref {{foo}}>test</ref {{foo}}>"
  89. output: [Text(text="<ref "), TemplateOpen(), Text(text="foo"), TemplateClose(), Text(text=">test</ref "), TemplateOpen(), Text(text="foo"), TemplateClose(), Text(text=">")]
  90. ---
  91. name: invalid_template_ends_nospace
  92. label: invalid tag: a template at the ends of both the open and close tags, without spacing
  93. input: "<ref {{foo}}>test</ref{{foo}}>"
  94. output: [Text(text="<ref "), TemplateOpen(), Text(text="foo"), TemplateClose(), Text(text=">test</ref"), TemplateOpen(), Text(text="foo"), TemplateClose(), Text(text=">")]
  95. ---
  96. name: valid_template_end_open
  97. label: valid tag: a template at the end of the open tag
  98. input: "<ref {{foo}}>test</ref>"
  99. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), TemplateOpen(), Text(text="foo"), TemplateClose(), TagCloseOpen(padding=""), Text(text="test"), TagOpenClose(), Text(text="ref"), TagCloseClose()]
  100. ---
  101. name: valid_template_end_open_space_end_close
  102. label: valid tag: a template at the end of the open tag; whitespace at the end of the close tag
  103. input: "<ref {{foo}}>test</ref\n>"
  104. output: [TagOpenOpen(showtag=True), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), TemplateOpen(), Text(text="foo"), TemplateClose(), TagCloseOpen(padding=""), Text(text="test"), TagOpenClose(), Text(text="ref\n"), TagCloseClose()]
  105. ---
  106. name: invalid_template_end_open_nospace
  107. label: invalid tag: a template at the end of the open tag, without spacing
  108. input: "<ref{{foo}}>test</ref>"
  109. output: [Text(text="<ref"), TemplateOpen(), Text(text="foo"), TemplateClose(), Text(text=">test</ref>")]
  110. ---
  111. name: invalid_template_start_close
  112. label: invalid tag: a template at the beginning of the close tag
  113. input: "<ref>test</{{foo}}ref>"
  114. output: [Text(text="<ref>test</"), TemplateOpen(), Text(text="foo"), TemplateClose(), Text(text="ref>")]
  115. ---
  116. name: invalid_template_start_open
  117. label: invalid tag: a template at the beginning of the open tag
  118. input: "<{{foo}}ref>test</ref>"
  119. output: [Text(text="<"), TemplateOpen(), Text(text="foo"), TemplateClose(), Text(text="ref>test</ref>")]
  120. ---
  121. name: incomplete_lbracket
  122. label: incomplete tags: just a left bracket
  123. input: "<"
  124. output: [Text(text="<")]
  125. ---
  126. name: incomplete_lbracket_junk
  127. label: incomplete tags: just a left bracket, surrounded by stuff
  128. input: "foo<bar"
  129. output: [Text(text="foo<bar")]
  130. ---
  131. name: incomplete_unclosed_open
  132. label: incomplete tags: an unclosed open tag
  133. input: "junk <ref"
  134. output: [Text(text="junk <ref")]
  135. ---
  136. name: incomplete_unclosed_open_space
  137. label: incomplete tags: an unclosed open tag, space
  138. input: "junk <ref "
  139. output: [Text(text="junk <ref ")]
  140. ---
  141. name: incomplete_unclosed_open_unnamed_attr
  142. label: incomplete tags: an unclosed open tag, unnamed attribute
  143. input: "junk <ref name"
  144. output: [Text(text="junk <ref name")]
  145. ---
  146. name: incomplete_unclosed_open_attr_equals
  147. label: incomplete tags: an unclosed open tag, attribute, equal sign
  148. input: "junk <ref name="
  149. output: [Text(text="junk <ref name=")]
  150. ---
  151. name: incomplete_unclosed_open_attr_equals_quoted
  152. label: incomplete tags: an unclosed open tag, attribute, equal sign, quote
  153. input: "junk <ref name=""
  154. output: [Text(text="junk <ref name=\"")]
  155. ---
  156. name: incomplete_unclosed_open_attr
  157. label: incomplete tags: an unclosed open tag, attribute with a key/value
  158. input: "junk <ref name=foo"
  159. output: [Text(text="junk <ref name=foo")]
  160. ---
  161. name: incomplete_unclosed_open_attr_quoted
  162. label: incomplete tags: an unclosed open tag, attribute with a key/value, quoted
  163. input: "junk <ref name="foo""
  164. output: [Text(text="junk <ref name=\"foo\"")]
  165. ---
  166. name: incomplete_open
  167. label: incomplete tags: an open tag
  168. input: "junk <ref>"
  169. output: [Text(text="junk <ref>")]
  170. ---
  171. name: incomplete_open_unnamed_attr
  172. label: incomplete tags: an open tag, unnamed attribute
  173. input: "junk <ref name>"
  174. output: [Text(text="junk <ref name>")]
  175. ---
  176. name: incomplete_open_attr_equals
  177. label: incomplete tags: an open tag, attribute, equal sign
  178. input: "junk <ref name=>"
  179. output: [Text(text="junk <ref name=>")]
  180. ---
  181. name: incomplete_open_attr
  182. label: incomplete tags: an open tag, attribute with a key/value
  183. input: "junk <ref name=foo>"
  184. output: [Text(text="junk <ref name=foo>")]
  185. ---
  186. name: incomplete_open_attr_quoted
  187. label: incomplete tags: an open tag, attribute with a key/value, quoted
  188. input: "junk <ref name="foo">"
  189. output: [Text(text="junk <ref name=\"foo\">")]
  190. ---
  191. name: incomplete_open_text
  192. label: incomplete tags: an open tag, text
  193. input: "junk <ref>foo"
  194. output: [Text(text="junk <ref>foo")]
  195. ---
  196. name: incomplete_open_attr_text
  197. label: incomplete tags: an open tag, attribute with a key/value, text
  198. input: "junk <ref name=foo>bar"
  199. output: [Text(text="junk <ref name=foo>bar")]
  200. ---
  201. name: incomplete_open_text_lbracket
  202. label: incomplete tags: an open tag, text, left open bracket
  203. input: "junk <ref>bar<"
  204. output: [Text(text="junk <ref>bar<")]
  205. ---
  206. name: incomplete_open_text_lbracket_slash
  207. label: incomplete tags: an open tag, text, left bracket, slash
  208. input: "junk <ref>bar</"
  209. output: [Text(text="junk <ref>bar</")]
  210. ---
  211. name: incomplete_open_text_unclosed_close
  212. label: incomplete tags: an open tag, text, unclosed close
  213. input: "junk <ref>bar</ref"
  214. output: [Text(text="junk <ref>bar</ref")]
  215. ---
  216. name: incomplete_open_text_wrong_close
  217. label: incomplete tags: an open tag, text, wrong close
  218. input: "junk <ref>bar</span>"
  219. output: [Text(text="junk <ref>bar</span>")]
  220. ---
  221. name: incomplete_no_tag_name_open
  222. label: incomplete tags: no tag name within brackets; just an open
  223. input: "junk <>"
  224. output: [Text(text="junk <>")]
  225. ---
  226. name: incomplete_no_tag_name_selfclosing
  227. label: incomplete tags: no tag name within brackets; self-closing
  228. input: "junk < />"
  229. output: [Text(text="junk < />")]
  230. ---
  231. name: incomplete_no_tag_name_open_close
  232. label: incomplete tags: no tag name within brackets; open and close
  233. input: "junk <></>"
  234. output: [Text(text="junk <></>")]