From 9e3cf8ebb9fb8d8fba112905cc9ce627b5332a7c Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Thu, 19 Mar 2026 09:34:07 +0000 Subject: [PATCH] py: normal-assign --- .../normal-assign/df4f33c273ca.mutation.json | 36 +++++++++++++++++++ corpus/python/normal-assign/df4f33c273ca.py | 1 + .../normal-assign/f073760316ef.mutation.json | 36 +++++++++++++++++++ corpus/python/normal-assign/f073760316ef.py | 1 + crates/bough-core/src/language/python.rs | 15 ++++++-- 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 corpus/python/normal-assign/df4f33c273ca.mutation.json create mode 100644 corpus/python/normal-assign/df4f33c273ca.py create mode 100644 corpus/python/normal-assign/f073760316ef.mutation.json create mode 100644 corpus/python/normal-assign/f073760316ef.py diff --git a/corpus/python/normal-assign/df4f33c273ca.mutation.json b/corpus/python/normal-assign/df4f33c273ca.mutation.json new file mode 100644 index 00000000..8002a508 --- /dev/null +++ b/corpus/python/normal-assign/df4f33c273ca.mutation.json @@ -0,0 +1,36 @@ +{ + "mutant": { + "lang": "py", + "twig": [ + "src/a.py" + ], + "kind": { + "Assign": "NormalAssign" + }, + "subst_span": { + "start": { + "line": 0, + "col": 2, + "byte": 2 + }, + "end": { + "line": 0, + "col": 3, + "byte": 3 + } + }, + "effect_span": { + "start": { + "line": 0, + "col": 0, + "byte": 0 + }, + "end": { + "line": 0, + "col": 5, + "byte": 5 + } + } + }, + "subst": "-=" +} \ No newline at end of file diff --git a/corpus/python/normal-assign/df4f33c273ca.py b/corpus/python/normal-assign/df4f33c273ca.py new file mode 100644 index 00000000..18cabc08 --- /dev/null +++ b/corpus/python/normal-assign/df4f33c273ca.py @@ -0,0 +1 @@ +x -= 1 diff --git a/corpus/python/normal-assign/f073760316ef.mutation.json b/corpus/python/normal-assign/f073760316ef.mutation.json new file mode 100644 index 00000000..aef46c94 --- /dev/null +++ b/corpus/python/normal-assign/f073760316ef.mutation.json @@ -0,0 +1,36 @@ +{ + "mutant": { + "lang": "py", + "twig": [ + "src/a.py" + ], + "kind": { + "Assign": "NormalAssign" + }, + "subst_span": { + "start": { + "line": 0, + "col": 2, + "byte": 2 + }, + "end": { + "line": 0, + "col": 3, + "byte": 3 + } + }, + "effect_span": { + "start": { + "line": 0, + "col": 0, + "byte": 0 + }, + "end": { + "line": 0, + "col": 5, + "byte": 5 + } + } + }, + "subst": "+=" +} \ No newline at end of file diff --git a/corpus/python/normal-assign/f073760316ef.py b/corpus/python/normal-assign/f073760316ef.py new file mode 100644 index 00000000..9feca8b7 --- /dev/null +++ b/corpus/python/normal-assign/f073760316ef.py @@ -0,0 +1 @@ +x += 1 diff --git a/crates/bough-core/src/language/python.rs b/crates/bough-core/src/language/python.rs index 3b4ab66e..902b8a7b 100644 --- a/crates/bough-core/src/language/python.rs +++ b/crates/bough-core/src/language/python.rs @@ -1,5 +1,5 @@ use super::LanguageDriver; -use crate::mutant::{BinaryOpMutationKind, MutantKind, Span, span_from_node}; +use crate::mutant::{AssignMutationKind, BinaryOpMutationKind, MutantKind, Span, span_from_node}; use tracing::trace; pub(crate) struct PythonDriver; @@ -53,6 +53,16 @@ impl LanguageDriver for PythonDriver { }; Some((MutantKind::BinaryOp(kind), span_from_node(&op_node), span_from_node(node))) } + "assignment" => { + let op_node = (0..node.child_count()) + .filter_map(|i| node.child(i as u32)) + .find(|c| c.kind() == "=")?; + Some(( + MutantKind::Assign(AssignMutationKind::NormalAssign), + span_from_node(&op_node), + span_from_node(node), + )) + } "boolean_operator" => { let op_node = node.child_by_field_name("operator")?; let op_text = op_node.utf8_text(file_content).ok()?; @@ -97,6 +107,7 @@ impl LanguageDriver for PythonDriver { MutantKind::BinaryOp(BinaryOpMutationKind::IsNot) => vec!["is".into()], MutantKind::BinaryOp(BinaryOpMutationKind::In) => vec!["not in".into()], MutantKind::BinaryOp(BinaryOpMutationKind::NotIn) => vec!["in".into()], + MutantKind::Assign(AssignMutationKind::NormalAssign) => vec!["+=".into(), "-=".into()], _ => vec![], } } @@ -134,6 +145,6 @@ mod tests { #[test] #[ignore] fn debug_tree() { - dump_tree("a = 1\nb = 2\nc = 3\nx = a < b < c"); + dump_tree("x = 1"); } } -- knotmirror 0.0.1