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.
 
 
 
 

432 line
21 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2012-2014 Ben Kurtovic <ben.kurtovic@gmail.com>
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. from __future__ import unicode_literals
  23. import unittest2
  24. from mwparserfromhell.compat import str
  25. from mwparserfromhell.nodes import HTMLEntity, Template, Text
  26. from mwparserfromhell.nodes.extras import Parameter
  27. from ._test_tree_equality import TreeEqualityTestCase, wrap, wraptext
  28. pgens = lambda k, v: Parameter(wraptext(k), wraptext(v), showkey=True)
  29. pgenh = lambda k, v: Parameter(wraptext(k), wraptext(v), showkey=False)
  30. class TestTemplate(TreeEqualityTestCase):
  31. """Test cases for the Template node."""
  32. def test_unicode(self):
  33. """test Template.__unicode__()"""
  34. node = Template(wraptext("foobar"))
  35. self.assertEqual("{{foobar}}", str(node))
  36. node2 = Template(wraptext("foo"),
  37. [pgenh("1", "bar"), pgens("abc", "def")])
  38. self.assertEqual("{{foo|bar|abc=def}}", str(node2))
  39. def test_children(self):
  40. """test Template.__children__()"""
  41. node2p1 = Parameter(wraptext("1"), wraptext("bar"), showkey=False)
  42. node2p2 = Parameter(wraptext("abc"), wrap([Text("def"), Text("ghi")]),
  43. showkey=True)
  44. node1 = Template(wraptext("foobar"))
  45. node2 = Template(wraptext("foo"), [node2p1, node2p2])
  46. gen1 = node1.__children__()
  47. gen2 = node2.__children__()
  48. self.assertEqual(node1.name, next(gen1))
  49. self.assertEqual(node2.name, next(gen2))
  50. self.assertEqual(node2.params[0].value, next(gen2))
  51. self.assertEqual(node2.params[1].name, next(gen2))
  52. self.assertEqual(node2.params[1].value, next(gen2))
  53. self.assertRaises(StopIteration, next, gen1)
  54. self.assertRaises(StopIteration, next, gen2)
  55. def test_strip(self):
  56. """test Template.__strip__()"""
  57. node1 = Template(wraptext("foobar"))
  58. node2 = Template(wraptext("foo"),
  59. [pgenh("1", "bar"), pgens("abc", "def")])
  60. for a in (True, False):
  61. for b in (True, False):
  62. self.assertEqual(None, node1.__strip__(a, b))
  63. self.assertEqual(None, node2.__strip__(a, b))
  64. def test_showtree(self):
  65. """test Template.__showtree__()"""
  66. output = []
  67. getter, marker = object(), object()
  68. get = lambda code: output.append((getter, code))
  69. mark = lambda: output.append(marker)
  70. node1 = Template(wraptext("foobar"))
  71. node2 = Template(wraptext("foo"),
  72. [pgenh("1", "bar"), pgens("abc", "def")])
  73. node1.__showtree__(output.append, get, mark)
  74. node2.__showtree__(output.append, get, mark)
  75. valid = [
  76. "{{", (getter, node1.name), "}}", "{{", (getter, node2.name),
  77. " | ", marker, (getter, node2.params[0].name), " = ", marker,
  78. (getter, node2.params[0].value), " | ", marker,
  79. (getter, node2.params[1].name), " = ", marker,
  80. (getter, node2.params[1].value), "}}"]
  81. self.assertEqual(valid, output)
  82. def test_name(self):
  83. """test getter/setter for the name attribute"""
  84. name = wraptext("foobar")
  85. node1 = Template(name)
  86. node2 = Template(name, [pgenh("1", "bar")])
  87. self.assertIs(name, node1.name)
  88. self.assertIs(name, node2.name)
  89. node1.name = "asdf"
  90. node2.name = "téstïng"
  91. self.assertWikicodeEqual(wraptext("asdf"), node1.name)
  92. self.assertWikicodeEqual(wraptext("téstïng"), node2.name)
  93. def test_params(self):
  94. """test getter for the params attribute"""
  95. node1 = Template(wraptext("foobar"))
  96. plist = [pgenh("1", "bar"), pgens("abc", "def")]
  97. node2 = Template(wraptext("foo"), plist)
  98. self.assertEqual([], node1.params)
  99. self.assertIs(plist, node2.params)
  100. def test_has(self):
  101. """test Template.has()"""
  102. node1 = Template(wraptext("foobar"))
  103. node2 = Template(wraptext("foo"),
  104. [pgenh("1", "bar"), pgens("\nabc ", "def")])
  105. node3 = Template(wraptext("foo"),
  106. [pgenh("1", "a"), pgens("b", "c"), pgens("1", "d")])
  107. node4 = Template(wraptext("foo"), [pgenh("1", "a"), pgens("b", " ")])
  108. self.assertFalse(node1.has("foobar", False))
  109. self.assertTrue(node2.has(1, False))
  110. self.assertTrue(node2.has("abc", False))
  111. self.assertFalse(node2.has("def", False))
  112. self.assertTrue(node3.has("1", False))
  113. self.assertTrue(node3.has(" b ", False))
  114. self.assertTrue(node4.has("b", False))
  115. self.assertTrue(node3.has("b", True))
  116. self.assertFalse(node4.has("b", True))
  117. def test_get(self):
  118. """test Template.get()"""
  119. node1 = Template(wraptext("foobar"))
  120. node2p1 = pgenh("1", "bar")
  121. node2p2 = pgens("abc", "def")
  122. node2 = Template(wraptext("foo"), [node2p1, node2p2])
  123. node3p1 = pgens("b", "c")
  124. node3p2 = pgens("1", "d")
  125. node3 = Template(wraptext("foo"), [pgenh("1", "a"), node3p1, node3p2])
  126. node4p1 = pgens(" b", " ")
  127. node4 = Template(wraptext("foo"), [pgenh("1", "a"), node4p1])
  128. self.assertRaises(ValueError, node1.get, "foobar")
  129. self.assertIs(node2p1, node2.get(1))
  130. self.assertIs(node2p2, node2.get("abc"))
  131. self.assertRaises(ValueError, node2.get, "def")
  132. self.assertIs(node3p1, node3.get("b"))
  133. self.assertIs(node3p2, node3.get("1"))
  134. self.assertIs(node4p1, node4.get("b "))
  135. def test_add(self):
  136. """test Template.add()"""
  137. node1 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  138. node2 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  139. node3 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  140. node4 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  141. node5 = Template(wraptext("a"), [pgens("b", "c"),
  142. pgens(" d ", "e")])
  143. node6 = Template(wraptext("a"), [pgens("b", "c"), pgens("b", "d"),
  144. pgens("b", "e")])
  145. node7 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  146. node8p = pgenh("1", "d")
  147. node8 = Template(wraptext("a"), [pgens("b", "c"), node8p])
  148. node9 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  149. node10 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "e")])
  150. node11 = Template(wraptext("a"), [pgens("b", "c")])
  151. node12 = Template(wraptext("a"), [pgens("b", "c")])
  152. node13 = Template(wraptext("a"), [
  153. pgens("\nb ", " c"), pgens("\nd ", " e"), pgens("\nf ", " g")])
  154. node14 = Template(wraptext("a\n"), [
  155. pgens("b ", "c\n"), pgens("d ", " e"), pgens("f ", "g\n"),
  156. pgens("h ", " i\n")])
  157. node15 = Template(wraptext("a"), [
  158. pgens("b ", " c\n"), pgens("\nd ", " e"), pgens("\nf ", "g ")])
  159. node16 = Template(wraptext("a"), [
  160. pgens("\nb ", " c"), pgens("\nd ", " e"), pgens("\nf ", " g")])
  161. node17 = Template(wraptext("a"), [
  162. pgens("\nb ", " c"), pgens("\nd ", " e"), pgens("\nf ", " g")])
  163. node18 = Template(wraptext("a\n"), [
  164. pgens("b ", "c\n"), pgens("d ", " e"), pgens("f ", "g\n"),
  165. pgens("h ", " i\n")])
  166. node19 = Template(wraptext("a"), [
  167. pgens("b ", " c\n"), pgens("\nd ", " e"), pgens("\nf ", "g ")])
  168. node20 = Template(wraptext("a"), [
  169. pgens("\nb ", " c"), pgens("\nd ", " e"), pgens("\nf ", " g")])
  170. node21 = Template(wraptext("a"), [pgenh("1", "b")])
  171. node22 = Template(wraptext("a"), [pgenh("1", "b")])
  172. node23 = Template(wraptext("a"), [pgenh("1", "b")])
  173. node24 = Template(wraptext("a"), [pgenh("1", "b"), pgenh("2", "c"),
  174. pgenh("3", "d"), pgenh("4", "e")])
  175. node25 = Template(wraptext("a"), [pgenh("1", "b"), pgenh("2", "c"),
  176. pgens("4", "d"), pgens("5", "e")])
  177. node26 = Template(wraptext("a"), [pgenh("1", "b"), pgenh("2", "c"),
  178. pgens("4", "d"), pgens("5", "e")])
  179. node27 = Template(wraptext("a"), [pgenh("1", "b")])
  180. node28 = Template(wraptext("a"), [pgenh("1", "b")])
  181. node29 = Template(wraptext("a"), [pgens("b", "c")])
  182. node30 = Template(wraptext("a"), [pgenh("1", "b")])
  183. node31 = Template(wraptext("a"), [pgenh("1", "b")])
  184. node32 = Template(wraptext("a"), [pgens("1", "b")])
  185. node33 = Template(wraptext("a"), [
  186. pgens("\nb ", " c"), pgens("\nd ", " e"), pgens("\nf ", " g")])
  187. node34 = Template(wraptext("a\n"), [
  188. pgens("b ", "c\n"), pgens("d ", " e"), pgens("f ", "g\n"),
  189. pgens("h ", " i\n")])
  190. node35 = Template(wraptext("a"), [
  191. pgens("b ", " c\n"), pgens("\nd ", " e"), pgens("\nf ", "g ")])
  192. node36 = Template(wraptext("a"), [
  193. pgens("\nb ", " c "), pgens("\nd ", " e "), pgens("\nf ", " g ")])
  194. node37 = Template(wraptext("a"), [pgens("b", "c"), pgens("d", "e"),
  195. pgens("b", "f"), pgens("b", "h"),
  196. pgens("i", "j")])
  197. node37 = Template(wraptext("a"), [pgens("b", "c"), pgens("d", "e"),
  198. pgens("b", "f"), pgens("b", "h"),
  199. pgens("i", "j")])
  200. node38 = Template(wraptext("a"), [pgens("1", "b"), pgens("x", "y"),
  201. pgens("1", "c"), pgens("2", "d")])
  202. node39 = Template(wraptext("a"), [pgens("1", "b"), pgens("x", "y"),
  203. pgenh("1", "c"), pgenh("2", "d")])
  204. node40 = Template(wraptext("a"), [pgens("b", "c"), pgens("d", "e"),
  205. pgens("f", "g")])
  206. node41 = Template(wraptext("a"), [pgenh("1", "")])
  207. node1.add("e", "f", showkey=True)
  208. node2.add(2, "g", showkey=False)
  209. node3.add("e", "foo|bar", showkey=True)
  210. node4.add("e", "f", showkey=True, before="b")
  211. node5.add("f", "g", showkey=True, before=" d ")
  212. node6.add("f", "g", showkey=True, before="b")
  213. self.assertRaises(ValueError, node7.add, "e", "f", showkey=True,
  214. before="q")
  215. node8.add("e", "f", showkey=True, before=node8p)
  216. node9.add("e", "f", showkey=True, before=pgenh("1", "d"))
  217. self.assertRaises(ValueError, node10.add, "e", "f", showkey=True,
  218. before=pgenh("1", "d"))
  219. node11.add("d", "foo=bar", showkey=True)
  220. node12.add("1", "foo=bar", showkey=False)
  221. node13.add("h", "i", showkey=True)
  222. node14.add("j", "k", showkey=True)
  223. node15.add("h", "i", showkey=True)
  224. node16.add("h", "i", showkey=True, preserve_spacing=False)
  225. node17.add("h", "i", showkey=False)
  226. node18.add("j", "k", showkey=False)
  227. node19.add("h", "i", showkey=False)
  228. node20.add("h", "i", showkey=False, preserve_spacing=False)
  229. node21.add("2", "c")
  230. node22.add("3", "c")
  231. node23.add("c", "d")
  232. node24.add("5", "f")
  233. node25.add("3", "f")
  234. node26.add("6", "f")
  235. node27.add("c", "foo=bar")
  236. node28.add("2", "foo=bar")
  237. node29.add("b", "d")
  238. node30.add("1", "foo=bar")
  239. node31.add("1", "foo=bar", showkey=True)
  240. node32.add("1", "foo=bar", showkey=False)
  241. node33.add("d", "foo")
  242. node34.add("f", "foo")
  243. node35.add("f", "foo")
  244. node36.add("d", "foo", preserve_spacing=False)
  245. node37.add("b", "k")
  246. node38.add("1", "e")
  247. node39.add("1", "e")
  248. node40.add("d", "h", before="b")
  249. node41.add(1, "b")
  250. self.assertEqual("{{a|b=c|d|e=f}}", node1)
  251. self.assertEqual("{{a|b=c|d|g}}", node2)
  252. self.assertEqual("{{a|b=c|d|e=foo&#124;bar}}", node3)
  253. self.assertIsInstance(node3.params[2].value.get(1), HTMLEntity)
  254. self.assertEqual("{{a|e=f|b=c|d}}", node4)
  255. self.assertEqual("{{a|b=c|f=g| d =e}}", node5)
  256. self.assertEqual("{{a|b=c|b=d|f=g|b=e}}", node6)
  257. self.assertEqual("{{a|b=c|d}}", node7)
  258. self.assertEqual("{{a|b=c|e=f|d}}", node8)
  259. self.assertEqual("{{a|b=c|e=f|d}}", node9)
  260. self.assertEqual("{{a|b=c|e}}", node10)
  261. self.assertEqual("{{a|b=c|d=foo=bar}}", node11)
  262. self.assertEqual("{{a|b=c|foo&#61;bar}}", node12)
  263. self.assertIsInstance(node12.params[1].value.get(1), HTMLEntity)
  264. self.assertEqual("{{a|\nb = c|\nd = e|\nf = g|\nh = i}}", node13)
  265. self.assertEqual("{{a\n|b =c\n|d = e|f =g\n|h = i\n|j =k\n}}", node14)
  266. self.assertEqual("{{a|b = c\n|\nd = e|\nf =g |h =i}}", node15)
  267. self.assertEqual("{{a|\nb = c|\nd = e|\nf = g|h=i}}", node16)
  268. self.assertEqual("{{a|\nb = c|\nd = e|\nf = g| i}}", node17)
  269. self.assertEqual("{{a\n|b =c\n|d = e|f =g\n|h = i\n|k\n}}", node18)
  270. self.assertEqual("{{a|b = c\n|\nd = e|\nf =g |i}}", node19)
  271. self.assertEqual("{{a|\nb = c|\nd = e|\nf = g|i}}", node20)
  272. self.assertEqual("{{a|b|c}}", node21)
  273. self.assertEqual("{{a|b|3=c}}", node22)
  274. self.assertEqual("{{a|b|c=d}}", node23)
  275. self.assertEqual("{{a|b|c|d|e|f}}", node24)
  276. self.assertEqual("{{a|b|c|4=d|5=e|f}}", node25)
  277. self.assertEqual("{{a|b|c|4=d|5=e|6=f}}", node26)
  278. self.assertEqual("{{a|b|c=foo=bar}}", node27)
  279. self.assertEqual("{{a|b|foo&#61;bar}}", node28)
  280. self.assertIsInstance(node28.params[1].value.get(1), HTMLEntity)
  281. self.assertEqual("{{a|b=d}}", node29)
  282. self.assertEqual("{{a|foo&#61;bar}}", node30)
  283. self.assertIsInstance(node30.params[0].value.get(1), HTMLEntity)
  284. self.assertEqual("{{a|1=foo=bar}}", node31)
  285. self.assertEqual("{{a|foo&#61;bar}}", node32)
  286. self.assertIsInstance(node32.params[0].value.get(1), HTMLEntity)
  287. self.assertEqual("{{a|\nb = c|\nd = foo|\nf = g}}", node33)
  288. self.assertEqual("{{a\n|b =c\n|d = e|f =foo\n|h = i\n}}", node34)
  289. self.assertEqual("{{a|b = c\n|\nd = e|\nf =foo }}", node35)
  290. self.assertEqual("{{a|\nb = c |\nd =foo|\nf = g }}", node36)
  291. self.assertEqual("{{a|b=k|d=e|i=j}}", node37)
  292. self.assertEqual("{{a|1=e|x=y|2=d}}", node38)
  293. self.assertEqual("{{a|x=y|e|d}}", node39)
  294. self.assertEqual("{{a|b=c|d=h|f=g}}", node40)
  295. self.assertEqual("{{a|b}}", node41)
  296. def test_remove(self):
  297. """test Template.remove()"""
  298. node1 = Template(wraptext("foobar"))
  299. node2 = Template(wraptext("foo"),
  300. [pgenh("1", "bar"), pgens("abc", "def")])
  301. node3 = Template(wraptext("foo"),
  302. [pgenh("1", "bar"), pgens("abc", "def")])
  303. node4 = Template(wraptext("foo"),
  304. [pgenh("1", "bar"), pgenh("2", "baz")])
  305. node5 = Template(wraptext("foo"), [
  306. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  307. node6 = Template(wraptext("foo"), [
  308. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  309. node7 = Template(wraptext("foo"), [
  310. pgens("1 ", "a"), pgens(" 1", "b"), pgens("2", "c")])
  311. node8 = Template(wraptext("foo"), [
  312. pgens("1 ", "a"), pgens(" 1", "b"), pgens("2", "c")])
  313. node9 = Template(wraptext("foo"), [
  314. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  315. node10 = Template(wraptext("foo"), [
  316. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  317. node11 = Template(wraptext("foo"), [
  318. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  319. node12 = Template(wraptext("foo"), [
  320. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  321. node13 = Template(wraptext("foo"), [
  322. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  323. node14 = Template(wraptext("foo"), [
  324. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  325. node15 = Template(wraptext("foo"), [
  326. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  327. node16 = Template(wraptext("foo"), [
  328. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  329. node17 = Template(wraptext("foo"), [
  330. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  331. node18 = Template(wraptext("foo"), [
  332. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  333. node19 = Template(wraptext("foo"), [
  334. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  335. node20 = Template(wraptext("foo"), [
  336. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  337. node21 = Template(wraptext("foo"), [
  338. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  339. pgens("a", "b")])
  340. node22 = Template(wraptext("foo"), [
  341. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  342. pgens("a", "b")])
  343. node23 = Template(wraptext("foo"), [
  344. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  345. pgens("a", "b")])
  346. node24 = Template(wraptext("foo"), [
  347. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  348. pgens("a", "b")])
  349. node25 = Template(wraptext("foo"), [
  350. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  351. pgens("a", "b")])
  352. node26 = Template(wraptext("foo"), [
  353. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  354. pgens("a", "b")])
  355. node2.remove("1")
  356. node2.remove("abc")
  357. node3.remove(1, keep_field=True)
  358. node3.remove("abc", keep_field=True)
  359. node4.remove("1", keep_field=False)
  360. node5.remove("a", keep_field=False)
  361. node6.remove("a", keep_field=True)
  362. node7.remove(1, keep_field=True)
  363. node8.remove(1, keep_field=False)
  364. node9.remove(1, keep_field=True)
  365. node10.remove(1, keep_field=False)
  366. node11.remove(node11.params[0], keep_field=False)
  367. node12.remove(node12.params[0], keep_field=True)
  368. node13.remove(node13.params[1], keep_field=False)
  369. node14.remove(node14.params[1], keep_field=True)
  370. node15.remove(node15.params[2], keep_field=False)
  371. node16.remove(node16.params[2], keep_field=True)
  372. node17.remove(node17.params[0], keep_field=False)
  373. node18.remove(node18.params[0], keep_field=True)
  374. node19.remove(node19.params[1], keep_field=False)
  375. node20.remove(node20.params[1], keep_field=True)
  376. node21.remove("a", keep_field=False)
  377. node22.remove("a", keep_field=True)
  378. node23.remove(node23.params[0], keep_field=False)
  379. node24.remove(node24.params[0], keep_field=True)
  380. node25.remove(node25.params[3], keep_field=False)
  381. node26.remove(node26.params[3], keep_field=True)
  382. self.assertRaises(ValueError, node1.remove, 1)
  383. self.assertRaises(ValueError, node1.remove, "a")
  384. self.assertRaises(ValueError, node2.remove, "1")
  385. self.assertEqual("{{foo}}", node2)
  386. self.assertEqual("{{foo||abc=}}", node3)
  387. self.assertEqual("{{foo||baz}}", node4)
  388. self.assertEqual("{{foo|b=c}}", node5)
  389. self.assertEqual("{{foo| a=|b=c}}", node6)
  390. self.assertEqual("{{foo|1 =|2=c}}", node7)
  391. self.assertEqual("{{foo|2=c}}", node8)
  392. self.assertEqual("{{foo||c}}", node9)
  393. self.assertEqual("{{foo||c}}", node10)
  394. self.assertEqual("{{foo|b=c|a =d}}", node11)
  395. self.assertEqual("{{foo| a=|b=c|a =d}}", node12)
  396. self.assertEqual("{{foo| a=b|a =d}}", node13)
  397. self.assertEqual("{{foo| a=b|b=|a =d}}", node14)
  398. self.assertEqual("{{foo| a=b|b=c}}", node15)
  399. self.assertEqual("{{foo| a=b|b=c|a =}}", node16)
  400. self.assertEqual("{{foo|b|c}}", node17)
  401. self.assertEqual("{{foo|1 =|b|c}}", node18)
  402. self.assertEqual("{{foo|1 =a||c}}", node19)
  403. self.assertEqual("{{foo|1 =a||c}}", node20)
  404. self.assertEqual("{{foo|c=d|e=f}}", node21)
  405. self.assertEqual("{{foo|a=|c=d|e=f}}", node22)
  406. self.assertEqual("{{foo|c=d|e=f|a=b|a=b}}", node23)
  407. self.assertEqual("{{foo|a=|c=d|e=f|a=b|a=b}}", node24)
  408. self.assertEqual("{{foo|a=b|c=d|e=f|a=b}}", node25)
  409. self.assertEqual("{{foo|a=b|c=d|e=f|a=|a=b}}", node26)
  410. if __name__ == "__main__":
  411. unittest2.main(verbosity=2)