Sfoglia il codice sorgente

Add some basic tests for templates; adjust error messages again.

tags/v0.2
Ben Kurtovic 11 anni fa
parent
commit
eb1bd6b281
2 ha cambiato i file con 39 aggiunte e 6 eliminazioni
  1. +7
    -6
      tests/_test_tokenizer.py
  2. +32
    -0
      tests/tokenizer/templates.test

+ 7
- 6
tests/_test_tokenizer.py Vedi File

@@ -64,14 +64,15 @@ class TokenizerTestCase(object):
raw = line[len("output:"):].strip()
try:
data["output"] = eval(raw, vars(tokens))
except Exception:
raise _TestParseError()
except _TestParseError:
except Exception as err:
raise _TestParseError(err)
except _TestParseError as err:
if data["name"]:
error = "Could not parse test '{0}' in '{1}'"
print(error.format(data["name"], filename))
error = "Could not parse test '{0}' in '{1}':\n\t{2}"
print(error.format(data["name"], filename, err))
else:
print("Could not parse a test in '{0}'".format(filename))
error = "Could not parse a test in '{0}':\n\t{1}"
print(error.format(filename, err))
continue
if not data["name"]:
error = "A test in '{0}' was ignored because it lacked a name"


+ 32
- 0
tests/tokenizer/templates.test Vedi File

@@ -0,0 +1,32 @@
name: no_params
label: simplest type of template
input: "{{template}}"
output: [TemplateOpen(), Text(text="template"), TemplateClose()]

---

name: one_param_unnamed
label: basic template with one unnamed parameter
input: "{{foo|bar}}"
output: [TemplateOpen(), Text(text="foo"), TemplateParamSeparator(), Text(text="bar"), TemplateClose()]

---

name: one_param_named
label: basic template with one named parameter
input: "{{foo|bar=baz}}"
output: [TemplateOpen(), Text(text="foo"), TemplateParamSeparator(), Text(text="bar"), TemplateParamEquals(), Text(text="baz"), TemplateClose()]

---

name: multiple_unnamed_params
label: basic template with multiple unnamed parameters
input: "{{foo|bar|baz|biz|buzz}}"
output: [TemplateOpen(), Text(text="foo"), TemplateParamSeparator(), Text(text="bar"), TemplateParamSeparator(), Text(text="baz"), TemplateParamSeparator(), Text(text="biz"), TemplateParamSeparator(), Text(text="buzz"), TemplateClose()]

---

name: multiple_named_params
label: basic template with multiple named parameters
input: "{{foo|bar=baz|biz=buzz|buff=baff|usr=bin}}"
output: [TemplateOpen(), Text(text="foo"), TemplateParamSeparator(), Text(text="bar"), TemplateParamEquals(), Text(text="baz"), TemplateParamSeparator(), Text(text="biz"), TemplateParamEquals(), Text(text="buzz"), TemplateParamSeparator(), Text(text="buff"), TemplateParamEquals(), Text(text="baff"), TemplateParamSeparator(), Text(text="usr"), TemplateParamEquals(), Text(text="bin"), TemplateClose()]

Caricamento…
Annulla
Salva