Fix diff parser generation for empty files

This commit is contained in:
Dave Halter
2019-01-13 23:38:35 +01:00
parent 55247a5a2c
commit 76c5754b76

View File

@@ -99,11 +99,12 @@ class FileModification:
lines = list(lines)
for _ in range(change_count):
if not lines:
break
rand = random.randint(1, 4)
if rand == 1:
if len(lines) == 1:
# We cannot delete every line, that doesn't make sense to
# fuzz and it would be annoying to rewrite everything here.
continue
l = LineDeletion(random_line())
elif rand == 2:
# Copy / Insertion
@@ -127,6 +128,7 @@ class FileModification:
# fuzzer is just way more effective here.
random_string += random.choice(_random_python_fragments)
l = LineReplacement(line_nr, line[:column] + random_string + line[column:])
l.apply(lines)
yield l
def __init__(self, modification_list):