Commit 3e9ed273 authored by Chris Kastorff's avatar Chris Kastorff Committed by Josh Bleecher Snyder

testing/quick: support generation of array types in Value

Generating array types like [4]int would fail even though the int type
is generatable. Allow generating values of array types when the inner
type is generatable.

Change-Id: I7d71b3c18edb3737e2fec1ddf5e36c9dc8401971
Reviewed-on: https://go-review.googlesource.com/3865Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 22f33765
......@@ -118,6 +118,14 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) {
}
v.Index(i).Set(elem)
}
case reflect.Array:
for i := 0; i < v.Len(); i++ {
elem, ok := Value(concrete.Elem(), rand)
if !ok {
return reflect.Value{}, false
}
v.Index(i).Set(elem)
}
case reflect.String:
numChars := rand.Intn(complexSize)
codePoints := make([]rune, numChars)
......
......@@ -144,6 +144,12 @@ type TestIntptrAlias *int
func fIntptrAlias(a TestIntptrAlias) TestIntptrAlias { return a }
func fArray(a [4]byte) [4]byte { return a }
type TestArrayAlias [4]byte
func fArrayAlias(a TestArrayAlias) TestArrayAlias { return a }
func reportError(property string, err error, t *testing.T) {
if err != nil {
t.Errorf("%s: %s", property, err)
......@@ -195,6 +201,8 @@ func TestCheckEqual(t *testing.T) {
reportError("fUintptrAlias", CheckEqual(fUintptrAlias, fUintptrAlias, nil), t)
reportError("fIntptr", CheckEqual(fIntptr, fIntptr, nil), t)
reportError("fIntptrAlias", CheckEqual(fIntptrAlias, fIntptrAlias, nil), t)
reportError("fArray", CheckEqual(fArray, fArray, nil), t)
reportError("fArrayAlais", CheckEqual(fArrayAlias, fArrayAlias, nil), t)
}
// This tests that ArbitraryValue is working by checking that all the arbitrary
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment