Loading DHParser/testing.py +6 −6 Original line number Diff line number Diff line Loading @@ -342,7 +342,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve parser[parser_name].apply(find_lookahead) return lookahead_found def lookahead_artifact(st): def lookahead_artifact(syntax_tree: Node): """ Returns True, if the error merely occurred, because the parser stopped in front of a sequence that was captured by a lookahead Loading @@ -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 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 and raw_errors[-1].code == Error.PARSER_LOOKAHEAD_MATCH_ONLY and raw_errors[-2].code == Error.PARSER_STOPPED_BEFORE_END) Loading @@ -360,7 +360,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve if is_artifact: # don't remove zombie node with error message at the end # 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), include_root=True, reverse=True): zombie = parent[ZOMBIE_TAG] Loading Loading @@ -472,7 +472,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve cst = RootNode(node).new_error(node, str(upe)) errata.append('Unknown parser "{}" in fail test "{}"!'.format(parser_name, test_name)) 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 ' 'expected failure!' % (test_name, parser_name)) tests.setdefault('__err__', {})[test_name] = errata[-1] Loading test/test_testing.py +3 −2 Original line number Diff line number Diff line Loading @@ -257,7 +257,8 @@ class TestLookahead: "match": { 1: """Mountains: big: 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": { 6: """Mountains: big: """ Loading Loading
DHParser/testing.py +6 −6 Original line number Diff line number Diff line Loading @@ -342,7 +342,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve parser[parser_name].apply(find_lookahead) return lookahead_found def lookahead_artifact(st): def lookahead_artifact(syntax_tree: Node): """ Returns True, if the error merely occurred, because the parser stopped in front of a sequence that was captured by a lookahead Loading @@ -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 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 and raw_errors[-1].code == Error.PARSER_LOOKAHEAD_MATCH_ONLY and raw_errors[-2].code == Error.PARSER_STOPPED_BEFORE_END) Loading @@ -360,7 +360,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve if is_artifact: # don't remove zombie node with error message at the end # 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), include_root=True, reverse=True): zombie = parent[ZOMBIE_TAG] Loading Loading @@ -472,7 +472,7 @@ def grammar_unit(test_unit, parser_factory, transformer_factory, report=True, ve cst = RootNode(node).new_error(node, str(upe)) errata.append('Unknown parser "{}" in fail test "{}"!'.format(parser_name, test_name)) 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 ' 'expected failure!' % (test_name, parser_name)) tests.setdefault('__err__', {})[test_name] = errata[-1] Loading
test/test_testing.py +3 −2 Original line number Diff line number Diff line Loading @@ -257,7 +257,8 @@ class TestLookahead: "match": { 1: """Mountains: big: 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": { 6: """Mountains: big: """ Loading