profile
viewpoint
Kwongtai kwongtailau @Tencent Guangzhou,China http://blog.csdn.net/weixin_36394852 Graduated from GDUT, now work in Tencent.

kwongtailau/Skill-Tree 5

🐼 准备秋招,欢迎来树上取果实

kwongtailau/Interview-Notebook 4

:books: 技术面试需要掌握的基础知识整理

kwongtailau/Job-Recommend 1

🔎 互联网内推信息

kwongtailau/Translator 1

A slight translator created by C++Qt

kwongtailau/beego 0

beego is an open-source, high-performance web framework for the Go programming language.

kwongtailau/build-web-application-with-golang 0

A golang ebook intro how to build a web with golang

kwongtailau/CSharp 0

A repository for my jobs using CSharp

kwongtailau/go-mutesting 0

Mutation testing for Go source code

kwongtailau/gofuzz 0

Fuzz testing for go.

kwongtailau/interview 0

📚 C/C++面试基础知识总结

starteddouyu/jupiter

started time in 5 days

startedghodss/yaml

started time in 15 days

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 type int63nPicker interface { 	Int63n(int64) int64 } -type charRange struct {-	first, last rune+// UnicodeRange describes a sequential range of unicode characters.+// Last must be numerically greater than First.+type UnicodeRange struct {+	First, Last rune } +// UnicodeRanges describes an arbitrary number of sequential ranges of unicode characters.+// To be useful, each range must have at least one character (First <= Last) and+// there must be at least one range.+type UnicodeRanges []UnicodeRange+ // choose returns a random unicode character from the given range, using the // given randomness source.-func (cr charRange) choose(r int63nPicker) rune {-	count := int64(cr.last - cr.first + 1)-	return cr.first + rune(r.Int63n(count))+func (ur UnicodeRange) choose(r int63nPicker) rune {+	count := int64(ur.Last - ur.First + 1)+	return ur.First + rune(r.Int63n(count))+}++// CustomStringFuzzFunc constructs a FuzzFunc which produces random strings.+// Each character is selected from the range ur. If there are no characters+// in the range (cr.Last < cr.First), this will panic.+func (ur UnicodeRange) CustomStringFuzzFunc() func(s *string, c Continue) {+	return func(s *string, c Continue) {+		ur.check()+		*s = ur.randString(c.Rand)+	}+}++// check is a function that used to check whether the first of ur(UnicodeRange)+// is greater than the last one.+func (ur UnicodeRange) check() {+	if ur.Last < ur.First {+		panic("last encoding must be greater than the first one.")+	}+}++// randString of UnicodeRange makes a random string up to 20 characters long.+// Each character is selected form ur(UnicodeRange).+func (ur UnicodeRange) randString(r *rand.Rand) string {+	n := r.Intn(20)+	sb := strings.Builder{}+	sb.Grow(n)+	for i := 0; i < n; i++ {+		sb.WriteRune(ur.choose(r))+	}+	return sb.String() } -var unicodeRanges = []charRange{+// defaultUnicodeRanges sets a default unicode range when user do not set+// CustomStringFuzzFunc() but wants fuzz string.+var defaultUnicodeRanges = UnicodeRanges{ 	{' ', '~'},           // ASCII characters 	{'\u00a0', '\u02af'}, // Multi-byte encoded characters 	{'\u4e00', '\u9fff'}, // Common CJK (even longer encodings) } -// randString makes a random string up to 20 characters long. The returned string-// may include a variety of (valid) UTF-8 encodings.-func randString(r *rand.Rand) string {+// CustomStringFuzzFunc constructs a FuzzFunc which produces random strings.+// Each character is selected from one of the ranges of ur(UnicodeRanges).+// Each range has an equal probability of being chosen. If there are no ranges,+// or a selected range has no characters (.Last < .First), this will panic.+func (ur UnicodeRanges) CustomStringFuzzFunc() func(s *string, c Continue) {+	return func(s *string, c Continue) {+		// Check unicode ranges slice is empty.+		if len(ur) == 0 {+			panic("Unicode ranges is empty.")+		}+		// if not empty, each range should be checked.+		for i := range ur {

You are so nice! ^ - ^

It is my first time to see the usage of Must function. I learned it ! Yes, I agree with you. Using Must function is more machinery. But in this test library, we need to add public Must function. The programer call Must function, they should call the package fuzz first, and the check function should be open as public function, so that they call will like this:

unicodeRange := fuzz.UnicodeRange{ 'a', 'z'}
fuzz.Must(unicodeRange.Check())
// ...

The usage of UnicodeRange will be complicated.

I have moved the check function outside the inner function. Please @lavalamp review again, thanks~

kwongtailau

comment created time in a month

push eventkwongtailau/gofuzz

kwongtailau

commit sha aa63c133c254f08f18302572dd506431fe6b7127

fix: move the check function outside of the inner function

view details

push time in a month

startedspf13/cobra

started time in a month

startedthx/rap2-delos

started time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 type int63nPicker interface { 	Int63n(int64) int64 } -type charRange struct {-	first, last rune+// UnicodeRange describes a sequential range of unicode characters.+// Last must be numerically greater than First.+type UnicodeRange struct {+	First, Last rune } +// UnicodeRanges describes an arbitrary number of sequential ranges of unicode characters.+// To be useful, each range must have at least one character (First <= Last) and+// there must be at least one range.+type UnicodeRanges []UnicodeRange+ // choose returns a random unicode character from the given range, using the // given randomness source.-func (cr charRange) choose(r int63nPicker) rune {-	count := int64(cr.last - cr.first + 1)-	return cr.first + rune(r.Int63n(count))+func (ur UnicodeRange) choose(r int63nPicker) rune {+	count := int64(ur.Last - ur.First + 1)+	return ur.First + rune(r.Int63n(count))+}++// CustomStringFuzzFunc constructs a FuzzFunc which produces random strings.+// Each character is selected from the range ur. If there are no characters+// in the range (cr.Last < cr.First), this will panic.+func (ur UnicodeRange) CustomStringFuzzFunc() func(s *string, c Continue) {+	return func(s *string, c Continue) {+		ur.check()+		*s = ur.randString(c.Rand)+	}+}++// check is a function that used to check whether the first of ur(UnicodeRange)+// is greater than the last one.+func (ur UnicodeRange) check() {+	if ur.Last < ur.First {+		panic("last encoding must be greater than the first one.")+	}+}++// randString of UnicodeRange makes a random string up to 20 characters long.+// Each character is selected form ur(UnicodeRange).+func (ur UnicodeRange) randString(r *rand.Rand) string {+	n := r.Intn(20)+	sb := strings.Builder{}+	sb.Grow(n)+	for i := 0; i < n; i++ {+		sb.WriteRune(ur.choose(r))+	}+	return sb.String() } -var unicodeRanges = []charRange{+// defaultUnicodeRanges sets a default unicode range when user do not set+// CustomStringFuzzFunc() but wants fuzz string.+var defaultUnicodeRanges = UnicodeRanges{ 	{' ', '~'},           // ASCII characters 	{'\u00a0', '\u02af'}, // Multi-byte encoded characters 	{'\u4e00', '\u9fff'}, // Common CJK (even longer encodings) } -// randString makes a random string up to 20 characters long. The returned string-// may include a variety of (valid) UTF-8 encodings.-func randString(r *rand.Rand) string {+// CustomStringFuzzFunc constructs a FuzzFunc which produces random strings.+// Each character is selected from one of the ranges of ur(UnicodeRanges).+// Each range has an equal probability of being chosen. If there are no ranges,+// or a selected range has no characters (.Last < .First), this will panic.

After solving the constructor problem above, I will add this comment. ^-^

kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 type int63nPicker interface { 	Int63n(int64) int64 } -type charRange struct {-	first, last rune+// UnicodeRange describes a sequential range of unicode characters.+// Last must be numerically greater than First.+type UnicodeRange struct {+	First, Last rune } +// UnicodeRanges describes an arbitrary number of sequential ranges of unicode characters.+// To be useful, each range must have at least one character (First <= Last) and+// there must be at least one range.+type UnicodeRanges []UnicodeRange+ // choose returns a random unicode character from the given range, using the // given randomness source.-func (cr charRange) choose(r int63nPicker) rune {-	count := int64(cr.last - cr.first + 1)-	return cr.first + rune(r.Int63n(count))+func (ur UnicodeRange) choose(r int63nPicker) rune {+	count := int64(ur.Last - ur.First + 1)+	return ur.First + rune(r.Int63n(count))+}++// CustomStringFuzzFunc constructs a FuzzFunc which produces random strings.+// Each character is selected from the range ur. If there are no characters+// in the range (cr.Last < cr.First), this will panic.+func (ur UnicodeRange) CustomStringFuzzFunc() func(s *string, c Continue) {+	return func(s *string, c Continue) {+		ur.check()+		*s = ur.randString(c.Rand)+	}+}++// check is a function that used to check whether the first of ur(UnicodeRange)+// is greater than the last one.+func (ur UnicodeRange) check() {+	if ur.Last < ur.First {+		panic("last encoding must be greater than the first one.")+	}+}++// randString of UnicodeRange makes a random string up to 20 characters long.+// Each character is selected form ur(UnicodeRange).+func (ur UnicodeRange) randString(r *rand.Rand) string {+	n := r.Intn(20)+	sb := strings.Builder{}+	sb.Grow(n)+	for i := 0; i < n; i++ {+		sb.WriteRune(ur.choose(r))+	}+	return sb.String() } -var unicodeRanges = []charRange{+// defaultUnicodeRanges sets a default unicode range when user do not set+// CustomStringFuzzFunc() but wants fuzz string.+var defaultUnicodeRanges = UnicodeRanges{ 	{' ', '~'},           // ASCII characters 	{'\u00a0', '\u02af'}, // Multi-byte encoded characters 	{'\u4e00', '\u9fff'}, // Common CJK (even longer encodings) } -// randString makes a random string up to 20 characters long. The returned string-// may include a variety of (valid) UTF-8 encodings.-func randString(r *rand.Rand) string {+// CustomStringFuzzFunc constructs a FuzzFunc which produces random strings.+// Each character is selected from one of the ranges of ur(UnicodeRanges).+// Each range has an equal probability of being chosen. If there are no ranges,+// or a selected range has no characters (.Last < .First), this will panic.+func (ur UnicodeRanges) CustomStringFuzzFunc() func(s *string, c Continue) {+	return func(s *string, c Continue) {+		// Check unicode ranges slice is empty.+		if len(ur) == 0 {+			panic("Unicode ranges is empty.")+		}+		// if not empty, each range should be checked.+		for i := range ur {

If the constructor of UnicodeRange is added, what bothers me is, what should the constructor of UnicodeRange look like?

emmmm...

I thought of two methods. One is: Constructor NewUnicodeRanges just return a pointer of UnicodeRanges, which is empty slice. Then supply function Add of UnicodeRanges to add UnicodeRange into slice. But this method requires the programmer to first call NewUnicodeRange to get a pointer of UnicodeRange

type UnicodeRanges []UnicodeRange
func (ur UnicodeRanges) Add(unicodeRange *UnicodeRange) error {
	if unicodeRange.last < unicodeRange.first {
		return fmt.Errorf("Unicode range: %v must be greater than %v", unicodeRange.Last, unicodeRange.First)
	}
	
	ur = append(ur, *unicodeRange)
	return nil 
}

Another is: The constructor of NewUnicodeRanges provides multi-parameter input of UnicodeRange, each UnicodeRange will be checked. If the conditions are not met, an error will be returned immediately. If met, the UnicodeRange will be added into UnicodeRanges, finally return the pointer of UnicodeRanges. The first and last must be public variables

func NewUnicodeRanges(unicodeRanges ...UnicodeRange) (*UnicodeRanges, error) {
	if len(unicodeRanges) == 0 {
		return nil, fmt.Errorf("Unicode ranges is empty.")
	}

	ur := make(UnicodeRanges, 0, len(unicodeRanges))
	for i := range unicodeRanges {
		if unicodeRanges[i].Last < unicodeRanges[i].First {
			return nil, fmt.Errorf("Range: %v is bigger than %v",
				unicodeRanges[i].First, unicodeRanges[i].Last)
		}
		ur[i] = unicodeRanges[i]
	}

	return &ur, nil
}
kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 type int63nPicker interface { 	Int63n(int64) int64 } -type charRange struct {-	first, last rune+// UnicodeRange describes a sequential range of unicode characters.+// Last must be numerically greater than First.+type UnicodeRange struct {+	First, Last rune } +// UnicodeRanges describes an arbitrary number of sequential ranges of unicode characters.+// To be useful, each range must have at least one character (First <= Last) and+// there must be at least one range.+type UnicodeRanges []UnicodeRange+ // choose returns a random unicode character from the given range, using the // given randomness source.-func (cr charRange) choose(r int63nPicker) rune {-	count := int64(cr.last - cr.first + 1)-	return cr.first + rune(r.Int63n(count))+func (ur UnicodeRange) choose(r int63nPicker) rune {+	count := int64(ur.Last - ur.First + 1)+	return ur.First + rune(r.Int63n(count))+}++// CustomStringFuzzFunc constructs a FuzzFunc which produces random strings.+// Each character is selected from the range ur. If there are no characters+// in the range (cr.Last < cr.First), this will panic.+func (ur UnicodeRange) CustomStringFuzzFunc() func(s *string, c Continue) {+	return func(s *string, c Continue) {+		ur.check()+		*s = ur.randString(c.Rand)+	}+}++// check is a function that used to check whether the first of ur(UnicodeRange)+// is greater than the last one.+func (ur UnicodeRange) check() {+	if ur.Last < ur.First {+		panic("last encoding must be greater than the first one.")+	}+}++// randString of UnicodeRange makes a random string up to 20 characters long.+// Each character is selected form ur(UnicodeRange).+func (ur UnicodeRange) randString(r *rand.Rand) string {+	n := r.Intn(20)+	sb := strings.Builder{}+	sb.Grow(n)+	for i := 0; i < n; i++ {+		sb.WriteRune(ur.choose(r))+	}+	return sb.String() } -var unicodeRanges = []charRange{+// defaultUnicodeRanges sets a default unicode range when user do not set+// CustomStringFuzzFunc() but wants fuzz string.+var defaultUnicodeRanges = UnicodeRanges{ 	{' ', '~'},           // ASCII characters 	{'\u00a0', '\u02af'}, // Multi-byte encoded characters 	{'\u4e00', '\u9fff'}, // Common CJK (even longer encodings) } -// randString makes a random string up to 20 characters long. The returned string-// may include a variety of (valid) UTF-8 encodings.-func randString(r *rand.Rand) string {+// CustomStringFuzzFunc constructs a FuzzFunc which produces random strings.+// Each character is selected from one of the ranges of ur(UnicodeRanges).+// Each range has an equal probability of being chosen. If there are no ranges,+// or a selected range has no characters (.Last < .First), this will panic.+func (ur UnicodeRanges) CustomStringFuzzFunc() func(s *string, c Continue) {+	return func(s *string, c Continue) {+		// Check unicode ranges slice is empty.+		if len(ur) == 0 {+			panic("Unicode ranges is empty.")+		}+		// if not empty, each range should be checked.+		for i := range ur {

I agree with what you said above. But I don't understand the use of the Must function here.

Does it mean that adding Must function in UnicodeRanges or Must function in UnicodeRange?

In Earlier time when I make this PR, I thought about making the First and Last of UnicodeRange as private variables.Then provide the constructor NewUnicodeRange to return a pointer of UnicodeRange. For Example:

type UnicodeRange struct {
	first, last rune
}

func NewUnicodeRange(first, last rune) (*UnicodeRange, error) {
	if last < first {
		return nil, fmt.Errorf("last encoding must be greater than the first one.")
	}

	ur := &UnicodeRange{
		first: first,
		last:  last,
	}
	return ur, nil
}

Do you have any suggestion about this constructor?

kwongtailau

comment created time in a month

pull request commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

Thank you for giving me a lot of suggestions patiently, which is very helpful to me.

As a student who has just graduated from school for just one year. I learned a lot in this PR. ^-^

kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 var myMap map[ComplexKeyType]string f.Fuzz(&myMap) // myMap will have exactly one element. ``` +Customize a string within one encoding range([Unicode](https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane)). 

I think of what you said before, it is too early to introduce this custom fuzz function concept.

At the same time, I also found that on line 67 of the README, it is not easy to add an introduction of generating a string in the custom encoding range, so delete it here.

Give back the choice to the developer, who can find related usage in the example_test.go.

kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 func ExampleEnum() { 	} 	// Output: }++func ExampleCustomString() {+	a2z := "abcdefghijklmnopqrstuvwxyz"+	a2z0to9 := "abcdefghijklmnopqrstuvwxyz0123456789"++	// example for generating custom string within one unicode range.+	var A string+	unicodeRange := fuzz.UnicodeRange{'a', 'z'}++	f := fuzz.New().Funcs(unicodeRange.CustomStringFuzzFunc())+	f.Fuzz(&A)++	for i := range A {+		if !strings.ContainsRune(a2z, rune(A[i])) {+			fmt.Printf("A[%d]: %v is not in range of a-z.\n", i, A[i])+		}+	}+	fmt.Println("Got a string, each character is selected from  a-z.")++	// example for generating custom string within multiple unicode range.+	var B string+	unicodeRanges := fuzz.UnicodeRanges{+		{'a', 'z'},+		{0x0030, 0x0039}, // 0 is 0x0030, 9 is 0x0039

Sorry about for this...

Previously, I considered that a-z has been used above, and the following can use 0x0030-0x0039 to instead of 0-9. I thought this will let developers know that there are two ways to pass in.

I have changed it according your suggestion, and put 0x0030-0x0039 in the comment.

kwongtailau

comment created time in a month

push eventkwongtailau/gofuzz

kwongtailau

commit sha bff41adca5a81d4e3b193fa002c51ffcd64c1a37

Fix: fix the problem or poor readablity of ExampleCustomString. Modify introduction about customizing string.

view details

push time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 type int63nPicker interface { 	Int63n(int64) int64 } -type charRange struct {-	first, last rune+// UnicodeRange is a structure that provides the developer with setting+// one encoding range.+type UnicodeRange struct {+	First, Last rune } +// UnicodeRanges is a slice that provides the developer with setting+// the different range of Unicode+type UnicodeRanges []UnicodeRange+ // choose returns a random unicode character from the given range, using the // given randomness source.-func (cr charRange) choose(r int63nPicker) rune {-	count := int64(cr.last - cr.first + 1)-	return cr.first + rune(r.Int63n(count))+func (cr UnicodeRange) choose(r int63nPicker) rune {+	count := int64(cr.Last - cr.First + 1)+	return cr.First + rune(r.Int63n(count))+}++// CustomStringFuzzFunc constructs a function which randomizes strings+func (cr UnicodeRange) CustomStringFuzzFunc() func(s *string, c Continue) {+	return func(s *string, c Continue) {+		n := c.Intn(20)+		sb := strings.Builder{}+		sb.Grow(n)+		for i := 0; i < n; i++ {+			sb.WriteRune(cr.choose(c.Rand))+		}+		*s = sb.String()+	} } -var unicodeRanges = []charRange{+// defaultUnicodeRanges sets a default unicode range when user do not set+// CustomStringFuzzFunc() but wants fuzz string.+var defaultUnicodeRanges = UnicodeRanges{ 	{' ', '~'},           // ASCII characters 	{'\u00a0', '\u02af'}, // Multi-byte encoded characters 	{'\u4e00', '\u9fff'}, // Common CJK (even longer encodings) } +// CustomStringFuzzFunc constructs a function which randomizes strings+func (r UnicodeRanges) CustomStringFuzzFunc() func(s *string, c Continue) {+	return func(s *string, c Continue) {+		n := c.Intn(20)+		sb := strings.Builder{}+		sb.Grow(n)+		for i := 0; i < n; i++ {+			sb.WriteRune(r[c.Intn(len(r))].choose(c.Rand))+		}+		*s = sb.String()+	}+}+ // randString makes a random string up to 20 characters long. The returned string // may include a variety of (valid) UTF-8 encodings. func randString(r *rand.Rand) string {

Fix I add private function randString of UnicodeRange, which is just for one encoding range. I add private function randString of UnicodeRanges, which is for multiple encoding range.

And the usual function randString just call the function randString of defaultUnicodeRanges.

kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 type int63nPicker interface { 	Int63n(int64) int64 } -type charRange struct {-	first, last rune+// UnicodeRange is a structure that provides the developer with setting+// one encoding range.+type UnicodeRange struct {+	First, Last rune } +// UnicodeRanges is a slice that provides the developer with setting

Fix

kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 type int63nPicker interface { 	Int63n(int64) int64 } -type charRange struct {-	first, last rune+// UnicodeRange is a structure that provides the developer with setting

Fix

kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 type int63nPicker interface { 	Int63n(int64) int64 } -type charRange struct {-	first, last rune+// UnicodeRange is a structure that provides the developer with setting+// one encoding range.+type UnicodeRange struct {+	First, Last rune } +// UnicodeRanges is a slice that provides the developer with setting+// the different range of Unicode+type UnicodeRanges []UnicodeRange+ // choose returns a random unicode character from the given range, using the // given randomness source.-func (cr charRange) choose(r int63nPicker) rune {-	count := int64(cr.last - cr.first + 1)-	return cr.first + rune(r.Int63n(count))+func (cr UnicodeRange) choose(r int63nPicker) rune {+	count := int64(cr.Last - cr.First + 1)+	return cr.First + rune(r.Int63n(count))+}++// CustomStringFuzzFunc constructs a function which randomizes strings

I just write down a private function of UnicodeRange, this will be panic if Lasr < First.

And the logic of UnicodeRanges is to call the check function of each range.

kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 type int63nPicker interface { 	Int63n(int64) int64 } -type charRange struct {-	first, last rune+// UnicodeRange is a structure that provides the developer with setting+// one encoding range.+type UnicodeRange struct {+	First, Last rune } +// UnicodeRanges is a slice that provides the developer with setting+// the different range of Unicode+type UnicodeRanges []UnicodeRange+ // choose returns a random unicode character from the given range, using the // given randomness source.-func (cr charRange) choose(r int63nPicker) rune {-	count := int64(cr.last - cr.first + 1)-	return cr.first + rune(r.Int63n(count))+func (cr UnicodeRange) choose(r int63nPicker) rune {+	count := int64(cr.Last - cr.First + 1)+	return cr.First + rune(r.Int63n(count))+}++// CustomStringFuzzFunc constructs a function which randomizes strings

rewrite

kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 type int63nPicker interface { 	Int63n(int64) int64 } -type charRange struct {-	first, last rune+// UnicodeRange is a structure that provides the developer with setting+// one encoding range.+type UnicodeRange struct {+	First, Last rune } +// UnicodeRanges is a slice that provides the developer with setting+// the different range of Unicode+type UnicodeRanges []UnicodeRange+ // choose returns a random unicode character from the given range, using the // given randomness source.-func (cr charRange) choose(r int63nPicker) rune {-	count := int64(cr.last - cr.first + 1)-	return cr.first + rune(r.Int63n(count))+func (cr UnicodeRange) choose(r int63nPicker) rune {+	count := int64(cr.Last - cr.First + 1)+	return cr.First + rune(r.Int63n(count))+}++// CustomStringFuzzFunc constructs a function which randomizes strings+func (cr UnicodeRange) CustomStringFuzzFunc() func(s *string, c Continue) {+	return func(s *string, c Continue) {+		n := c.Intn(20)+		sb := strings.Builder{}+		sb.Grow(n)+		for i := 0; i < n; i++ {+			sb.WriteRune(cr.choose(c.Rand))+		}+		*s = sb.String()+	} } -var unicodeRanges = []charRange{+// defaultUnicodeRanges sets a default unicode range when user do not set+// CustomStringFuzzFunc() but wants fuzz string.+var defaultUnicodeRanges = UnicodeRanges{ 	{' ', '~'},           // ASCII characters 	{'\u00a0', '\u02af'}, // Multi-byte encoded characters 	{'\u4e00', '\u9fff'}, // Common CJK (even longer encodings) } +// CustomStringFuzzFunc constructs a function which randomizes strings

rewrite

kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 var myInt int f.Fuzz(&myInt) // myInt gets a random value. ``` +If you want to use it on string with different character like Chinese or Number, 

It is a good idea.

I delete this block from README, finally add about five lines to introduce this feature, which is try my best (^_^) .

I suggest that this five lines should be still kept in the README, which will give developers who use gofuzz a clearer understanding of the functions of gofuzz.

kwongtailau

comment created time in a month

push eventkwongtailau/gofuzz

kwongtailau

commit sha 658e6004e90219b3e03a44115643f5ed811d8060

Fix: fix the format output of string in fuzz_test.go

view details

push time in a month

push eventkwongtailau/gofuzz

kwongtailau

commit sha f190b9d7c6b8f9c55290910919b6e58f56853ee9

Feat: Modify randString as private function in UnicodeRanges, add check function for the first and last of UnicodeRange, add Example function.

view details

push time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 var unicodeRanges = []charRange{ }  // randString makes a random string up to 20 characters long. The returned string-// may include a variety of (valid) UTF-8 encodings.-func randString(r *rand.Rand) string {+// may include a variety of (valid) UTF-8 encodings. If wants specific encoding+// string, it should input character range.+func randString(r *rand.Rand, characterRange *charRange) string { 	n := r.Intn(20) 	sb := strings.Builder{} 	sb.Grow(n) 	for i := 0; i < n; i++ {-		sb.WriteRune(unicodeRanges[r.Intn(len(unicodeRanges))].choose(r))+		if characterRange == nil {

For using function CustomStringFuzzFunc of UnicodeRange and UnicodeRanges, the logic using unicodeRange is changed.

I add defaultUnicodeRanges in package, for those who just want to generate string as usual.

kwongtailau

comment created time in a month

Pull request review commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

 func (f *Fuzzer) SkipFieldsWithPattern(pattern *regexp.Regexp) *Fuzzer { 	return f } +// WithCharRange is used to set the Unicode encoding range of the string.+func (f *Fuzzer) WithCharRange(first, last rune) *Fuzzer {

Well, it is good idea.

I delete function WithCharRange, add structure UnicodeRange and slice UnicodeRanges.Each of them has function CustomStringFuzzFunc

If people who just wants to generate a string with one encoding, they can use UnicodeRange function CustomStringFuzzFunc to generate. Those who want to generate a string in different encoding, they can use UnicodeRanges function CustomStringFuzzFunc to generate. If people don't want to custom string, they can use f.Fuzz(myString) as usual.

The changes have push, please @lavalamp review and comment !

kwongtailau

comment created time in a month

push eventkwongtailau/gofuzz

kwongtailau

commit sha fb69c53cf18bcfdab7c469a104a54265a7b6ad31

Feat: Modify charRange to UnicodeRange, add UnicodeRanges, and add func CustomStringFuzzFunc to UnicodeRange and UnicodeRanges to generate custom string

view details

push time in a month

pull request commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

@lavalamp Thanks for your reply. I seriously thought about the situation that you are worried about. Finally I changes the function WithStringGenMode to WithCharRange. This function provides the logic for the developers to input the Unicode encoding range, so that they can generate different encoding string. If they do not want to specific the string, they can generate fuzz string as usual. Looking forward to receiving your reply again or comment in code.

kwongtailau

comment created time in a month

push eventkwongtailau/gofuzz

kwongtailau

commit sha 63c87bad5e6087462e1821fa85657c59fa8e9b73

Feat: Add benchmark test function of testing randString with char range.

view details

push time in a month

push eventkwongtailau/gofuzz

kwongtailau

commit sha d5dcf20fd0933d146dff9e7d8570d7e7ac1649ab

Feat: Add function WithCharRange to generate different encoding string, low and high encoding of unicode should be input if you want different encoding string.

view details

push time in a month

create barnchkwongtailau/gofuzz

branch : feat/test

created branch time in a month

pull request commentgoogle/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

@googlebot I signed it!

kwongtailau

comment created time in a month

PR opened google/gofuzz

Set the character generation mode to generate character that conform to Unicode encoding

You can use f.WithStringGenMode(mode) to set generation mode to generate different character, like ASCII, MultiByte, CommonCJK, Chinese, Japanese, Number, Lower-Case, Upper-Case , default is random mode(each rune will be one of above character).

+74 -7

0 comment

3 changed files

pr created time in a month

push eventkwongtailau/gofuzz

kwongtailau

commit sha a36479649f3218ae3080dd3c1de8f35d8dbd196b

Feat: Add func WithString Mode to gen Chinese, Japanese, Number, Lower-case, Upper-case etc..Default mode is Random mode

view details

push time in a month

delete branch kwongtailau/gofuzz

delete branch : master_bk

delete time in a month

create barnchkwongtailau/gofuzz

branch : master

created branch time in a month

delete branch kwongtailau/gofuzz

delete branch : master

delete time in a month

create barnchkwongtailau/gofuzz

branch : master_bk

created branch time in a month

push eventkwongtailau/gofuzz

kwongtailau

commit sha 70bd5436a3513591d61d66e858c70229dc689b94

update go module url for test

view details

push time in a month

push eventkwongtailau/gofuzz

kwongtailau

commit sha 3849e2cabde249ea8041d8bb671fd8e1d8c993d0

feat: add func to gen Chinese char with utf-8.

view details

push time in a month

fork kwongtailau/gofuzz

Fuzz testing for go.

fork in a month

startedfullstorydev/grpcui

started time in a month

startedpanjf2000/ants

started time in 2 months

startedpanjf2000/gnet

started time in 2 months

startedfullstorydev/grpcui

started time in 2 months

startedgolang/lint

started time in 2 months

startedstretchr/testify

started time in 2 months

startedrcrowley/go-metrics

started time in 2 months

startedjhump/protoreflect

started time in 2 months

startedzimmski/go-mutesting

started time in 3 months

startedgo-xorm/xorm

started time in 3 months

more