mirror of
https://github.com/AdaCore/langkit.git
synced 2026-02-12 12:28:12 -08:00
Add a testcase for EquationType binding in the Python API
TN: Q221-031
This commit is contained in:
21
testsuite/tests/python-api/equation_type/main.py
Normal file
21
testsuite/tests/python-api/equation_type/main.py
Normal file
@@ -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.')
|
||||
4
testsuite/tests/python-api/equation_type/test.out
Normal file
4
testsuite/tests/python-api/equation_type/test.out
Normal file
@@ -0,0 +1,4 @@
|
||||
main.py: Running...
|
||||
u.root.p_eq(None) = None
|
||||
main.py: Done.
|
||||
Done
|
||||
41
testsuite/tests/python-api/equation_type/test.py
Normal file
41
testsuite/tests/python-api/equation_type/test.py
Normal file
@@ -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')
|
||||
1
testsuite/tests/python-api/equation_type/test.yaml
Normal file
1
testsuite/tests/python-api/equation_type/test.yaml
Normal file
@@ -0,0 +1 @@
|
||||
driver: python
|
||||
Reference in New Issue
Block a user