Commit 4ac99699 authored by eckhart's avatar eckhart
Browse files

- tests/ a bit of cleaning up

parent 7f0f2467
...@@ -165,16 +165,12 @@ class TestParserNameOverwriteBug: ...@@ -165,16 +165,12 @@ class TestParserNameOverwriteBug:
def test_term_bug(self): def test_term_bug(self):
grammar = get_ebnf_grammar() grammar = get_ebnf_grammar()
st = grammar('impossible = [§"an optional requirement"]') st = grammar('impossible = [§"an optional requirement"]')
# print(st.as_sxpr())
get_ebnf_transformer()(st) get_ebnf_transformer()(st)
# print(st.as_sxpr())
lang = """series = "A" "B" §"C" "D" lang = """series = "A" "B" §"C" "D"
""" """
parser = get_ebnf_grammar() parser = get_ebnf_grammar()
st = grammar(lang) st = grammar(lang)
# print(st.as_sxpr())
get_ebnf_transformer()(st) get_ebnf_transformer()(st)
# print(st.as_sxpr())
result = get_ebnf_compiler()(st) result = get_ebnf_compiler()(st)
messages = st.errors_sorted messages = st.errors_sorted
assert not has_errors(messages), str(messages) assert not has_errors(messages), str(messages)
...@@ -182,7 +178,6 @@ class TestParserNameOverwriteBug: ...@@ -182,7 +178,6 @@ class TestParserNameOverwriteBug:
def test_single_mandatory_bug(self): def test_single_mandatory_bug(self):
lang = """series = § /B/""" lang = """series = § /B/"""
result, messages, ast = compile_ebnf(lang) result, messages, ast = compile_ebnf(lang)
# print(result)
assert result.find('Required') < 0 assert result.find('Required') < 0
parser = grammar_provider(lang)() parser = grammar_provider(lang)()
st = parser('B') st = parser('B')
...@@ -477,7 +472,6 @@ class TestErrorCustomization: ...@@ -477,7 +472,6 @@ class TestErrorCustomization:
st = parser("ABCD"); assert not st.error_flag st = parser("ABCD"); assert not st.error_flag
st = parser("A_CD"); assert not st.error_flag st = parser("A_CD"); assert not st.error_flag
st = parser("AB_D"); assert st.error_flag st = parser("AB_D"); assert st.error_flag
print(st.errors_sorted)
assert st.errors_sorted[0].code == Error.MANDATORY_CONTINUATION assert st.errors_sorted[0].code == Error.MANDATORY_CONTINUATION
assert st.errors_sorted[0].message == "a user defined error message" assert st.errors_sorted[0].message == "a user defined error message"
# transitivity of mandatory-operator # transitivity of mandatory-operator
......
...@@ -55,7 +55,6 @@ class TestParserClass: ...@@ -55,7 +55,6 @@ class TestParserClass:
l = [] l = []
gr.root__.apply(visitor) gr.root__.apply(visitor)
s3 = ", ".join(l) s3 = ", ".join(l)
# print(s1); print(s2); print(s3)
assert s1 == s2 == s3 assert s1 == s2 == s3
...@@ -119,8 +118,6 @@ class TestInfiLoopsAndRecursion: ...@@ -119,8 +118,6 @@ class TestInfiLoopsAndRecursion:
parser = grammar_provider(minilang)() parser = grammar_provider(minilang)()
syntax_tree = parser(snippet) syntax_tree = parser(snippet)
assert syntax_tree.error_flag assert syntax_tree.error_flag
# print(syntax_tree.as_sxpr())
# print(syntax_tree.errors())
class TestFlowControl: class TestFlowControl:
...@@ -325,7 +322,6 @@ class TestSeries: ...@@ -325,7 +322,6 @@ class TestSeries:
st = parser("ABCD"); assert not st.error_flag st = parser("ABCD"); assert not st.error_flag
st = parser("A_CD"); assert not st.error_flag st = parser("A_CD"); assert not st.error_flag
st = parser("AB_D"); assert st.error_flag st = parser("AB_D"); assert st.error_flag
# print(st.errors())
assert st.errors_sorted[0].code == Error.MANDATORY_CONTINUATION assert st.errors_sorted[0].code == Error.MANDATORY_CONTINUATION
# transitivity of mandatory-operator # transitivity of mandatory-operator
st = parser("ABC_"); assert st.error_flag st = parser("ABC_"); assert st.error_flag
...@@ -646,7 +642,6 @@ class TestReentryAfterError: ...@@ -646,7 +642,6 @@ class TestReentryAfterError:
gr = self.gr; gr.resume_rules = dict() gr = self.gr; gr.resume_rules = dict()
content = 'ALPHA acb BETA bac GAMMA cab .' content = 'ALPHA acb BETA bac GAMMA cab .'
cst = gr(content) cst = gr(content)
# print(cst.as_sxpr())
assert cst.error_flag assert cst.error_flag
assert cst.content == content assert cst.content == content
assert cst.pick('alpha').content.startswith('ALPHA') assert cst.pick('alpha').content.startswith('ALPHA')
...@@ -655,7 +650,6 @@ class TestReentryAfterError: ...@@ -655,7 +650,6 @@ class TestReentryAfterError:
gr = self.gr; gr.resume_rules = dict() gr = self.gr; gr.resume_rules = dict()
content = 'ALPHA acb' content = 'ALPHA acb'
cst = gr(content, 'alpha') cst = gr(content, 'alpha')
# print(cst.as_sxpr())
assert cst.error_flag assert cst.error_flag
assert cst.content == content assert cst.content == content
assert cst.pick('alpha').content.startswith('ALPHA') assert cst.pick('alpha').content.startswith('ALPHA')
...@@ -665,7 +659,6 @@ class TestReentryAfterError: ...@@ -665,7 +659,6 @@ class TestReentryAfterError:
gr.resume_rules__['alpha'] = ['BETA'] gr.resume_rules__['alpha'] = ['BETA']
content = 'ALPHA acb BETA bac GAMMA cab .' content = 'ALPHA acb BETA bac GAMMA cab .'
cst = gr(content) cst = gr(content)
# print(cst.as_sxpr())
assert cst.error_flag assert cst.error_flag
assert cst.content == content assert cst.content == content
assert cst.pick('alpha').content.startswith('ALPHA') assert cst.pick('alpha').content.startswith('ALPHA')
...@@ -677,7 +670,6 @@ class TestReentryAfterError: ...@@ -677,7 +670,6 @@ class TestReentryAfterError:
gr.resume_rules__['alpha'] = ['XXX'] gr.resume_rules__['alpha'] = ['XXX']
content = 'ALPHA acb BETA bac GAMMA cab .' content = 'ALPHA acb BETA bac GAMMA cab .'
cst = gr(content) cst = gr(content)
# print(cst.as_sxpr())
assert cst.error_flag assert cst.error_flag
assert cst.content == content assert cst.content == content
# assert cst.pick('alpha').content.startswith('ALPHA') # assert cst.pick('alpha').content.startswith('ALPHA')
...@@ -688,7 +680,6 @@ class TestReentryAfterError: ...@@ -688,7 +680,6 @@ class TestReentryAfterError:
gr.resume_rules__['alpha'] = ['BETA', 'GAMMA'] gr.resume_rules__['alpha'] = ['BETA', 'GAMMA']
content = 'ALPHA acb BETA bac GAMMA cab .' content = 'ALPHA acb BETA bac GAMMA cab .'
cst = gr(content) cst = gr(content)
# print(cst.as_sxpr())
assert cst.error_flag assert cst.error_flag
assert cst.content == content assert cst.content == content
assert cst.pick('alpha').content.startswith('ALPHA') assert cst.pick('alpha').content.startswith('ALPHA')
...@@ -700,7 +691,6 @@ class TestReentryAfterError: ...@@ -700,7 +691,6 @@ class TestReentryAfterError:
gr.resume_rules__['alpha'] = ['BETA', 'GAMMA'] gr.resume_rules__['alpha'] = ['BETA', 'GAMMA']
content = 'ALPHA acb GAMMA cab .' content = 'ALPHA acb GAMMA cab .'
cst = gr(content) cst = gr(content)
# print(cst.as_sxpr())
assert cst.error_flag assert cst.error_flag
assert cst.content == content assert cst.content == content
assert cst.pick('alpha').content.startswith('ALPHA') assert cst.pick('alpha').content.startswith('ALPHA')
...@@ -714,7 +704,6 @@ class TestReentryAfterError: ...@@ -714,7 +704,6 @@ class TestReentryAfterError:
gr.resume_rules__['bac'] = ['GAMMA'] gr.resume_rules__['bac'] = ['GAMMA']
content = 'ALPHA abc BETA bad GAMMA cab .' content = 'ALPHA abc BETA bad GAMMA cab .'
cst = gr(content) cst = gr(content)
# print(cst.as_sxpr())
assert cst.error_flag assert cst.error_flag
assert cst.content == content assert cst.content == content
assert cst.pick('alpha').content.startswith('ALPHA') assert cst.pick('alpha').content.startswith('ALPHA')
...@@ -723,7 +712,6 @@ class TestReentryAfterError: ...@@ -723,7 +712,6 @@ class TestReentryAfterError:
# multiple failures # multiple failures
content = 'ALPHA acb BETA bad GAMMA cab .' content = 'ALPHA acb BETA bad GAMMA cab .'
cst = gr(content) cst = gr(content)
# print(cst.as_sxpr())
assert cst.error_flag assert cst.error_flag
assert cst.content == content assert cst.content == content
assert cst.pick('alpha').content.startswith('ALPHA') assert cst.pick('alpha').content.startswith('ALPHA')
...@@ -743,7 +731,6 @@ class TestConfiguredErrorMessages: ...@@ -743,7 +731,6 @@ class TestConfiguredErrorMessages:
st = parser("AB_D"); assert st.error_flag st = parser("AB_D"); assert st.error_flag
assert st.errors_sorted[0].code == Error.MALFORMED_ERROR_STRING assert st.errors_sorted[0].code == Error.MALFORMED_ERROR_STRING
assert st.errors_sorted[1].code == Error.MANDATORY_CONTINUATION assert st.errors_sorted[1].code == Error.MANDATORY_CONTINUATION
# print(st.errors())
class TestUnknownParserError: class TestUnknownParserError:
...@@ -773,7 +760,6 @@ class TestEarlyTokenWhitespaceDrop: ...@@ -773,7 +760,6 @@ class TestEarlyTokenWhitespaceDrop:
def test_drop(self): def test_drop(self):
cst = self.gr('4 + 3 * 5') cst = self.gr('4 + 3 * 5')
# print(cst.as_sxpr())
assert not cst.pick(':Token') assert not cst.pick(':Token')
assert not cst.pick(':Whitespace') assert not cst.pick(':Whitespace')
cst = self.gr('A + B') cst = self.gr('A + B')
......
...@@ -98,8 +98,6 @@ class TestNode: ...@@ -98,8 +98,6 @@ class TestNode:
tree['d'].result = "x" tree['d'].result = "x"
assert not tree.equals(tree_copy) assert not tree.equals(tree_copy)
assert tree_copy.equals(parse_sxpr('(a (b c) (d (e f) (h i)))')) assert tree_copy.equals(parse_sxpr('(a (b c) (d (e f) (h i)))'))
# print(tree.as_sxpr())
# print(parse_sxpr('(a (b c) (d x))').as_sxpr())
assert tree.equals(parse_sxpr('(a (b c) (d x))')) assert tree.equals(parse_sxpr('(a (b c) (d x))'))
# this also checks for errors equality... # this also checks for errors equality...
...@@ -301,7 +299,6 @@ class TestSerialization: ...@@ -301,7 +299,6 @@ class TestSerialization:
assert tree.as_xml() == "<A>\n <B>C</B>\n <D>E</D>\n</A>", xml assert tree.as_xml() == "<A>\n <B>C</B>\n <D>E</D>\n</A>", xml
tree.attr['xml:space'] = 'preserve' tree.attr['xml:space'] = 'preserve'
# print(tree.attr)
xml = tree.as_xml() xml = tree.as_xml()
assert xml == '<A xml:space="preserve"><B>C</B><D>E</D></A>', xml assert xml == '<A xml:space="preserve"><B>C</B><D>E</D></A>', xml
......
...@@ -224,8 +224,6 @@ class TestGrammarTest: ...@@ -224,8 +224,6 @@ class TestGrammarTest:
report = get_report(self.cases) report = get_report(self.cases)
assert report.find('### CST') >= 0 assert report.find('### CST') >= 0
errata = grammar_unit(self.failure_cases, parser_fac, trans_fac) errata = grammar_unit(self.failure_cases, parser_fac, trans_fac)
# for e in errata:
# print(e)
assert len(errata) == 3, str(errata) assert len(errata) == 3, str(errata)
# def test_get_report(self): # def test_get_report(self):
...@@ -310,9 +308,6 @@ class TestLookahead: ...@@ -310,9 +308,6 @@ class TestLookahead:
grammar = self.grammar_fac() grammar = self.grammar_fac()
cst = grammar(doc) cst = grammar(doc)
assert not cst.error_flag assert not cst.error_flag
# trans = self.trans_fac()
# trans(cst)
# print(cst.as_sxpr())
def test_unit_lookahead(self): def test_unit_lookahead(self):
errata = grammar_unit(self.cases, self.grammar_fac, self.trans_fac) errata = grammar_unit(self.cases, self.grammar_fac, self.trans_fac)
......
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