diff --git a/src/mutator/sites.py b/src/mutator/sites.py index 73161f0..146d683 100644 --- a/src/mutator/sites.py +++ b/src/mutator/sites.py @@ -124,7 +124,7 @@ _CLOJURE_HEAD = { class RawSite: def __init__( - self, line: int, start: int, end: int, original: str, mutant: str, category: str, anchor_line: int = 0 + self, line: int, start: int, end: int, original: str, mutant: str, category: str, anchor_line: int ): self.line = line # The line its statement starts on. LCOV marks only that line of a multi-line statement. @@ -248,10 +248,10 @@ def _is_head(node) -> bool: parent = node.parent if parent is None or parent.type != "list_lit": return False + # The symbol is one of these children, so this loop returns. for child in parent.children: if child.type == "sym_lit": return child.id == node.id - return False def _clojure_skipped(node, data: bytes) -> bool: @@ -268,7 +268,7 @@ def _clojure_skipped(node, data: bytes) -> bool: def _clojure_text(node, data: bytes) -> str: - if node.child_count == 0 or node.type in {"sym_lit", "bool_lit", "num_lit"}: + if node.type in {"sym_lit", "bool_lit", "num_lit"}: return _text(data, node) return "" diff --git a/tests/test_sites.py b/tests/test_sites.py index bae3e62..32ccf32 100644 --- a/tests/test_sites.py +++ b/tests/test_sites.py @@ -29,6 +29,8 @@ def test_clojure_rules_follow_clj_mutate_and_mark_private_defns(tmp_path): assert ("defn/place", "1", "0") in described assert ("defn-/hide", "false", "true") in described assert {site.namespace for site in sites} == {"demo.core"} + plus = [site for site in sites if site.original == "+"] + assert [site.anchor_line for site in plus] == [4] functions = project_functions(source, tmp_path / "src/demo/core.clj", tmp_path) assert form_id("hide", True) == "defn-/hide" assert is_private("clojure", "hide", source, 6, 7) @@ -40,12 +42,25 @@ def test_clojure_ignores_strings_comments_and_quotes(tmp_path): (defn place [] (comment (+ 1 0)) (quote (+ 1 0)) + '(+ 1 0) (str "true + 1")) """ sites = _sites(tmp_path, "src/demo/core.clj", source) assert sites == [] +def test_a_clojure_vector_and_a_capitalized_symbol_are_not_calls(tmp_path): + source = """(defn place [] + [+ 1] + True) +""" + sites = _sites(tmp_path, "src/demo/core.clj", source) + described = {(site.original, site.mutant) for site in sites} + assert ("+", "-") not in described + assert ("True", "False") not in described + assert ("1", "0") in described + + def test_java_rules_follow_mutate4java(tmp_path): source = """package demo; class Board {