STRA-338: architecture gate forbids new mechanical file names (impl_*, *_fn, numbered), baseline lists the 964 existing; rustsplit names modules after what they hold

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-08 00:50:17 +01:00
co-authored by Claude Sonnet 5.5
parent 4b04c24981
commit ac60df040f
14 changed files with 1124 additions and 42 deletions
+21 -5
View File
@@ -68,7 +68,7 @@ class Items(unittest.TestCase):
def test_item_kinds_and_names(self):
found = [(i.kind, i.name) for i in parse_items(SOURCE)]
self.assertEqual(found, [("other", "std"), ("other", "LIMIT"), ("other", "Thing"), ("impl", "Thing"),
("impl", "fmt_Display_for"), ("fn", "helper"), ("fn", "shared"), ("other", "tests")])
("impl", "Display_for_Thing"), ("fn", "helper"), ("fn", "shared"), ("other", "tests")])
def test_inherent_impl_is_detected(self):
self.assertEqual([i.inherent for i in parse_items(SOURCE) if i.kind == "impl"], [True, False])
@@ -111,6 +111,22 @@ class Retargeting(unittest.TestCase):
class Planning(unittest.TestCase):
def test_module_names_say_what_they_hold_and_never_how_they_were_made(self):
_, children = plan_split(SOURCE, 8)
self.assertEqual(sorted(children), ["display_for_thing", "helper", "shared", "thing_methods"])
for name in children:
self.assertFalse(name.startswith("impl_") or name.endswith("_fn") or re.search(r"_[0-9]+$", name), name)
def test_a_cut_impl_names_its_continuation_after_its_first_method(self):
method = " fn m{n}(&self) {{\n let x = {n};\n }}\n"
source = "struct S;\nimpl S {\n" + "".join(method.format(n=n) for n in range(6)) + "}\n"
_, children = plan_split(source, 8)
self.assertTrue(any(name.startswith("s_methods_from_m") for name in children), sorted(children))
def test_a_taken_name_gets_a_word_not_a_number(self):
_, children = plan_split("fn a() {}\nfn a() {}\n", 1)
self.assertEqual(sorted(children), ["a", "a_more"])
def test_fns_and_impls_move_and_the_rest_stays(self):
parent, children = plan_split(SOURCE, 8)
self.assertIn("pub struct Thing", parent)
@@ -120,12 +136,12 @@ class Planning(unittest.TestCase):
self.assertTrue(all("use super::*;" in text for text in children.values()))
for name in children:
self.assertIn(f"mod {name};", parent)
self.assertIn("use helper_fn::helper;", parent)
self.assertIn("pub(crate) use shared_fn::shared;", parent)
self.assertIn("use helper::helper;", parent)
self.assertIn("pub(crate) use shared::shared;", parent)
def test_cfg_attributes_follow_the_fn_to_its_use(self):
parent, _ = plan_split('#[cfg(unix)]\npub fn a() {}\n', 100)
self.assertIn('#[cfg(unix)]\n#[allow(unused_imports)]\npub use a_fn::a;', parent)
self.assertIn('#[cfg(unix)]\n#[allow(unused_imports)]\npub use a::a;', parent)
def test_a_long_inherent_impl_is_cut_between_its_methods(self):
methods = "".join(f" fn m{n}(&self) -> u32 {{\n {n}\n }}\n" for n in range(6))
@@ -147,7 +163,7 @@ class Planning(unittest.TestCase):
def test_explicit_paths_are_written_for_path_loaded_files(self):
parent, _ = plan_split("fn a() {}\n", 100, explicit_dir="foo")
self.assertIn('#[path = "foo/a_fn.rs"]', parent)
self.assertIn('#[path = "foo/a.rs"]', parent)
if __name__ == "__main__":