Index: gc_core/py/lang_core/tests_core.py ================================================================== --- gc_core/py/lang_core/tests_core.py +++ gc_core/py/lang_core/tests_core.py @@ -72,45 +72,51 @@ spfParsingTest = os.path.join(spHere, "gc_test.txt") if not os.path.exists(spfParsingTest): print(f"No file in <{spHere}>") return with open(spfParsingTest, "r", encoding="utf-8") as hSrc: - nError = 0 - for sLine in ( s for s in hSrc if not s.startswith("#") and s.strip() ): + nUnexpectedErrors = 0 + nTestWithExpectedError = 0 + nTestWithExpectedErrorAndSugg = 0 + for i, sLine in enumerate( s for s in hSrc if not s.startswith("#") and s.strip() ): sLineNum = sLine[:10].strip() sLine = sLine[10:].strip() sOption = None m = zOption.search(sLine) if m: sLine = sLine[m.end():] sOption = m.group(1) if "->>" in sLine: sErrorText, sExceptedSuggs = self._splitTestLine(sLine) + nTestWithExpectedErrorAndSugg += 1 else: sErrorText = sLine.strip() sExceptedSuggs = "" sExpectedErrors = self._getExpectedErrors(sErrorText) + if sExpectedErrors.strip() != "": + nTestWithExpectedError += 1 sTextToCheck = sErrorText.replace("}}", "").replace("{{", "") sFoundErrors, sListErr, sFoundSuggs = self._getFoundErrors(sTextToCheck, sOption) # tests if sExpectedErrors != sFoundErrors: print("\n# Line num: " + sLineNum + \ "\n> to check: " + _fuckBackslashUTF8(sTextToCheck) + \ "\n expected: " + sExpectedErrors + \ "\n found: " + sFoundErrors + \ "\n errors: \n" + sListErr) - nError += 1 + nUnexpectedErrors += 1 elif sExceptedSuggs: if sExceptedSuggs != sFoundSuggs: print("\n# Line num: " + sLineNum + \ "\n> to check: " + _fuckBackslashUTF8(sTextToCheck) + \ "\n expected: " + sExceptedSuggs + \ "\n found: " + sFoundSuggs + \ "\n errors: \n" + sListErr) - nError += 1 - if nError: - print("Unexpected errors:", nError) + nUnexpectedErrors += 1 + print("Tests with expected errors:", nTestWithExpectedError, " and suggestions:", nTestWithExpectedErrorAndSugg, ":", str(nTestWithExpectedErrorAndSugg/nTestWithExpectedError*100), "%") + if nUnexpectedErrors: + print("Unexpected errors:", nUnexpectedErrors) # untested rules aUntestedRules = set() for _, sOpt, sLineId, sRuleId in gc_engine.listRules(): sRuleId = sRuleId.rstrip("0123456789") if sOpt != "@@@@" and sRuleId not in self._aTestedRules and not re.search("^[0-9]+[sp]$|^[pd]_", sRuleId): @@ -150,11 +156,11 @@ if aGramErrs or aSpellErrs or "" in dErr["sMessage"] or "" in dErr["sMessage"]: print("\n# Error in: <" + dErr["sMessage"] + ">\n " + dErr["sLineId"] + " / " + dErr["sRuleId"]) for dMsgErr in aGramErrs: print(" error: {sLineId} / {sRuleId} at {nStart}:{nEnd}".format(**dMsgErr)) for dMsgErr in aSpellErrs: - print(" spelling mistake: <{sValue}> at {nStart}:{nEnd}".format(**dMsgErr)) + print(" spelling mistake: <{sValue}> at {nStart}:{nEnd}".format(**dMsgErr)) return sRes, sListErr, "|||".join(lAllSugg) def _getExpectedErrors (self, sLine): sRes = " " * len(sLine) for i, m in enumerate(self._zError.finditer(sLine)):