Add regression tests for a multi constraint Dart mixin on clause

Covers a mixin on clause naming two superclass constraints, asserting
both get an inherits edge and the second one's generic argument
still surfaces as a reference, plus a control confirming a single
constraint on clause still resolves exactly as before.

(cherry picked from commit 7b3bf2fa30)
This commit is contained in:
ayushcodes10 authored and safishamsi committed 2026-10-31 23:49:14 +00:00
1 parent 462b86213c
commit 8652055ed2
1 file changed
+49
+49
View File
@@ -817,5 +817,54 @@ class TestDart(unittest.TestCase):
self.assertIsNotNone(ext_node)
self.assertIsNone(next((n for n in result["nodes"] if "anonymous_extension" in n["id"]), None))
def test_mixin_on_clause_with_multiple_superclass_constraints(self):
"""A mixin's `on` clause may list several superclass constraints,
comma-separated (`mixin Foo on A, B {}`); every one of them must get
an `inherits` edge, not just the first."""
code = textwrap.dedent("""
mixin Selectable on Comparable<Selectable>, State<WidgetState> {
void select() {}
}
""")
path = self.temp_path / "selectable.dart"
path.write_text(code, encoding="utf-8")
result = extract_dart(path)
mixin_node = next((n for n in result["nodes"] if n["label"] == "Selectable"), None)
self.assertIsNotNone(mixin_node)
inherits_targets = {
e["target"] for e in result["edges"]
if e["source"] == mixin_node["id"] and e["relation"] == "inherits"
}
self.assertEqual(inherits_targets, {"comparable", "state"})
# The generic argument of the dropped second constraint must still
# surface as a reference, exactly like the first constraint's does.
ref_targets = {
e["target"] for e in result["edges"]
if e["source"] == mixin_node["id"] and e["relation"] == "references"
}
self.assertIn("widgetstate", ref_targets)
def test_mixin_on_clause_with_single_superclass_constraint_is_unaffected(self):
"""A control for the fix above: a mixin with only one `on` superclass
constraint must still resolve exactly as before."""
code = textwrap.dedent("""
mixin AuthMixin on BaseWidget {}
""")
path = self.temp_path / "auth_mixin.dart"
path.write_text(code, encoding="utf-8")
result = extract_dart(path)
mixin_node = next((n for n in result["nodes"] if n["label"] == "AuthMixin"), None)
self.assertIsNotNone(mixin_node)
inherits = [
e for e in result["edges"]
if e["source"] == mixin_node["id"] and e["relation"] == "inherits"
]
self.assertEqual([e["target"] for e in inherits], ["basewidget"])
if __name__ == "__main__":
unittest.main()