enable for more types - byte arrays still use builtin mutator

This commit is contained in:
Antonis Geralis 2022-09-14 13:00:27 +03:00
parent a398134458
commit 5b4c0d0585
2 changed files with 8 additions and 15 deletions

View File

@ -283,7 +283,7 @@ proc sample[T: SomeNumber](x: T; s: var Sampler; r: var Rand; res: var int) =
proc sample[T](x: seq[T]; s: var Sampler; r: var Rand; res: var int) =
sampleAttempt(attempt(s, r, DefaultMutateWeight, res))
when T is PostProcessTypes:
when T isnot ByteSized:
for i in 0..<x.len:
sample(x[i], s, r, res)
@ -294,11 +294,11 @@ proc sample[T: tuple|object](x: T; s: var Sampler; r: var Rand; res: var int) =
when compiles(mutate(x, 0, false, r)):
sampleAttempt(attempt(s, r, DefaultMutateWeight, res))
when compiles(for v in mitems(x): discard):
when typeof(for v in mitems(x): v) is PostProcessTypes:
when typeof(for v in mitems(x): v) isnot ByteSized:
for v in mitems(x):
sample(v, s, r, res)
elif compiles(for k, v in mpairs(x): discard):
when typeof(for k, v in mpairs(x): v) is PostProcessTypes:
when typeof(for k, v in mpairs(x): v) isnot ByteSized:
for k, v in mpairs(x):
sample(v, s, r, res)
else:
@ -314,10 +314,7 @@ proc sample[T](x: ref T; s: var Sampler; r: var Rand; res: var int) =
proc sample[S, T](x: array[S, T]; s: var Sampler; r: var Rand; res: var int) =
when compiles(mutate(x, 0, false, r)):
sampleAttempt(attempt(s, r, DefaultMutateWeight, res))
when T is PostProcessTypes:
for i in low(x)..high(x):
sample(x[i], s, r, res)
else:
when T isnot ByteSized:
for i in low(x)..high(x):
sample(x[i], s, r, res)
@ -369,7 +366,7 @@ proc pick[T: SomeNumber](x: var T; sizeIncreaseHint: int; enforceChanges: bool;
proc pick[T](x: var seq[T]; sizeIncreaseHint: int; enforceChanges: bool; r: var Rand;
res: var int) =
pickMutate(mutate(x, sizeIncreaseHint, enforceChanges, r))
when T is PostProcessTypes:
when T isnot ByteSized:
for i in 0..<x.len:
pick(x[i], sizeIncreaseHint, enforceChanges, r, res)
@ -390,11 +387,11 @@ proc pick[T: object](x: var T; sizeIncreaseHint: int; enforceChanges: bool;
when compiles(mutate(x, sizeIncreaseHint, enforceChanges, r)):
pickMutate(mutate(x, sizeIncreaseHint, enforceChanges, r))
when compiles(for v in mitems(x): discard):
when typeof(for v in mitems(x): v) is PostProcessTypes:
when typeof(for v in mitems(x): v) isnot ByteSized:
for v in mitems(x):
pick(v, sizeIncreaseHint, enforceChanges, r, res)
elif compiles(for k, v in mpairs(x): discard):
when typeof(for k, v in mpairs(x): v) is PostProcessTypes:
when typeof(for k, v in mpairs(x): v) isnot ByteSized:
for k, v in mpairs(x):
sample(v, sizeIncreaseHint, enforceChanges, r, res)
else:
@ -413,10 +410,7 @@ proc pick[S, T](x: var array[S, T]; sizeIncreaseHint: int; enforceChanges: bool;
r: var Rand; res: var int) =
when compiles(mutate(x, sizeIncreaseHint, enforceChanges, r)):
pickMutate(mutate(x, sizeIncreaseHint, enforceChanges, r))
when T is PostProcessTypes:
for i in low(x)..high(x):
pick(x[i], sizeIncreaseHint, enforceChanges, r, res)
else:
when T isnot ByteSized:
for i in low(x)..high(x):
pick(x[i], sizeIncreaseHint, enforceChanges, r, res)

View File

@ -1,4 +1,3 @@
# Good seed to try out: -seed=4013847822
when defined(runFuzzTests):
const
MaxNodes = 8 # User defined, statically limits number of nodes.