Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_relative_rule_import_rename(self):
l = _Lark_open('test_relative_rule_import_rename.lark',
rel_to=__file__)
x = l.parse('xaabby')
self.assertEqual(x.children, [
'x',
Tree('ab', ['a', Tree('ab', ['a', 'b']), 'b']),
'y'])
def test_CleaningTransformer_value(str_value, expected_value):
full_sdl = """
type Test {{
fieldName(arg: Int = {}): String
}}
""".format(
str_value
)
expected = Tree(
"document",
[
Tree(
"type_system_definition",
[
Tree(
"type_definition",
[
Tree(
"object_type_definition",
[
Token("TYPE", "type"),
Token("IDENT", "Test"),
Tree(
"fields_definition",
[
),
Tree(
"type",
[
Tree(
"named_type",
[
Token(
"IDENT",
"Int",
)
],
)
],
),
Tree(
"default_value",
[
Tree(
"value",
[
expected_value
],
)
],
),
],
)
],
),
Tree(
"type",
Tree('enum_value_definition', [
Tree('enum_value', [
Tree('name', [
Token('IDENT', 'INACTIVE'),
]),
]),
]),
Tree('enum_value_definition', [
Tree('enum_value', [
Tree('name', [
Token('IDENT', 'SUSPENDED'),
]),
]),
]),
]),
]),
]),
def test_iter_subtrees_topdown(self):
expected = [Tree('a', [Tree('b', 'x'), Tree('c', 'y'), Tree('d', 'z')]),
Tree('b', 'x'), Tree('c', 'y'), Tree('d', 'z')]
nodes = list(self.tree1.iter_subtrees_topdown())
self.assertEqual(nodes, expected)
Tree('enum_type_definition', [
Token('ENUM', 'enum'),
Tree('name', [
Token('IDENT', 'Episode'),
]),
Tree('directives', [
Tree('directive', [
Tree('name', [
Token('IDENT', 'link_db'),
]),
Tree('arguments', [
Tree('argument', [
Tree('name', [
Token('IDENT', 'table'),
]),
Tree('value', [
Tree('string_value', [
Token('STRING', '"movies.slug"'),
]),
]),
]),
]),
]),
]),
Tree('enum_values_definition', [
Tree('enum_value_definition', [
Tree('enum_value', [
Tree('name', [
Token('IDENT', 'A_NEW_HOPE'),
]),
]),
]),
fieldName(arg: Int = {}): String
}}
""".format(
str_value
)
expected = Tree(
"document",
[
Tree(
"type_system_definition",
[
Tree(
"type_definition",
[
Tree(
"object_type_definition",
[
Token("TYPE", "type"),
Token("IDENT", "Test"),
Tree(
"fields_definition",
[
Tree(
"field_definition",
[
Token(
"IDENT", "fieldName"
),
Tree(
"arguments_definition",
[
def test_relative_rule_import_subrule_no_conflict(self):
l = _Lark_open(
'test_relative_rule_import_subrule_no_conflict.lark',
rel_to=__file__)
x = l.parse('xaby')
self.assertEqual(x.children, [Tree('expr', [
'x',
Tree('startab', [
Tree('grammars__ab__expr', ['a', 'b']),
]),
'y'])])
self.assertRaises((ParseError, UnexpectedInput),
l.parse, 'xaxabyby')
Tree('union_member_types', [
Tree('named_type', [
Tree('name', [
Token('IDENT', 'Foo'),
]),
]),
Tree('named_type', [
Tree('name', [
Token('IDENT', 'Bar'),
]),
]),
Tree('named_type', [
Tree('name', [
Token('IDENT', 'Baz'),
]),
]),
]),