Add regression tests for OCaml and chained modules and classes
Covers both repaired chains directly: a module and a class pair
each keep both of their own members, nothing from the second
dropped. A control confirms a lone module or class with no chain
still resolves to its own name and line.
(cherry picked from commit ddf32c80e4)
This commit is contained in:
1 parent
754bbb6da5
commit
572fc7e889
1 file changed
+54
@@ -234,3 +234,57 @@ def test_interface_extracts_class_signatures(tmp_path):
|
||||
assert ("counter", "count") in contains
|
||||
# a signature has no expression body -> no calls
|
||||
assert not [e for e in r["edges"] if e["relation"] == "calls"]
|
||||
|
||||
|
||||
AND_CHAINED_MODULES = """\
|
||||
module Alpha = struct
|
||||
let f x = x
|
||||
end
|
||||
and Beta = struct
|
||||
let g x = x
|
||||
end
|
||||
"""
|
||||
|
||||
|
||||
def test_and_chained_modules_are_not_dropped(tmp_path):
|
||||
"""`module A = ... and B = ...` nests every binding under ONE
|
||||
module_definition node; taking only the first silently dropped every
|
||||
module after it, along with everything defined inside it."""
|
||||
r = extract_ocaml(_write(tmp_path, "pair.ml", AND_CHAINED_MODULES))
|
||||
assert "error" not in r
|
||||
assert {"Alpha", "f", "Beta", "g"} <= _labels(r)
|
||||
defines = _rel_pairs(r, "defines")
|
||||
assert {("pair.ml", "Alpha"), ("pair.ml", "Beta")} <= defines
|
||||
contains = _rel_pairs(r, "contains")
|
||||
assert {("Alpha", "f"), ("Beta", "g")} <= contains
|
||||
|
||||
|
||||
AND_CHAINED_CLASSES = """\
|
||||
class alpha = object
|
||||
method m = 1
|
||||
end
|
||||
and beta = object
|
||||
method n = 2
|
||||
end
|
||||
"""
|
||||
|
||||
|
||||
def test_and_chained_classes_are_not_dropped(tmp_path):
|
||||
"""`class a = ... and b = ...` (mutually recursive classes) nests every
|
||||
binding under ONE class_definition node the same way modules do; taking
|
||||
only the first silently dropped every class after it."""
|
||||
r = extract_ocaml(_write(tmp_path, "pair.ml", AND_CHAINED_CLASSES))
|
||||
assert "error" not in r
|
||||
assert {"alpha", "m", "beta", "n"} <= _labels(r)
|
||||
method = _rel_pairs(r, "method")
|
||||
assert {("alpha", "m"), ("beta", "n")} <= method
|
||||
|
||||
|
||||
def test_single_module_and_class_are_unaffected(tmp_path):
|
||||
"""Control: a lone module/class (no `and` chain) must still resolve to
|
||||
its own name and line, not the file's or each other's."""
|
||||
r = extract_ocaml(_write(tmp_path, "solo.ml", "module Solo = struct\n let v = 1\nend\n"))
|
||||
assert "error" not in r
|
||||
assert {"Solo", "v"} <= _labels(r)
|
||||
node = next(n for n in r["nodes"] if n["label"] == "Solo")
|
||||
assert node["source_location"] == "L1"
|
||||
Reference in new issue
Block a user