// Generate implements testing/quick.Generator.
Generate implements testing/quick.Generator.
// Generate implements testing / quick . Generator .
func (jsonValue) Generate(rand *rand.Rand, size int) reflect.Value {
	whitespace := func() string {
		if rand.Intn(2) == 0 {
			return ""
		}
		ws := make([]byte, 1+rand.Intn(3))
		for i := 0; i < len(ws); i++ {
			switch rand.Intn(3) {
			case 0:
				ws[i] = ' '
			case 1:
				ws[i] = '\t'
			default:
				if i+1 < len(ws) {
					ws[i] = '\r'
					ws[i+1] = '\n'
					i++
				} else {
					ws[i] = '\n'
				}
			}
		}
		return string(ws)
	}
	var genRecursively func(int) string
	genRecursively = func(typ int) string {
		switch typ {
		case 0:
			return whitespace() + "null" + whitespace()
		case 1:
			return whitespace() + "true" + whitespace()
		case 2:
			return whitespace() + "false" + whitespace()
		case 3:
			return whitespace() + fmt.Sprintf("%f", rand.Float64()) + whitespace()
		case 4:
			size := rand.Intn(8)
			qs := make([]byte, size)
			for i := 0; i < size; i++ {
				qs[i] = 'a' + byte(rand.Intn('z'-'a'+1))
			}
			return whitespace() + fmt.Sprintf("%q", qs) + whitespace()
		case 5:
			arr := bytes.NewBufferString(whitespace() + "[")
			for sz := rand.Intn(4); sz > 0; sz-- {
				arr.WriteString(genRecursively(rand.Intn(7)))
				if sz > 1 {
					arr.WriteString(",")
				}
			}
			arr.WriteString("]")
			arr.WriteString(whitespace())
			return arr.String()
		default: 
			keys := make(map[string]bool)
			obj := bytes.NewBufferString("{")
			for sz := rand.Intn(4); sz > 0; sz-- {
				key := genRecursively(4)
				for keys[strings.TrimSpace(key)] {
					key = genRecursively(4)
				}
				keys[strings.TrimSpace(key)] = true
				obj.WriteString(key)
				obj.WriteString(":")
				obj.WriteString(genRecursively(rand.Intn(7)))
				if sz > 1 {
					obj.WriteString(",")
				}
			}
			obj.WriteString("}")
			return obj.String()
		}
	}
	return reflect.ValueOf(jsonValue(genRecursively(rand.Intn(7))))
}
func ( jsonValue ) Generate ( rand * rand . Rand , size int ) reflect . Value { whitespace := func ( ) string { if rand . Intn ( 2 ) == 0 { return " " } ws := make ( [ ] byte , 1 + rand . Intn ( 3 ) ) for i := 0 ; i < len ( ws ) ; i ++ { switch rand . Intn ( 3 ) { case 0 : ws [ i ] = ' ' case 1 : ws [ i ] = '\t' default : if i + 1 < len ( ws ) { ws [ i ] = '\r' ws [ i + 1 ] = '\n' i ++ } else { ws [ i ] = '\n' } } } return string ( ws ) } var genRecursively func ( int ) string genRecursively = func ( typ int ) string { switch typ { case 0 : return whitespace ( ) + " " + whitespace ( ) case 1 : return whitespace ( ) + " " + whitespace ( ) case 2 : return whitespace ( ) + " " + whitespace ( ) case 3 : return whitespace ( ) + fmt . Sprintf ( " " , rand . Float64 ( ) ) + whitespace ( ) case 4 : size := rand . Intn ( 8 ) qs := make ( [ ] byte , size ) for i := 0 ; i < size ; i ++ { qs [ i ] = 'a' + byte ( rand . Intn ( 'z' - 'a' + 1 ) ) } return whitespace ( ) + fmt . Sprintf ( " " , qs ) + whitespace ( ) case 5 : arr := bytes . NewBufferString ( whitespace ( ) + " " ) for sz := rand . Intn ( 4 ) ; sz > 0 ; sz -- { arr . WriteString ( genRecursively ( rand . Intn ( 7 ) ) ) if sz > 1 { arr . WriteString ( " " ) } } arr . WriteString ( " " ) arr . WriteString ( whitespace ( ) ) return arr . String ( ) default : keys := make ( map [ string ] bool ) obj := bytes . NewBufferString ( " " ) for sz := rand . Intn ( 4 ) ; sz > 0 ; sz -- { key := genRecursively ( 4 ) for keys [ strings . TrimSpace ( key ) ] { key = genRecursively ( 4 ) } keys [ strings . TrimSpace ( key ) ] = true obj . WriteString ( key ) obj . WriteString ( " " ) obj . WriteString ( genRecursively ( rand . Intn ( 7 ) ) ) if sz > 1 { obj . WriteString ( " " ) } } obj . WriteString ( " " ) return obj . String ( ) } } return reflect . ValueOf ( jsonValue ( genRecursively ( rand . Intn ( 7 ) ) ) ) }
Generate implements testing/quick.Generator.
Generate implements testing / quick . Generator .
// Half the times this is called, return no whitespace. // Half the times, between 1 and 4 bytes of whitespace. // A quoted string consisting of at most 8 bytes, and only characters // in the class [a-z]. // At most 4 values in the array, of random types. /*6*/ // At most 4 key-value pairs. // Keys are randomly-generated quoted strings. // Values are recursively generated, of random type.