@@ -226,9 +226,9 @@ class Template(Node): | |||||
self.remove(name, keep_field=True) | self.remove(name, keep_field=True) | ||||
existing = self.get(name) | existing = self.get(name) | ||||
if showkey is not None: | if showkey is not None: | ||||
if not showkey: | |||||
self._surface_escape(value, "=") | |||||
existing.showkey = showkey | existing.showkey = showkey | ||||
if not existing.showkey: | |||||
self._surface_escape(value, "=") | |||||
nodes = existing.value.nodes | nodes = existing.value.nodes | ||||
if preserve_spacing: | if preserve_spacing: | ||||
existing.value = parse_anything([nodes[0], value, nodes[1]]) | existing.value = parse_anything([nodes[0], value, nodes[1]]) | ||||
@@ -262,7 +262,12 @@ class Template(Node): | |||||
value = parse_anything([before_v, value, after_v]) | value = parse_anything([before_v, value, after_v]) | ||||
param = Parameter(name, value, showkey) | param = Parameter(name, value, showkey) | ||||
self.params.append(param) | |||||
if before: | |||||
if not isinstance(before, Parameter): | |||||
before = self.get(before) | |||||
self.params.insert(self.params.index(before), param) | |||||
else: | |||||
self.params.append(param) | |||||
return param | return param | ||||
def remove(self, name, keep_field=False): | def remove(self, name, keep_field=False): | ||||
@@ -133,7 +133,27 @@ class TestTemplate(TreeEqualityTestCase): | |||||
self.assertIs(node3p2, node3.get("1")) | self.assertIs(node3p2, node3.get("1")) | ||||
self.assertIs(node4p1, node4.get("b ")) | self.assertIs(node4p1, node4.get("b ")) | ||||
# add | |||||
def test_add(self): | |||||
"""test Template.add()""" | |||||
# add new param with showkey to end | |||||
# add new param without showkey to end | |||||
# add new param to end with an escapable | | |||||
# add new param with showkey to end with an escapable = | |||||
# add new param without showkey to end with an escapable = | |||||
# add new param with showkey to end preserving spacing (x3) | |||||
# add new param without showkey to end not preserving spacing | |||||
# add new param guessing showkey where key is to be shown | |||||
# add new param guessing showkey where key is to be shown with an escapable = | |||||
# add new param guessing showkey where key is not to be shown | |||||
# add new param guessing showkey where key is not to be shown with an escapable = | |||||
# add existing parameter without modifying showkey | |||||
# add existing parameter without modifying showkey with an escapable = | |||||
# add existing parameter with modifying showkey | |||||
# add existing parameter with modifying showkey with an escapable = | |||||
# add existing parameter preserving spacing (x3) | |||||
# add existing parameter not preserving spacing | |||||
# add existing parameter when there are multiple params involved | |||||
# add existing parameter when there are multiple params involved; params with dependencies | |||||
def test_remove(self): | def test_remove(self): | ||||
"""test Template.remove()""" | """test Template.remove()""" | ||||