mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-28 04:18:52 -06:00
refactor: index source lines once per file
core.lines.LineIndex answers the line of an offset by binary search. mame_parser and fbneo_parser counted the newlines before each match, O(n) per set, and csharp_source kept its own copy of the index. arcade_parent_importer reads a profile's repository slug through core.upstream.parse_repo and refuses a source that is not on GitHub, the only forge its fetches reach.
This commit is contained in:
1 parent
c63c2f369e
commit
facebef9e5
5 files changed
+83
-6
No files matched your search
@@ -0,0 +1,42 @@
|
||||
"""One line index answers the line of every offset a parser reports."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tests
|
||||
|
||||
import unittest
|
||||
|
||||
from core.lines import LineIndex
|
||||
|
||||
|
||||
class LinesOfOffsets(unittest.TestCase):
|
||||
TEXT = "a\nbc\n\nd"
|
||||
|
||||
def test_each_offset_gets_the_count_of_newlines_before_it_plus_one(self):
|
||||
index = LineIndex(self.TEXT)
|
||||
for offset in range(len(self.TEXT) + 1):
|
||||
with self.subTest(offset=offset):
|
||||
self.assertEqual(index.line(offset), self.TEXT[:offset].count("\n") + 1)
|
||||
|
||||
def test_a_line_starts_after_the_newline_before_it(self):
|
||||
index = LineIndex(self.TEXT)
|
||||
self.assertEqual([index.start(n) for n in (1, 2, 3, 4)], [0, 2, 5, 6])
|
||||
|
||||
def test_a_text_without_newline_is_one_line(self):
|
||||
self.assertEqual(LineIndex("").line(0), 1)
|
||||
self.assertEqual(LineIndex("abc").line(2), 1)
|
||||
|
||||
|
||||
class ParsersReportLines(unittest.TestCase):
|
||||
def test_mame_and_fbneo_sets_carry_their_line(self):
|
||||
from scripts.scraper.fbneo_parser import find_bios_sets
|
||||
from scripts.scraper.mame_parser import find_bios_root_sets
|
||||
|
||||
mame = "\n\nGAME( 1990, neogeo, 0, ng, ng, ng_state, init, ROT0, \"SNK\", \"Neo\", MACHINE_IS_BIOS_ROOT )\n"
|
||||
self.assertEqual(find_bios_root_sets(mame, "neogeo.cpp")["neogeo"]["source_line"], 3)
|
||||
fbneo = '\n\n\nstruct BurnDriver BurnDrvNeogeo = {\n\t"neogeo", NULL, NULL, NULL, "1990",\n\tBDF_BOARDROM,\n};\n'
|
||||
self.assertEqual(find_bios_sets(fbneo, "d_neogeo.cpp")["neogeo"]["source_line"], 4)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user