138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
lAllSugg = []
for dErr in sorted(aErrs, key=lambda d: d["nStart"]):
sRes = sRes[:dErr["nStart"]] + "~" * (dErr["nEnd"] - dErr["nStart"]) + sRes[dErr["nEnd"]:]
sListErr += " * {sLineId} / {sRuleId} at {nStart}:{nEnd}\n".format(**dErr)
lAllSugg.append("|".join(dErr["aSuggestions"]))
self._aTestedRules.add(dErr["sRuleId"].rstrip("0123456789"))
# test messages
if "<start>" in dErr["sMessage"] or "<end>" in dErr["sMessage"]:
print("\n# Line num : " + dErr["sLineId"] + \
"\n rule name: " + dErr["sRuleId"] + \
"\n message : " + dErr["sMessage"])
return sRes, sListErr, "|||".join(lAllSugg)
def _getExpectedErrors (self, sLine):
sRes = " " * len(sLine)
for i, m in enumerate(self._zError.finditer(sLine)):
nStart = m.start() - (4 * i)
nEnd = m.end() - (4 * (i+1))
sRes = sRes[:nStart] + "~" * (nEnd - nStart) + sRes[nEnd:-4]
return sRes
def main():
"start function"
unittest.main()
if __name__ == '__main__':
|
>
>
|
|
|
<
>
>
>
>
>
>
>
>
|
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
lAllSugg = []
for dErr in sorted(aErrs, key=lambda d: d["nStart"]):
sRes = sRes[:dErr["nStart"]] + "~" * (dErr["nEnd"] - dErr["nStart"]) + sRes[dErr["nEnd"]:]
sListErr += " * {sLineId} / {sRuleId} at {nStart}:{nEnd}\n".format(**dErr)
lAllSugg.append("|".join(dErr["aSuggestions"]))
self._aTestedRules.add(dErr["sRuleId"].rstrip("0123456789"))
# test messages
if False:
aMsgErrs = gc_engine.parse(purgeMessage(dErr["sMessage"]))
if aMsgErrs or "<start>" in dErr["sMessage"] or "<end>" in dErr["sMessage"]:
print("\n# Incorrect message: <" + dErr["sMessage"] + ">\n " + dErr["sLineId"] + " / " + dErr["sRuleId"])
if aMsgErrs:
for dMsgErr in sorted(aMsgErrs, key=lambda d: d["nStart"]):
print(" error: {sLineId} / {sRuleId} 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)):
nStart = m.start() - (4 * i)
nEnd = m.end() - (4 * (i+1))
sRes = sRes[:nStart] + "~" * (nEnd - nStart) + sRes[nEnd:-4]
return sRes
def purgeMessage (sMessage):
sMessage = sMessage.replace("l’ ", "l’").replace("d’ ", "d’").replace("m’ ", "m’").replace("t’ ", "t’").replace("s’ ", "s’").replace("qu’ ", "qu’")
sMessage = sMessage.replace("L’ ", "L’").replace("D’ ", "D’").replace("M’ ", "M’").replace("T’ ", "T’").replace("S’ ", "S’").replace("QU’ ", "QU’")
return sMessage
def main():
"start function"
unittest.main()
if __name__ == '__main__':
|