Commit 656ac9e2 authored by di68kap's avatar di68kap
Browse files

- test cases for MLW adjusted

- some minor  bug fixes
parent 557c56cd
......@@ -786,6 +786,7 @@ class EBNFCompiler(Compiler):
def on_expression(self, node) -> str:
# TODO: Add check for errors like "a" | "ab" (which will always yield a, even for ab)
return self.non_terminal(node, 'Alternative')
......
......@@ -86,12 +86,27 @@ def unit_from_file(filename):
determined by the ending of its name.
"""
if filename.endswith(".json"):
return unit_from_json(filename)
test_unit = unit_from_json(filename)
elif filename.endswith(".ini"):
return unit_from_configfile(filename)
test_unit = unit_from_configfile(filename)
else:
raise ValueError("Unknown unit test file type: " + filename[filename.rfind('.'):])
# Check for ambiguous Test names
errors = []
for parser_name, tests in test_unit.items():
m_names = set(tests.get('match', dict()).keys())
f_names = set(tests.get('fail', dict()).keys())
intersection = list(m_names & f_names); intersection.sort()
if intersection:
errors.append("Same names %s assigned to match and fail test "
"of parser %s." % (str(intersection), parser_name))
if errors:
raise EnvironmentError("Error(s) in Testfile %s :\n" % filename
+ '\n'.join(errors))
return test_unit
def get_report(test_unit):
"""
......@@ -122,6 +137,15 @@ def get_report(test_unit):
elif ast:
report.append('\n### AST')
report.append(indent(ast.as_sxpr()))
for test_name, test_code in tests.get('fail', dict()).items():
heading = 'Fail-test "%s"' % test_name
report.append('\n%s\n%s\n' % (heading, '-' * len(heading)))
report.append('### Test-code:')
report.append(indent(test_code))
error = tests.get('__err__', {}).get(test_name, "")
if error:
report.append('\n### Error:')
report.append(error)
return '\n'.join(report)
......@@ -235,14 +259,17 @@ def grammar_suite(directory, parser_factory, transformer_factory,
if not ignore_unknown_filetypes or str(e).find("Unknown") < 0:
raise e
os.chdir(save_cwd)
error_report = []
error_report = []; err_N = 0
if all_errors:
for filename in all_errors:
error_report.append('Errors found by unit test "%s":' % filename)
err_N += len(all_errors[filename])
for error in all_errors[filename]:
error_report.append('\t' + '\n\t'.join(error.split('\n')))
if error_report:
if verbose: print("\nFAILURE! %i error%s found!\n" % (err_N, 's' if err_N > 1 else ''))
return ('Test suite "%s" revealed some errors:\n\n' % directory) + '\n'.join(error_report)
if verbose: print("\nSUCCESS! All tests passed :-)\n")
return ''
......
......@@ -48,5 +48,4 @@ if error_report:
print('\n')
print(error_report)
sys.exit(1)
else:
print('\nSUCCESS! All tests passed :-)')
......@@ -60,7 +60,7 @@ genus = "maskulinum" | "m."
## ETYMOLOGIE-POSITION ##
EtymologiePosition = "ETYMOLOGIE" [LZ] EtymologieVarianten
EtymologieVarianten = { !([LZ] GROSSFOLGE) EtymologieVariante }+
EtymologieVarianten = { !SCHLUESSELWORT EtymologieVariante }+
EtymologieVariante = /.*/ # NOCH ZU VERFOLLSTÄNDIGEN
......@@ -69,7 +69,7 @@ EtymologieVariante = /.*/ # NOCH ZU VERFOLLSTÄNDIGEN
ArtikelKopf = SchreibweisenPosition
SchreibweisenPosition = "SCHREIBWEISE" [LZ] §SWTyp ":" [LZ]
SWVariante { ABS SWVariante} [LZ]
SWTyp = "script." | "script. fat-"
SWTyp = "script. fat-" | "script."
SWVariante = Schreibweise ":" Beleg
Schreibweise = ZEICHENFOLGE
......@@ -84,9 +84,9 @@ Interpretamente = LateinischeBedeutung [LZ] §DeutscheBedeutung [LZ]
LateinischeBedeutung = SW_LAT /(?:(?![A-ZÄÖÜ][A-ZÄÖÜ]).)+/~
DeutscheBedeutung = SW_DEU /(?:(?![A-ZÄÖÜ][A-ZÄÖÜ]).)+/~
Belege = "BELEGE" [LZ] (EinBeleg | { "*" EinBeleg })
EinBeleg = { !([LZ] ("*" | GROSSFOLGE )) /\s*[^\n]*\s*/ }+ [Zusatz]
Zusatz = "ZUSATZ" /\s*.*/ ABS
Belege = "BELEGE" [LZ] (EinBeleg | { "*" EinBeleg }) ABS
EinBeleg = { !([LZ] "*" | SCHLUESSELWORT) /\s*[^\n]*/~ [ZW] }+ [Zusatz]
Zusatz = "ZUSATZ" /\s*.*/
#### AUTOR/AUTORIN ###########################################################
......@@ -98,9 +98,11 @@ Name = { NAME | NAMENS_ABKÜRZUNG }+
#### Schlüsselwörter #########################################################
SW_LAT = "LATEINISCH" | "LAT"
SW_DEU = "DEUTSCH" | "DEUT"
SW_DEU = "DEUTSCH" | "DEU"
SW_GRIECH = "GRIECHISCH" | "GRIECH" | "GRIE" | "GRI"
SCHLUESSELWORT = { //~ /\n/ }+ !ROEMISCHE_ZAHL /[A-ZÄÖÜ]{3,}\s+/
#### GENERISCHE UND ATOMARE AUSDRÜCKE ########################################
......@@ -119,7 +121,8 @@ DEU_KLEIN = /[a-zäöüß]+/~
LAT_WORT = /[a-z]+/~
LAT_WORT_TEIL = /[a-z]+/
GROSSSCHRIFT = /[A-ZÄÖÜ]+/~
GROSSFOLGE = /[A-ZÄÖÜ][A-ZÄÖÜ][A-ZÄÖÜ]/ # drei Großbuchstaben in Folge
ZAHL = /\d+/~
ROEMISCHE_ZAHL = /(?=[MDCLXVI])M*(C[MD]|D?C*)(X[CL]|L?X*)(I[XV]|V?I*)/~
BUCHSTABENFOLGE = /\w+/~
ZEICHENFOLGE = /[\w()-]+/~
......
[match:SCHLUESSELWORT]
M1: """
AUTORIN """
[match:RZS]
1: """
M1: """
"""
[match:LEERZEILE]
1: """
M1: """
"""
2: """
M2: """
\# Kommentar"""
3: """
M3: """
"""
[fail:LEERZEILE]
1: """
F1: """
"""
2: """
F2: """
\# Kommentar
......@@ -29,98 +34,98 @@
[match:LÜCKE]
1: """
M1: """
"""
2: """
M2: """
\# Kommentar
"""
3: """
M3: """
"""
4: """
M4: """
\# Kommentar
\# Kommentar
"""
5: """ \#Kommentar
M5: """ \#Kommentar
\# Kommentar
\# Kommentar"""
[fail:LÜCKE]
1: " "
F1: " "
2: """
F2: """
"""
3: """
F3: """
\# Kommentar"""
4: """ \#Kommentar
F4: """ \#Kommentar
\# Kommentar
\# Kommentar"""
[match:LEERRAUM]
1: " "
2: " # Kommentar"
3: " "
4: "# Kommentar"
5: """# Kommentar
M1: " "
M2: " # Kommentar"
M3: " "
M4: "# Kommentar"
M5: """# Kommentar
"""
6: """
M6: """
\# Kommentar
\# Kommentar
"""
7: """
M7: """
"""
[fail:LEERRAUM]
1: "X"
F1: "X"
[match:ZWW]
1: """
M1: """
"""
2: """
M2: """
\# Kommentar"""
3: """
M3: """
\# Kommentar
"""
4: """
M4: """
"""
[fail:ZWW]
1: " "
F1: " "
[match:ZW]
1: """
M1: """
"""
2: """
M2: """
\# Kommentar"""
[fail:ZW]
1: """
F1: """
"""
[match:SchreibweisenPosition]
1: """script.:
1: """SCHREIBWEISE
script.:
vizreg-: Verweis_003
festregel(a): Verweis_004
fezdregl(a): Verweis_005
......
[match:BedeutungsPosition]
1: """BEDEUTUNG
M1: """BEDEUTUNG
LAT pannus, faciale, sudarium
DEU Gesichts-, Schweißtuch [usu liturg.; de re v. p. 32, 63]
"""
[match:Bedeutung]
1: """LAT capital, rica
M1: """LAT capital, rica
DEU Kopftuch
BELEGE
......@@ -15,24 +15,21 @@
clerici et laici inprimis cum eorum -cula, dein vestibus solitis."
"""
[match:Bedeutungskategorie]###
1: """"""
[match:Interpretamente]
1: """LAT capital, rica
M1: """LAT capital, rica
DEU Kopftuch
"""
[match:LateinischeBedeutung]
1: """LAT pannus, faciale, sudarium"""
2: """LAT capital, rica"""
M1: """LAT pannus, faciale, sudarium"""
M2: """LAT capital, rica"""
[match:DeutscheBedeutung]
1: """DEU Gesichts-, Schweißtuch [usu liturg.; de re v. p. 32, 63]"""
2: """DEU Kopftuch"""
M1: """DEU Gesichts-, Schweißtuch [usu liturg.; de re v. p. 32, 63]"""
M2: """DEU Kopftuch"""
[match:Belege]
1: """BELEGE
M1: """BELEGE
* Catal.: thes. Germ.; 28,11 (post 851) "-um III."
* Form.: Sangall.; 39 p. 421,16 "munuscula ... direximus, hoc est palliolum ... ,
-as duas."
......@@ -46,10 +43,16 @@
"""
[match:EinBeleg]
1: """* Catal.: thes. Germ.; 28,11 (post 851) "-um III.""""
2: """* Form.: Sangall.; 39 p. 421,16 "munuscula ... direximus, hoc est palliolum ... ,
M1: """Catal.: thes. Germ.; 28,11 (post 851) "-um III.""""
M2: """Form.: Sangall.; 39 p. 421,16 "munuscula ... direximus, hoc est palliolum ... ,
-as duas.""""
3: """* Catal.: thes. Germ.; 18,7 "-eterculi viginti quatuor"."""
M3: """Catal.: thes. Germ.; 18,7 "-eterculi viginti quatuor"."""
[fail:EinBeleg]
F1: "* nächster Beleg"
F2: """
AUTORIN """
[match:Zusatz]
1: """ZUSATZ saepe."""
\ No newline at end of file
M1: """ZUSATZ saepe."""
......@@ -4,10 +4,10 @@
[match:SW_DEU]
1: """DEUTSCH"""
2: """DEUT"""
2: """DEU"""
[match:SW_GRIECH]
1: """GRIECHISCH"""
2: """GRIECH"""
3: """GRIE"""
4: """GRI"""
\ No newline at end of file
4: """GRI"""
import os
import sys
sys.path.extend(['../../', '../', './'])
from DHParser.toolkit import logging
from DHParser.parser import compile_source
from DHParser.dsl import recompile_grammar
if not recompile_grammar('MLW.ebnf', force=False): # recompiles Grammar only if it has changed
with open('MLW_ebnf_ERRORS.txt') as f:
print(f.read())
sys.exit(1)
from MLWCompiler import get_preprocessor, get_grammar, get_transformer, get_compiler
save_path = os.getcwd()
os.chdir("Beispiele")
for entry in os.listdir():
if entry.lower().endswith('.mlw'):
raw_name = os.path.splitext(entry)[0]
with logging(True):
result, messages, AST = compile_source(entry,
get_preprocessor(),
get_grammar(),
get_transformer(),
get_compiler())
if AST:
with open(raw_name + '.ast', 'w', encoding='utf-8') as f:
f.write(AST.as_sxpr(compact=False))
if messages:
print("Errors in: " + entry)
with open(raw_name + '.messages', 'w', encoding='utf-8') as f:
for m in messages:
s = str(m)
print(s)
f.write(s)
f.write('\n')
else:
print("\nParsing of %s successfull :-)\n" % entry)
os.chdir(save_path)
......@@ -37,15 +37,6 @@ from MLWCompiler import get_grammar, get_transformer
with toolkit.logging(True):
error_report = testing.grammar_suite('grammar_tests', get_grammar, get_transformer,
verbose=True)
# assert not error_report, error_report
# class TestMLWGrammar:
# def test_lemma_position(self):
# errata = testing.grammar_unit('grammar_tests/test_lemmaposition.ini', # MLW_TEST_CASES_LEMMA_POSITION,
# get_MLW_grammar,
# get_MLW_transformer)
# assert not errata, str(errata)
#
#
# if __name__ == "__main__":
# testing.runner("", globals())
print(error_report)
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