11.08., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit 257b0ada authored by di68kap's avatar di68kap

- Fehler in DHParser/testing.py korrigiert

parent c4a9089a
...@@ -342,7 +342,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve ...@@ -342,7 +342,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
parser[parser_name].apply(find_lookahead) parser[parser_name].apply(find_lookahead)
return lookahead_found return lookahead_found
def lookahead_artifact(st): def lookahead_artifact(syntax_tree: Node):
""" """
Returns True, if the error merely occurred, because the parser Returns True, if the error merely occurred, because the parser
stopped in front of a sequence that was captured by a lookahead stopped in front of a sequence that was captured by a lookahead
...@@ -350,7 +350,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve ...@@ -350,7 +350,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
This is required for testing of parsers that put a lookahead This is required for testing of parsers that put a lookahead
operator at the end. See test_testing.TestLookahead. operator at the end. See test_testing.TestLookahead.
""" """
raw_errors = st.errors_sorted raw_errors = syntax_tree.errors_sorted
is_artifact = ((len(raw_errors) == 2 # case 1: superfluous data for lookahead is_artifact = ((len(raw_errors) == 2 # case 1: superfluous data for lookahead
and raw_errors[-1].code == Error.PARSER_LOOKAHEAD_MATCH_ONLY and raw_errors[-1].code == Error.PARSER_LOOKAHEAD_MATCH_ONLY
and raw_errors[-2].code == Error.PARSER_STOPPED_BEFORE_END) and raw_errors[-2].code == Error.PARSER_STOPPED_BEFORE_END)
...@@ -360,9 +360,9 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve ...@@ -360,9 +360,9 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
if is_artifact: if is_artifact:
# don't remove zombie node with error message at the end # don't remove zombie node with error message at the end
# but change it's tag_name to indicate that it is an artifact! # but change it's tag_name to indicate that it is an artifact!
for parent in st.select_if(lambda node: any(child.tag_name == ZOMBIE_TAG for parent in syntax_tree.select_if(lambda node: any(child.tag_name == ZOMBIE_TAG
for child in node.children), for child in node.children),
include_root=True, reverse=True): include_root=True, reverse=True):
zombie = parent[ZOMBIE_TAG] zombie = parent[ZOMBIE_TAG]
zombie.tag_name = '__TESTING_ARTIFACT__' zombie.tag_name = '__TESTING_ARTIFACT__'
zombie.result = 'Artifact can be ignored. Be aware, though, that also the' \ zombie.result = 'Artifact can be ignored. Be aware, though, that also the' \
...@@ -472,7 +472,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve ...@@ -472,7 +472,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve
cst = RootNode(node).new_error(node, str(upe)) cst = RootNode(node).new_error(node, str(upe))
errata.append('Unknown parser "{}" in fail test "{}"!'.format(parser_name, test_name)) errata.append('Unknown parser "{}" in fail test "{}"!'.format(parser_name, test_name))
tests.setdefault('__err__', {})[test_name] = errata[-1] tests.setdefault('__err__', {})[test_name] = errata[-1]
if not is_error(cst.error_flag) and not lookahead_artifact(cst): if not (is_error(cst.error_flag) and not lookahead_artifact(cst)):
errata.append('Fail test "%s" for parser "%s" yields match instead of ' errata.append('Fail test "%s" for parser "%s" yields match instead of '
'expected failure!' % (test_name, parser_name)) 'expected failure!' % (test_name, parser_name))
tests.setdefault('__err__', {})[test_name] = errata[-1] tests.setdefault('__err__', {})[test_name] = errata[-1]
......
...@@ -257,10 +257,11 @@ class TestLookahead: ...@@ -257,10 +257,11 @@ class TestLookahead:
"match": { "match": {
1: """Mountains: big: 1: """Mountains: big:
K2""", # case 1: matches only with lookahead (but should not fail in a test) K2""", # case 1: matches only with lookahead (but should not fail in a test)
2: """Rivers:""" # case 2: lookahaead failure occurs at end of file and is mandatory. (should not fail as a test) 2: """Rivers:""", # case 2: lookahaead failure occurs at end of file and is mandatory. (should not fail as a test)
3: """Mountains: big:""" # same here
}, },
"fail": { "fail": {
6: """Mountains: big:""" 6: """Mountains: big: """
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment