mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-18 09:23:26 -05:00
fix: never extend a RetroPie list of examples
This commit is contained in:
1 parent
d0bdf6d08f
commit
1e2f4e810b
2 files changed
+20
-1
No files matched your search
@@ -49,6 +49,7 @@ _FILENAME = re.compile(r"[A-Za-z0-9][\w.+-]*\.[A-Za-z0-9]{1,5}\b")
|
||||
_BIOS_CLAUSE = re.compile(r"BIOS\b.*?(?=\\n|$)", re.DOTALL)
|
||||
_BIOS_NOUN = re.compile(r"BIOS (files?)\b")
|
||||
_SEPARATOR = re.compile(r"\s*(?:,\s*(?:and\s+)?|and\s+)")
|
||||
_EXAMPLES = re.compile(r"\b(?:e\.?g\b|for example|for instance|such as|like)\W*$", re.I)
|
||||
|
||||
|
||||
class Exporter(BaseExporter):
|
||||
@@ -148,7 +149,8 @@ class Exporter(BaseExporter):
|
||||
A list of alternatives ("a or b", "a/b") is not an enumeration: an
|
||||
appended ", c" reads as one more required file and the plural turns
|
||||
"one of these" into "all of these". Such a list is left alone, and so
|
||||
is one with words between its names, which a rewrite would lose.
|
||||
are a list of examples ("eg. a, b") and one with words between its
|
||||
names, which a rewrite would lose.
|
||||
"""
|
||||
clause = _BIOS_CLAUSE.search(help_text)
|
||||
if clause is None:
|
||||
@@ -160,6 +162,10 @@ class Exporter(BaseExporter):
|
||||
between = text[names[0].start():names[-1].end()]
|
||||
if re.search(r"\bor\b|/", between):
|
||||
return None
|
||||
# "a minimum of two BIOS files (eg. a, b)" names examples, not the
|
||||
# set: an appended name reads as one more required file.
|
||||
if _EXAMPLES.search(text[:names[0].start()]):
|
||||
return None
|
||||
gaps = [text[a.end():b.start()] for a, b in zip(names, names[1:])]
|
||||
if not all(_SEPARATOR.fullmatch(gap) for gap in gaps):
|
||||
return None
|
||||
|
||||
@@ -543,6 +543,19 @@ class RetroPieProposals(unittest.TestCase):
|
||||
RetroPie._extended(help_text, enumeration, missing), expected
|
||||
)
|
||||
|
||||
def test_a_list_of_examples_is_not_extended(self):
|
||||
# lr-neocd: "a minimum of two BIOS files (eg. ng-lo.rom,
|
||||
# uni-bioscd.rom)" became "(eg. ng-lo.rom, uni-bioscd.rom and
|
||||
# neocd.bin)": two announced, three named, read as all required.
|
||||
help_text = (
|
||||
"You will need a minimum of two BIOS files (eg. ng-lo.rom, "
|
||||
"uni-bioscd.rom) which should be copied to $biosdir/neocd"
|
||||
)
|
||||
self.assertIsNone(RetroPie._enumeration(help_text))
|
||||
self.assertIsNone(RetroPie._enumeration(
|
||||
"Copy BIOS files such as a.bin and b.bin to $biosdir"
|
||||
))
|
||||
|
||||
def test_words_between_names_are_not_rewritten(self):
|
||||
self.assertIsNone(
|
||||
RetroPie._enumeration("BIOS files a.bin (US) and b.bin to $biosdir")
|
||||
|
||||
Reference in new issue
Block a user