From b72cf76fa2e4fc65cef1fb602bbb43673d820efe Mon Sep 17 00:00:00 2001 From: Pierre-Marie de Rodat Date: Wed, 1 Mar 2017 19:39:44 +0100 Subject: [PATCH] Add a testcase for EquationType binding in the Python API TN: Q221-031 --- .../tests/python-api/equation_type/main.py | 21 ++++++++++ .../tests/python-api/equation_type/test.out | 4 ++ .../tests/python-api/equation_type/test.py | 41 +++++++++++++++++++ .../tests/python-api/equation_type/test.yaml | 1 + 4 files changed, 67 insertions(+) create mode 100644 testsuite/tests/python-api/equation_type/main.py create mode 100644 testsuite/tests/python-api/equation_type/test.out create mode 100644 testsuite/tests/python-api/equation_type/test.py create mode 100644 testsuite/tests/python-api/equation_type/test.yaml diff --git a/testsuite/tests/python-api/equation_type/main.py b/testsuite/tests/python-api/equation_type/main.py new file mode 100644 index 000000000..f3ec0bcbe --- /dev/null +++ b/testsuite/tests/python-api/equation_type/main.py @@ -0,0 +1,21 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +print('main.py: Running...') + + +import sys + +import libfoolang + + +ctx = libfoolang.AnalysisContext() +u = ctx.get_from_buffer('foo.txt', 'example') +if u.diagnostics: + for d in u.diagnostics: + print(d) + sys.exit(1) + +u.populate_lexical_env() +print('u.root.p_eq(None) = {}'.format(u.root.p_eq(None))) +print('main.py: Done.') diff --git a/testsuite/tests/python-api/equation_type/test.out b/testsuite/tests/python-api/equation_type/test.out new file mode 100644 index 000000000..67732a2e6 --- /dev/null +++ b/testsuite/tests/python-api/equation_type/test.out @@ -0,0 +1,4 @@ +main.py: Running... +u.root.p_eq(None) = None +main.py: Done. +Done diff --git a/testsuite/tests/python-api/equation_type/test.py b/testsuite/tests/python-api/equation_type/test.py new file mode 100644 index 000000000..ef6d26c99 --- /dev/null +++ b/testsuite/tests/python-api/equation_type/test.py @@ -0,0 +1,41 @@ +""" +Test that property checks are properly emitted when null checks should trigger +them. +""" + +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +import os.path + +from langkit.compiled_types import ( + ASTNode, EquationType, Field, Token as TokenType, root_grammar_class +) +from langkit.diagnostics import Diagnostics +from langkit.expressions import langkit_property +from langkit.parsers import Grammar, Tok + +from lexer_example import Token +from utils import build_and_run + + +Diagnostics.set_lang_source_dir(os.path.abspath(__file__)) + + +@root_grammar_class() +class FooNode(ASTNode): + @langkit_property(public=True, return_type=EquationType) + def eq(eq=EquationType): + return eq + + +class Example(FooNode): + tok = Field(type=TokenType) + + +foo_grammar = Grammar('main_rule') +foo_grammar.add_rules( + main_rule=Example(Tok(Token.Example, keep=True)), +) +build_and_run(foo_grammar, 'main.py') +print('Done') diff --git a/testsuite/tests/python-api/equation_type/test.yaml b/testsuite/tests/python-api/equation_type/test.yaml new file mode 100644 index 000000000..30423a038 --- /dev/null +++ b/testsuite/tests/python-api/equation_type/test.yaml @@ -0,0 +1 @@ +driver: python