Browse Source

Update changelog, rerun hooks, add an assert

main
Ben Kurtovic 11 months ago
parent
commit
e0150e359e
6 changed files with 17 additions and 9 deletions
  1. +1
    -1
      CHANGELOG
  2. +3
    -1
      docs/changelog.rst
  3. +1
    -1
      scripts/memtest.py
  4. +5
    -3
      src/mwparserfromhell/nodes/template.py
  5. +1
    -1
      src/mwparserfromhell/parser/ctokenizer/avl_tree.c
  6. +6
    -2
      tests/test_template.py

+ 1
- 1
CHANGELOG View File

@@ -1,6 +1,6 @@
v0.7 (unreleased):

- ...
- Added 'after' parameter to Template.add(). (#281, #315)

v0.6.6 (released January 4, 2024):



+ 3
- 1
docs/changelog.rst View File

@@ -7,7 +7,9 @@ v0.7
Unreleased
(`changes <https://github.com/earwig/mwparserfromhell/compare/v0.6.6...main>`__):

- ...
- Added 'after' parameter to Template.add().
(`#281 <https://github.com/earwig/mwparserfromhell/issues/281>`_,
`#315 <https://github.com/earwig/mwparserfromhell/pull/315>`_)

v0.6.6
------


+ 1
- 1
scripts/memtest.py View File

@@ -114,7 +114,7 @@ class MemoryTest:
def run(self):
"""Run the memory test suite."""
width = 1
for (name, _) in self._tests:
for name, _ in self._tests:
if len(name) > width:
width = len(name)



+ 5
- 3
src/mwparserfromhell/nodes/template.py View File

@@ -237,8 +237,9 @@ class Template(Node):
def __getitem__(self, name):
return self.get(name)

def add(self, name, value, showkey=None, before=None, after=None,
preserve_spacing=True):
def add(
self, name, value, showkey=None, before=None, after=None, preserve_spacing=True
):
"""Add a parameter to the template with a given *name* and *value*.

*name* and *value* can be anything parsable by
@@ -317,13 +318,14 @@ class Template(Node):

param = Parameter(name, value, showkey)
if before:
assert after is None, "Cannot set a value for both 'before' and 'after'"
if not isinstance(before, Parameter):
before = self.get(before)
self.params.insert(self.params.index(before), param)
elif after:
if not isinstance(after, Parameter):
after = self.get(after)
self.params.insert(self.params.index(after)+1, param)
self.params.insert(self.params.index(after) + 1, param)
else:
self.params.append(param)
return param


+ 1
- 1
src/mwparserfromhell/parser/ctokenizer/avl_tree.c View File

@@ -19,7 +19,7 @@
*/

#define false 0
#define true 1
#define true 1

typedef int bool;



+ 6
- 2
tests/test_template.py View File

@@ -334,8 +334,12 @@ def test_add():
node40.add("3", "d")
node41.add("3", "d")
node42.add("b", "hello")
node43 = Template(wraptext("a"), [pgens("b", "c"), pgens("d", "e"), pgens("f", "g")])
node44 = Template(wraptext("a"), [pgens("b", "c"), pgens("d", "e"), pgens("f", "g")])
node43 = Template(
wraptext("a"), [pgens("b", "c"), pgens("d", "e"), pgens("f", "g")]
)
node44 = Template(
wraptext("a"), [pgens("b", "c"), pgens("d", "e"), pgens("f", "g")]
)
node43.add("new_param", "value", after="d")
node44.add("new_param", "value", after="f")



Loading…
Cancel
Save