**Breaking change**; closes #51.tags/v0.3.3
@@ -1,5 +1,8 @@ | |||||
v0.4 (unreleased): | v0.4 (unreleased): | ||||
- Template.has() is now passed 'ignore_empty=False' by default instead of True. | |||||
This fixes a bug when adding parameters to templates with empty fields, and | |||||
is a breaking change if you rely on the default behavior. | |||||
- The 'matches' argument of Wikicode's filter methods now accepts a function | - The 'matches' argument of Wikicode's filter methods now accepts a function | ||||
(taking one argument, a Node, and returning a bool) in addition to a regex. | (taking one argument, a Node, and returning a bool) in addition to a regex. | ||||
- Wikicode.matches() now accepts a tuple of strings/Wikicode objects instead of | - Wikicode.matches() now accepts a tuple of strings/Wikicode objects instead of | ||||
@@ -7,6 +7,10 @@ v0.4 | |||||
Unreleased | Unreleased | ||||
(`changes <https://github.com/earwig/mwparserfromhell/compare/v0.3.2...develop>`__): | (`changes <https://github.com/earwig/mwparserfromhell/compare/v0.3.2...develop>`__): | ||||
- :py:meth:`.Template.has` is now passed *ignore_empty=False* by default | |||||
instead of *True*. This fixes a bug when adding parameters to templates with | |||||
empty fields, **and is a breaking change if you rely on the default | |||||
behavior.** | |||||
- The *matches* argument of :py:class:`Wikicode's <.Wikicode>` | - The *matches* argument of :py:class:`Wikicode's <.Wikicode>` | ||||
:py:meth:`.filter` methods now accepts a function (taking one argument, a | :py:meth:`.filter` methods now accepts a function (taking one argument, a | ||||
:py:class:`.Node`, and returning a bool) in addition to a regex. | :py:class:`.Node`, and returning a bool) in addition to a regex. | ||||
@@ -174,7 +174,7 @@ class Template(Node): | |||||
def name(self, value): | def name(self, value): | ||||
self._name = parse_anything(value) | self._name = parse_anything(value) | ||||
def has(self, name, ignore_empty=True): | |||||
def has(self, name, ignore_empty=False): | |||||
"""Return ``True`` if any parameter in the template is named *name*. | """Return ``True`` if any parameter in the template is named *name*. | ||||
With *ignore_empty*, ``False`` will be returned even if the template | With *ignore_empty*, ``False`` will be returned even if the template | ||||
@@ -190,7 +190,7 @@ class Template(Node): | |||||
return True | return True | ||||
return False | return False | ||||
has_param = lambda self, name, ignore_empty=True: \ | |||||
has_param = lambda self, name, ignore_empty=False: \ | |||||
self.has(name, ignore_empty) | self.has(name, ignore_empty) | ||||
has_param.__doc__ = "Alias for :py:meth:`has`." | has_param.__doc__ = "Alias for :py:meth:`has`." | ||||
@@ -123,15 +123,15 @@ class TestTemplate(TreeEqualityTestCase): | |||||
node3 = Template(wraptext("foo"), | node3 = Template(wraptext("foo"), | ||||
[pgenh("1", "a"), pgens("b", "c"), pgens("1", "d")]) | [pgenh("1", "a"), pgens("b", "c"), pgens("1", "d")]) | ||||
node4 = Template(wraptext("foo"), [pgenh("1", "a"), pgens("b", " ")]) | node4 = Template(wraptext("foo"), [pgenh("1", "a"), pgens("b", " ")]) | ||||
self.assertFalse(node1.has("foobar")) | |||||
self.assertTrue(node2.has(1)) | |||||
self.assertTrue(node2.has("abc")) | |||||
self.assertFalse(node2.has("def")) | |||||
self.assertTrue(node3.has("1")) | |||||
self.assertTrue(node3.has(" b ")) | |||||
self.assertFalse(node4.has("b")) | |||||
self.assertTrue(node3.has("b", False)) | |||||
self.assertFalse(node1.has("foobar", False)) | |||||
self.assertTrue(node2.has(1, False)) | |||||
self.assertTrue(node2.has("abc", False)) | |||||
self.assertFalse(node2.has("def", False)) | |||||
self.assertTrue(node3.has("1", False)) | |||||
self.assertTrue(node3.has(" b ", False)) | |||||
self.assertTrue(node4.has("b", False)) | self.assertTrue(node4.has("b", False)) | ||||
self.assertTrue(node3.has("b", True)) | |||||
self.assertFalse(node4.has("b", True)) | |||||
def test_get(self): | def test_get(self): | ||||
"""test Template.get()""" | """test Template.get()""" | ||||
@@ -223,6 +223,7 @@ class TestTemplate(TreeEqualityTestCase): | |||||
pgenh("1", "c"), pgenh("2", "d")]) | pgenh("1", "c"), pgenh("2", "d")]) | ||||
node40 = Template(wraptext("a"), [pgens("b", "c"), pgens("d", "e"), | node40 = Template(wraptext("a"), [pgens("b", "c"), pgens("d", "e"), | ||||
pgens("f", "g")]) | pgens("f", "g")]) | ||||
node41 = Template(wraptext("a"), [pgenh("1", "")]) | |||||
node1.add("e", "f", showkey=True) | node1.add("e", "f", showkey=True) | ||||
node2.add(2, "g", showkey=False) | node2.add(2, "g", showkey=False) | ||||
@@ -266,6 +267,7 @@ class TestTemplate(TreeEqualityTestCase): | |||||
node38.add("1", "e") | node38.add("1", "e") | ||||
node39.add("1", "e") | node39.add("1", "e") | ||||
node40.add("d", "h", before="b") | node40.add("d", "h", before="b") | ||||
node41.add(1, "b") | |||||
self.assertEqual("{{a|b=c|d|e=f}}", node1) | self.assertEqual("{{a|b=c|d|e=f}}", node1) | ||||
self.assertEqual("{{a|b=c|d|g}}", node2) | self.assertEqual("{{a|b=c|d|g}}", node2) | ||||
@@ -312,6 +314,7 @@ class TestTemplate(TreeEqualityTestCase): | |||||
self.assertEqual("{{a|1=e|x=y|2=d}}", node38) | self.assertEqual("{{a|1=e|x=y|2=d}}", node38) | ||||
self.assertEqual("{{a|x=y|e|d}}", node39) | self.assertEqual("{{a|x=y|e|d}}", node39) | ||||
self.assertEqual("{{a|b=c|d=h|f=g}}", node40) | self.assertEqual("{{a|b=c|d=h|f=g}}", node40) | ||||
self.assertEqual("{{a|b}}", node41) | |||||
def test_remove(self): | def test_remove(self): | ||||
"""test Template.remove()""" | """test Template.remove()""" | ||||