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.
 
 
 
 

444 regels
22 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2012-2016 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. try:
  24. import unittest2 as unittest
  25. except ImportError:
  26. import unittest
  27. from mwparserfromhell.compat import str
  28. from mwparserfromhell.nodes import HTMLEntity, Template, Text
  29. from mwparserfromhell.nodes.extras import Parameter
  30. from ._test_tree_equality import TreeEqualityTestCase, wrap, wraptext
  31. pgens = lambda k, v: Parameter(wraptext(k), wraptext(v), showkey=True)
  32. pgenh = lambda k, v: Parameter(wraptext(k), wraptext(v), showkey=False)
  33. class TestTemplate(TreeEqualityTestCase):
  34. """Test cases for the Template node."""
  35. def test_unicode(self):
  36. """test Template.__unicode__()"""
  37. node = Template(wraptext("foobar"))
  38. self.assertEqual("{{foobar}}", str(node))
  39. node2 = Template(wraptext("foo"),
  40. [pgenh("1", "bar"), pgens("abc", "def")])
  41. self.assertEqual("{{foo|bar|abc=def}}", str(node2))
  42. def test_children(self):
  43. """test Template.__children__()"""
  44. node2p1 = Parameter(wraptext("1"), wraptext("bar"), showkey=False)
  45. node2p2 = Parameter(wraptext("abc"), wrap([Text("def"), Text("ghi")]),
  46. showkey=True)
  47. node1 = Template(wraptext("foobar"))
  48. node2 = Template(wraptext("foo"), [node2p1, node2p2])
  49. gen1 = node1.__children__()
  50. gen2 = node2.__children__()
  51. self.assertEqual(node1.name, next(gen1))
  52. self.assertEqual(node2.name, next(gen2))
  53. self.assertEqual(node2.params[0].value, next(gen2))
  54. self.assertEqual(node2.params[1].name, next(gen2))
  55. self.assertEqual(node2.params[1].value, next(gen2))
  56. self.assertRaises(StopIteration, next, gen1)
  57. self.assertRaises(StopIteration, next, gen2)
  58. def test_strip(self):
  59. """test Template.__strip__()"""
  60. node1 = Template(wraptext("foobar"))
  61. node2 = Template(wraptext("foo"), [
  62. pgenh("1", "bar"), pgens("foo", ""), pgens("abc", "def")])
  63. node3 = Template(wraptext("foo"), [
  64. pgenh("1", "foo"),
  65. Parameter(wraptext("2"), wrap([Template(wraptext("hello"))]),
  66. showkey=False),
  67. pgenh("3", "bar")])
  68. self.assertEqual(None, node1.__strip__(keep_template_params=False))
  69. self.assertEqual(None, node2.__strip__(keep_template_params=False))
  70. self.assertEqual("", node1.__strip__(keep_template_params=True))
  71. self.assertEqual("bar def", node2.__strip__(keep_template_params=True))
  72. self.assertEqual("foo bar", node3.__strip__(keep_template_params=True))
  73. def test_showtree(self):
  74. """test Template.__showtree__()"""
  75. output = []
  76. getter, marker = object(), object()
  77. get = lambda code: output.append((getter, code))
  78. mark = lambda: output.append(marker)
  79. node1 = Template(wraptext("foobar"))
  80. node2 = Template(wraptext("foo"),
  81. [pgenh("1", "bar"), pgens("abc", "def")])
  82. node1.__showtree__(output.append, get, mark)
  83. node2.__showtree__(output.append, get, mark)
  84. valid = [
  85. "{{", (getter, node1.name), "}}", "{{", (getter, node2.name),
  86. " | ", marker, (getter, node2.params[0].name), " = ", marker,
  87. (getter, node2.params[0].value), " | ", marker,
  88. (getter, node2.params[1].name), " = ", marker,
  89. (getter, node2.params[1].value), "}}"]
  90. self.assertEqual(valid, output)
  91. def test_name(self):
  92. """test getter/setter for the name attribute"""
  93. name = wraptext("foobar")
  94. node1 = Template(name)
  95. node2 = Template(name, [pgenh("1", "bar")])
  96. self.assertIs(name, node1.name)
  97. self.assertIs(name, node2.name)
  98. node1.name = "asdf"
  99. node2.name = "téstïng"
  100. self.assertWikicodeEqual(wraptext("asdf"), node1.name)
  101. self.assertWikicodeEqual(wraptext("téstïng"), node2.name)
  102. def test_params(self):
  103. """test getter for the params attribute"""
  104. node1 = Template(wraptext("foobar"))
  105. plist = [pgenh("1", "bar"), pgens("abc", "def")]
  106. node2 = Template(wraptext("foo"), plist)
  107. self.assertEqual([], node1.params)
  108. self.assertIs(plist, node2.params)
  109. def test_has(self):
  110. """test Template.has()"""
  111. node1 = Template(wraptext("foobar"))
  112. node2 = Template(wraptext("foo"),
  113. [pgenh("1", "bar"), pgens("\nabc ", "def")])
  114. node3 = Template(wraptext("foo"),
  115. [pgenh("1", "a"), pgens("b", "c"), pgens("1", "d")])
  116. node4 = Template(wraptext("foo"), [pgenh("1", "a"), pgens("b", " ")])
  117. self.assertFalse(node1.has("foobar", False))
  118. self.assertTrue(node2.has(1, False))
  119. self.assertTrue(node2.has("abc", False))
  120. self.assertFalse(node2.has("def", False))
  121. self.assertTrue(node3.has("1", False))
  122. self.assertTrue(node3.has(" b ", False))
  123. self.assertTrue(node4.has("b", False))
  124. self.assertTrue(node3.has("b", True))
  125. self.assertFalse(node4.has("b", True))
  126. self.assertFalse(node1.has_param("foobar", False))
  127. self.assertTrue(node2.has_param(1, False))
  128. def test_get(self):
  129. """test Template.get()"""
  130. node1 = Template(wraptext("foobar"))
  131. node2p1 = pgenh("1", "bar")
  132. node2p2 = pgens("abc", "def")
  133. node2 = Template(wraptext("foo"), [node2p1, node2p2])
  134. node3p1 = pgens("b", "c")
  135. node3p2 = pgens("1", "d")
  136. node3 = Template(wraptext("foo"), [pgenh("1", "a"), node3p1, node3p2])
  137. node4p1 = pgens(" b", " ")
  138. node4 = Template(wraptext("foo"), [pgenh("1", "a"), node4p1])
  139. self.assertRaises(ValueError, node1.get, "foobar")
  140. self.assertIs(node2p1, node2.get(1))
  141. self.assertIs(node2p2, node2.get("abc"))
  142. self.assertRaises(ValueError, node2.get, "def")
  143. self.assertIs(node3p1, node3.get("b"))
  144. self.assertIs(node3p2, node3.get("1"))
  145. self.assertIs(node4p1, node4.get("b "))
  146. def test_add(self):
  147. """test Template.add()"""
  148. node1 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  149. node2 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  150. node3 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  151. node4 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  152. node5 = Template(wraptext("a"), [pgens("b", "c"),
  153. pgens(" d ", "e")])
  154. node6 = Template(wraptext("a"), [pgens("b", "c"), pgens("b", "d"),
  155. pgens("b", "e")])
  156. node7 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  157. node8p = pgenh("1", "d")
  158. node8 = Template(wraptext("a"), [pgens("b", "c"), node8p])
  159. node9 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "d")])
  160. node10 = Template(wraptext("a"), [pgens("b", "c"), pgenh("1", "e")])
  161. node11 = Template(wraptext("a"), [pgens("b", "c")])
  162. node12 = Template(wraptext("a"), [pgens("b", "c")])
  163. node13 = Template(wraptext("a"), [
  164. pgens("\nb ", " c"), pgens("\nd ", " e"), pgens("\nf ", " g")])
  165. node14 = Template(wraptext("a\n"), [
  166. pgens("b ", "c\n"), pgens("d ", " e"), pgens("f ", "g\n"),
  167. pgens("h ", " i\n")])
  168. node15 = Template(wraptext("a"), [
  169. pgens("b ", " c\n"), pgens("\nd ", " e"), pgens("\nf ", "g ")])
  170. node16 = Template(wraptext("a"), [
  171. pgens("\nb ", " c"), pgens("\nd ", " e"), pgens("\nf ", " g")])
  172. node17 = Template(wraptext("a"), [pgenh("1", "b")])
  173. node18 = Template(wraptext("a"), [pgenh("1", "b")])
  174. node19 = Template(wraptext("a"), [pgenh("1", "b")])
  175. node20 = Template(wraptext("a"), [pgenh("1", "b"), pgenh("2", "c"),
  176. pgenh("3", "d"), pgenh("4", "e")])
  177. node21 = Template(wraptext("a"), [pgenh("1", "b"), pgenh("2", "c"),
  178. pgens("4", "d"), pgens("5", "e")])
  179. node22 = Template(wraptext("a"), [pgenh("1", "b"), pgenh("2", "c"),
  180. pgens("4", "d"), pgens("5", "e")])
  181. node23 = Template(wraptext("a"), [pgenh("1", "b")])
  182. node24 = Template(wraptext("a"), [pgenh("1", "b")])
  183. node25 = Template(wraptext("a"), [pgens("b", "c")])
  184. node26 = Template(wraptext("a"), [pgenh("1", "b")])
  185. node27 = Template(wraptext("a"), [pgenh("1", "b")])
  186. node28 = Template(wraptext("a"), [pgens("1", "b")])
  187. node29 = Template(wraptext("a"), [
  188. pgens("\nb ", " c"), pgens("\nd ", " e"), pgens("\nf ", " g")])
  189. node30 = Template(wraptext("a\n"), [
  190. pgens("b ", "c\n"), pgens("d ", " e"), pgens("f ", "g\n"),
  191. pgens("h ", " i\n")])
  192. node31 = Template(wraptext("a"), [
  193. pgens("b ", " c\n"), pgens("\nd ", " e"), pgens("\nf ", "g ")])
  194. node32 = Template(wraptext("a"), [
  195. pgens("\nb ", " c "), pgens("\nd ", " e "), pgens("\nf ", " g ")])
  196. node33 = Template(wraptext("a"), [pgens("b", "c"), pgens("d", "e"),
  197. pgens("b", "f"), pgens("b", "h"),
  198. pgens("i", "j")])
  199. node34 = Template(wraptext("a"), [pgens("1", "b"), pgens("x", "y"),
  200. pgens("1", "c"), pgens("2", "d")])
  201. node35 = Template(wraptext("a"), [pgens("1", "b"), pgens("x", "y"),
  202. pgenh("1", "c"), pgenh("2", "d")])
  203. node36 = Template(wraptext("a"), [pgens("b", "c"), pgens("d", "e"),
  204. pgens("f", "g")])
  205. node37 = Template(wraptext("a"), [pgenh("1", "")])
  206. node38 = Template(wraptext("abc"))
  207. node39 = Template(wraptext("a"), [pgenh("1", " b ")])
  208. node40 = Template(wraptext("a"), [pgenh("1", " b"), pgenh("2", " c")])
  209. node41 = Template(wraptext("a"), [pgens("1", " b"), pgens("2", " c")])
  210. node42 = Template(wraptext("a"), [pgens("b", " \n")])
  211. node1.add("e", "f", showkey=True)
  212. node2.add(2, "g", showkey=False)
  213. node3.add("e", "foo|bar", showkey=True)
  214. node4.add("e", "f", showkey=True, before="b")
  215. node5.add("f", "g", showkey=True, before=" d ")
  216. node6.add("f", "g", showkey=True, before="b")
  217. self.assertRaises(ValueError, node7.add, "e", "f", showkey=True,
  218. before="q")
  219. node8.add("e", "f", showkey=True, before=node8p)
  220. node9.add("e", "f", showkey=True, before=pgenh("1", "d"))
  221. self.assertRaises(ValueError, node10.add, "e", "f", showkey=True,
  222. before=pgenh("1", "d"))
  223. node11.add("d", "foo=bar", showkey=True)
  224. node12.add("1", "foo=bar", showkey=False)
  225. node13.add("h", "i", showkey=True)
  226. node14.add("j", "k", showkey=True)
  227. node15.add("h", "i", showkey=True)
  228. node16.add("h", "i", showkey=True, preserve_spacing=False)
  229. node17.add("2", "c")
  230. node18.add("3", "c")
  231. node19.add("c", "d")
  232. node20.add("5", "f")
  233. node21.add("3", "f")
  234. node22.add("6", "f")
  235. node23.add("c", "foo=bar")
  236. node24.add("2", "foo=bar")
  237. node25.add("b", "d")
  238. node26.add("1", "foo=bar")
  239. node27.add("1", "foo=bar", showkey=True)
  240. node28.add("1", "foo=bar", showkey=False)
  241. node29.add("d", "foo")
  242. node30.add("f", "foo")
  243. node31.add("f", "foo")
  244. node32.add("d", "foo", preserve_spacing=False)
  245. node33.add("b", "k")
  246. node34.add("1", "e")
  247. node35.add("1", "e")
  248. node36.add("d", "h", before="b")
  249. node37.add(1, "b")
  250. node38.add("1", "foo")
  251. self.assertRaises(ValueError, node38.add, "z", "bar", showkey=False)
  252. node39.add("1", "c")
  253. node40.add("3", "d")
  254. node41.add("3", "d")
  255. node42.add("b", "hello")
  256. self.assertEqual("{{a|b=c|d|e=f}}", node1)
  257. self.assertEqual("{{a|b=c|d|g}}", node2)
  258. self.assertEqual("{{a|b=c|d|e=foo&#124;bar}}", node3)
  259. self.assertIsInstance(node3.params[2].value.get(1), HTMLEntity)
  260. self.assertEqual("{{a|e=f|b=c|d}}", node4)
  261. self.assertEqual("{{a|b=c|f=g| d =e}}", node5)
  262. self.assertEqual("{{a|b=c|b=d|f=g|b=e}}", node6)
  263. self.assertEqual("{{a|b=c|d}}", node7)
  264. self.assertEqual("{{a|b=c|e=f|d}}", node8)
  265. self.assertEqual("{{a|b=c|e=f|d}}", node9)
  266. self.assertEqual("{{a|b=c|e}}", node10)
  267. self.assertEqual("{{a|b=c|d=foo=bar}}", node11)
  268. self.assertEqual("{{a|b=c|foo&#61;bar}}", node12)
  269. self.assertIsInstance(node12.params[1].value.get(1), HTMLEntity)
  270. self.assertEqual("{{a|\nb = c|\nd = e|\nf = g|\nh = i}}", node13)
  271. self.assertEqual("{{a\n|b =c\n|d = e|f =g\n|h = i\n|j =k\n}}", node14)
  272. self.assertEqual("{{a|b = c\n|\nd = e|\nf =g |h =i}}", node15)
  273. self.assertEqual("{{a|\nb = c|\nd = e|\nf = g|h=i}}", node16)
  274. self.assertEqual("{{a|b|c}}", node17)
  275. self.assertEqual("{{a|b|3=c}}", node18)
  276. self.assertEqual("{{a|b|c=d}}", node19)
  277. self.assertEqual("{{a|b|c|d|e|f}}", node20)
  278. self.assertEqual("{{a|b|c|4=d|5=e|f}}", node21)
  279. self.assertEqual("{{a|b|c|4=d|5=e|6=f}}", node22)
  280. self.assertEqual("{{a|b|c=foo=bar}}", node23)
  281. self.assertEqual("{{a|b|foo&#61;bar}}", node24)
  282. self.assertIsInstance(node24.params[1].value.get(1), HTMLEntity)
  283. self.assertEqual("{{a|b=d}}", node25)
  284. self.assertEqual("{{a|foo&#61;bar}}", node26)
  285. self.assertIsInstance(node26.params[0].value.get(1), HTMLEntity)
  286. self.assertEqual("{{a|1=foo=bar}}", node27)
  287. self.assertEqual("{{a|foo&#61;bar}}", node28)
  288. self.assertIsInstance(node28.params[0].value.get(1), HTMLEntity)
  289. self.assertEqual("{{a|\nb = c|\nd = foo|\nf = g}}", node29)
  290. self.assertEqual("{{a\n|b =c\n|d = e|f =foo\n|h = i\n}}", node30)
  291. self.assertEqual("{{a|b = c\n|\nd = e|\nf =foo }}", node31)
  292. self.assertEqual("{{a|\nb = c |\nd =foo|\nf = g }}", node32)
  293. self.assertEqual("{{a|b=k|d=e|i=j}}", node33)
  294. self.assertEqual("{{a|1=e|x=y|2=d}}", node34)
  295. self.assertEqual("{{a|x=y|e|d}}", node35)
  296. self.assertEqual("{{a|b=c|d=h|f=g}}", node36)
  297. self.assertEqual("{{a|b}}", node37)
  298. self.assertEqual("{{abc|foo}}", node38)
  299. self.assertEqual("{{a|c}}", node39)
  300. self.assertEqual("{{a| b| c|d}}", node40)
  301. self.assertEqual("{{a|1= b|2= c|3= d}}", node41)
  302. self.assertEqual("{{a|b=hello \n}}", node42)
  303. def test_remove(self):
  304. """test Template.remove()"""
  305. node1 = Template(wraptext("foobar"))
  306. node2 = Template(wraptext("foo"),
  307. [pgenh("1", "bar"), pgens("abc", "def")])
  308. node3 = Template(wraptext("foo"),
  309. [pgenh("1", "bar"), pgens("abc", "def")])
  310. node4 = Template(wraptext("foo"),
  311. [pgenh("1", "bar"), pgenh("2", "baz")])
  312. node5 = Template(wraptext("foo"), [
  313. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  314. node6 = Template(wraptext("foo"), [
  315. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  316. node7 = Template(wraptext("foo"), [
  317. pgens("1 ", "a"), pgens(" 1", "b"), pgens("2", "c")])
  318. node8 = Template(wraptext("foo"), [
  319. pgens("1 ", "a"), pgens(" 1", "b"), pgens("2", "c")])
  320. node9 = Template(wraptext("foo"), [
  321. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  322. node10 = Template(wraptext("foo"), [
  323. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  324. node11 = Template(wraptext("foo"), [
  325. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  326. node12 = Template(wraptext("foo"), [
  327. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  328. node13 = Template(wraptext("foo"), [
  329. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  330. node14 = Template(wraptext("foo"), [
  331. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  332. node15 = Template(wraptext("foo"), [
  333. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  334. node16 = Template(wraptext("foo"), [
  335. pgens(" a", "b"), pgens("b", "c"), pgens("a ", "d")])
  336. node17 = Template(wraptext("foo"), [
  337. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  338. node18 = Template(wraptext("foo"), [
  339. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  340. node19 = Template(wraptext("foo"), [
  341. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  342. node20 = Template(wraptext("foo"), [
  343. pgens("1 ", "a"), pgenh("1", "b"), pgenh("2", "c")])
  344. node21 = Template(wraptext("foo"), [
  345. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  346. pgens("a", "b")])
  347. node22 = Template(wraptext("foo"), [
  348. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  349. pgens("a", "b")])
  350. node23 = Template(wraptext("foo"), [
  351. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  352. pgens("a", "b")])
  353. node24 = Template(wraptext("foo"), [
  354. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  355. pgens("a", "b")])
  356. node25 = Template(wraptext("foo"), [
  357. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  358. pgens("a", "b")])
  359. node26 = Template(wraptext("foo"), [
  360. pgens("a", "b"), pgens("c", "d"), pgens("e", "f"), pgens("a", "b"),
  361. pgens("a", "b")])
  362. node27 = Template(wraptext("foo"), [pgenh("1", "bar")])
  363. node28 = Template(wraptext("foo"), [pgenh("1", "bar")])
  364. node2.remove("1")
  365. node2.remove("abc")
  366. node3.remove(1, keep_field=True)
  367. node3.remove("abc", keep_field=True)
  368. node4.remove("1", keep_field=False)
  369. node5.remove("a", keep_field=False)
  370. node6.remove("a", keep_field=True)
  371. node7.remove(1, keep_field=True)
  372. node8.remove(1, keep_field=False)
  373. node9.remove(1, keep_field=True)
  374. node10.remove(1, keep_field=False)
  375. node11.remove(node11.params[0], keep_field=False)
  376. node12.remove(node12.params[0], keep_field=True)
  377. node13.remove(node13.params[1], keep_field=False)
  378. node14.remove(node14.params[1], keep_field=True)
  379. node15.remove(node15.params[2], keep_field=False)
  380. node16.remove(node16.params[2], keep_field=True)
  381. node17.remove(node17.params[0], keep_field=False)
  382. node18.remove(node18.params[0], keep_field=True)
  383. node19.remove(node19.params[1], keep_field=False)
  384. node20.remove(node20.params[1], keep_field=True)
  385. node21.remove("a", keep_field=False)
  386. node22.remove("a", keep_field=True)
  387. node23.remove(node23.params[0], keep_field=False)
  388. node24.remove(node24.params[0], keep_field=True)
  389. node25.remove(node25.params[3], keep_field=False)
  390. node26.remove(node26.params[3], keep_field=True)
  391. self.assertRaises(ValueError, node1.remove, 1)
  392. self.assertRaises(ValueError, node1.remove, "a")
  393. self.assertRaises(ValueError, node2.remove, "1")
  394. self.assertEqual("{{foo}}", node2)
  395. self.assertEqual("{{foo||abc=}}", node3)
  396. self.assertEqual("{{foo|2=baz}}", node4)
  397. self.assertEqual("{{foo|b=c}}", node5)
  398. self.assertEqual("{{foo| a=|b=c}}", node6)
  399. self.assertEqual("{{foo|1 =|2=c}}", node7)
  400. self.assertEqual("{{foo|2=c}}", node8)
  401. self.assertEqual("{{foo||c}}", node9)
  402. self.assertEqual("{{foo|2=c}}", node10)
  403. self.assertEqual("{{foo|b=c|a =d}}", node11)
  404. self.assertEqual("{{foo| a=|b=c|a =d}}", node12)
  405. self.assertEqual("{{foo| a=b|a =d}}", node13)
  406. self.assertEqual("{{foo| a=b|b=|a =d}}", node14)
  407. self.assertEqual("{{foo| a=b|b=c}}", node15)
  408. self.assertEqual("{{foo| a=b|b=c|a =}}", node16)
  409. self.assertEqual("{{foo|b|c}}", node17)
  410. self.assertEqual("{{foo|1 =|b|c}}", node18)
  411. self.assertEqual("{{foo|1 =a|2=c}}", node19)
  412. self.assertEqual("{{foo|1 =a||c}}", node20)
  413. self.assertEqual("{{foo|c=d|e=f}}", node21)
  414. self.assertEqual("{{foo|a=|c=d|e=f}}", node22)
  415. self.assertEqual("{{foo|c=d|e=f|a=b|a=b}}", node23)
  416. self.assertEqual("{{foo|a=|c=d|e=f|a=b|a=b}}", node24)
  417. self.assertEqual("{{foo|a=b|c=d|e=f|a=b}}", node25)
  418. self.assertEqual("{{foo|a=b|c=d|e=f|a=|a=b}}", node26)
  419. self.assertRaises(ValueError, node27.remove, node28.get(1))
  420. if __name__ == "__main__":
  421. unittest.main(verbosity=2)