mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-15 08:57:11 +08:00
Fix diff parser generation for empty files
This commit is contained in:
@@ -99,11 +99,12 @@ class FileModification:
|
|||||||
|
|
||||||
lines = list(lines)
|
lines = list(lines)
|
||||||
for _ in range(change_count):
|
for _ in range(change_count):
|
||||||
if not lines:
|
|
||||||
break
|
|
||||||
|
|
||||||
rand = random.randint(1, 4)
|
rand = random.randint(1, 4)
|
||||||
if rand == 1:
|
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())
|
l = LineDeletion(random_line())
|
||||||
elif rand == 2:
|
elif rand == 2:
|
||||||
# Copy / Insertion
|
# Copy / Insertion
|
||||||
@@ -127,6 +128,7 @@ class FileModification:
|
|||||||
# fuzzer is just way more effective here.
|
# fuzzer is just way more effective here.
|
||||||
random_string += random.choice(_random_python_fragments)
|
random_string += random.choice(_random_python_fragments)
|
||||||
l = LineReplacement(line_nr, line[:column] + random_string + line[column:])
|
l = LineReplacement(line_nr, line[:column] + random_string + line[column:])
|
||||||
|
l.apply(lines)
|
||||||
yield l
|
yield l
|
||||||
|
|
||||||
def __init__(self, modification_list):
|
def __init__(self, modification_list):
|
||||||
|
|||||||
Reference in New Issue
Block a user