Answer stability round 1: 1 🔴, 0 🟡 (1 misread); mutated matches Gremlins' lines that keep their CR as well as mutmut's, and the last line of a mutant that ends the file takes no line end; the prose findings' rewording is in this commit
This commit is contained in:
@@ -23,16 +23,19 @@ class Mutant(typing.NamedTuple):
|
||||
def mutated(source: bytes, mutant: Mutant) -> bytes | None:
|
||||
"""A file's source with the mutant applied, or None where the lines the mutant changes don't stand at the mutant's line.
|
||||
|
||||
The mutant's lines come from a file read as text, so they hold no `\\r`: they match a file's lines without theirs, and go in with
|
||||
the line end the file's first line has."""
|
||||
A mutant's lines hold no `\\r` where its tool read the file as text, as mutmut does, and hold it where the tool split the bytes on
|
||||
`\\n`, as Gremlins' planter does. Both match a file's lines, and a new line without `\\r` gets the line end of the file's first line."""
|
||||
lines = source.split(b"\n")
|
||||
first = mutant.line - 1
|
||||
end = first + len(mutant.was)
|
||||
if not 0 <= first <= len(lines) or tuple(line.removesuffix(b"\r") for line in lines[first:end]) != mutant.was:
|
||||
if not 0 <= first <= len(lines) or tuple(line.removesuffix(b"\r") for line in lines[first:end]) != tuple(line.removesuffix(b"\r") for line in mutant.was):
|
||||
return None
|
||||
# The file's last line has no line end, so none of its lines takes one.
|
||||
line_end = b"\r" if lines[0].endswith(b"\r") and end < len(lines) else b""
|
||||
lines[first:end] = (line + line_end for line in mutant.now)
|
||||
line_end = b"\r" if lines[0].endswith(b"\r") else b""
|
||||
new = [line if line.endswith(b"\r") else line + line_end for line in mutant.now]
|
||||
# Where the mutant's lines end the file, the last of them has no line end.
|
||||
if new and end >= len(lines):
|
||||
new[-1] = mutant.now[-1]
|
||||
lines[first:end] = new
|
||||
return b"\n".join(lines)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user