mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Improve value parsing
Parse values as different AST nodes rather than just strings. This allows for better validation and will eventually make expressions possible.
This commit is contained in:
parent
5f0eef5f2e
commit
80b5698533
16 changed files with 352 additions and 138 deletions
|
@ -20,38 +20,44 @@
|
|||
|
||||
import difflib # I love Python
|
||||
from pathlib import Path
|
||||
import traceback
|
||||
import unittest
|
||||
|
||||
from gtkblueprinttool import tokenizer, parser
|
||||
from gtkblueprinttool.errors import PrintableError
|
||||
from gtkblueprinttool.errors import PrintableError, MultipleErrors
|
||||
from gtkblueprinttool.tokenizer import Token, TokenType, tokenize
|
||||
|
||||
|
||||
class TestSamples(unittest.TestCase):
|
||||
def assert_sample(self, name):
|
||||
with open((Path(__file__).parent / f"samples/{name}.blp").resolve()) as f:
|
||||
blueprint = f.read()
|
||||
with open((Path(__file__).parent / f"samples/{name}.ui").resolve()) as f:
|
||||
expected = f.read()
|
||||
try:
|
||||
with open((Path(__file__).parent / f"samples/{name}.blp").resolve()) as f:
|
||||
blueprint = f.read()
|
||||
with open((Path(__file__).parent / f"samples/{name}.ui").resolve()) as f:
|
||||
expected = f.read()
|
||||
|
||||
tokens = tokenizer.tokenize(blueprint)
|
||||
ast, errors = parser.parse(tokens)
|
||||
tokens = tokenizer.tokenize(blueprint)
|
||||
ast, errors = parser.parse(tokens)
|
||||
|
||||
if errors:
|
||||
raise errors
|
||||
if len(ast.errors):
|
||||
raise MultipleErrors(ast.errors)
|
||||
if errors:
|
||||
raise errors
|
||||
if len(ast.errors):
|
||||
raise MultipleErrors(ast.errors)
|
||||
|
||||
actual = ast.generate()
|
||||
if actual.strip() != expected.strip():
|
||||
diff = difflib.unified_diff(expected.splitlines(), actual.splitlines())
|
||||
print("\n".join(diff))
|
||||
actual = ast.generate()
|
||||
if actual.strip() != expected.strip():
|
||||
diff = difflib.unified_diff(expected.splitlines(), actual.splitlines())
|
||||
print("\n".join(diff))
|
||||
raise AssertionError()
|
||||
except PrintableError as e:
|
||||
e.pretty_print(name + ".blp", blueprint)
|
||||
raise AssertionError()
|
||||
|
||||
|
||||
def test_samples(self):
|
||||
self.assert_sample("binding")
|
||||
self.assert_sample("child_type")
|
||||
self.assert_sample("flags")
|
||||
self.assert_sample("layout")
|
||||
self.assert_sample("menu")
|
||||
self.assert_sample("property")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue