Browse Source

Solve a couple more coverage issues; tighten.

tags/v0.4
Ben Kurtovic 9 years ago
parent
commit
871d48c688
3 changed files with 21 additions and 2 deletions
  1. +1
    -0
      .coveragerc
  2. +6
    -2
      mwparserfromhell/parser/tokenizer.py
  3. +14
    -0
      tests/tokenizer/templates.mwtest

+ 1
- 0
.coveragerc View File

@@ -6,3 +6,4 @@ partial_branches =
pragma: no branch
if py3k:
if not py3k:
if py26:

+ 6
- 2
mwparserfromhell/parser/tokenizer.py View File

@@ -369,9 +369,11 @@ class Tokenizer(object):
if "(" in this and ")" in punct:
punct = punct[:-1] # ')' is not longer valid punctuation
if this.endswith(punct):
for i in reversed(range(-len(this), 0)):
if i == -len(this) or this[i - 1] not in punct:
for i in range(len(this) - 1, 0, -1):
if this[i - 1] not in punct:
break
else:
i = 0
stripped = this[:i]
if stripped and tail:
self._emit_text(tail)
@@ -762,6 +764,8 @@ class Tokenizer(object):
depth -= 1
if depth == 0:
break
else: # pragma: no cover (untestable/exceptional case)
raise ParserError("_handle_single_tag_end() missed a TagCloseOpen")
padding = stack[index].padding
stack[index] = tokens.TagCloseSelfclose(padding=padding, implicit=True)
return self._pop()


+ 14
- 0
tests/tokenizer/templates.mwtest View File

@@ -376,6 +376,20 @@ output: [Text(text="{{\nfoo\n|\n{{\nb\nar\n|\nb\naz\n=\nb\niz\n}}\n=\nb\nuzz\n}}

---

name: newlines_spaces
label: newlines in the middle of a template name, followed by spaces
input: "{{foo\n }}"
output: [TemplateOpen(), Text(text="foo\n "), TemplateClose()]

---

name: newlines_spaces_param
label: newlines in the middle of a template name, followed by spaces
input: "{{foo\n }}"
output: [TemplateOpen(), Text(text="foo\n "), TemplateClose()]

---

name: invalid_name_left_brace_middle
label: invalid characters in template name: left brace in middle
input: "{{foo{bar}}"


Loading…
Cancel
Save