mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
tests: Test that docs & completions don't crash
This commit is contained in:
parent
6576e02837
commit
3f37380c25
4 changed files with 21 additions and 5 deletions
|
@ -24,12 +24,21 @@ import traceback
|
|||
import unittest
|
||||
|
||||
from blueprintcompiler import tokenizer, parser, decompiler
|
||||
from blueprintcompiler.completions import complete
|
||||
from blueprintcompiler.errors import PrintableError, MultipleErrors, CompileError
|
||||
from blueprintcompiler.tokenizer import Token, TokenType, tokenize
|
||||
from blueprintcompiler import utils
|
||||
|
||||
|
||||
class TestSamples(unittest.TestCase):
|
||||
def assert_docs_dont_crash(self, text, ast):
|
||||
for i in range(len(text)):
|
||||
ast.get_docs(i)
|
||||
|
||||
def assert_completions_dont_crash(self, text, ast, tokens):
|
||||
for i in range(len(text)):
|
||||
list(complete(ast, tokens, i))
|
||||
|
||||
def assert_sample(self, name):
|
||||
try:
|
||||
with open((Path(__file__).parent / f"samples/{name}.blp").resolve()) as f:
|
||||
|
@ -52,6 +61,9 @@ class TestSamples(unittest.TestCase):
|
|||
diff = difflib.unified_diff(expected.splitlines(), actual.splitlines())
|
||||
print("\n".join(diff))
|
||||
raise AssertionError()
|
||||
|
||||
self.assert_docs_dont_crash(blueprint, ast)
|
||||
self.assert_completions_dont_crash(blueprint, ast, tokens)
|
||||
except PrintableError as e: # pragma: no cover
|
||||
e.pretty_print(name + ".blp", blueprint)
|
||||
raise AssertionError()
|
||||
|
@ -67,6 +79,9 @@ class TestSamples(unittest.TestCase):
|
|||
tokens = tokenizer.tokenize(blueprint)
|
||||
ast, errors, warnings = parser.parse(tokens)
|
||||
|
||||
self.assert_docs_dont_crash(blueprint, ast)
|
||||
self.assert_completions_dont_crash(blueprint, ast, tokens)
|
||||
|
||||
if errors:
|
||||
raise errors
|
||||
if len(ast.errors):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue