j = len(v)
}
}
+
+ // Then, try to make it more simplified and human-readable by trying to replace each
+ // byte with a printable character.
+ printableChars := []byte("012789ABCXYZabcxyz !\"#$%&'()*+,.")
+ for i, b := range v {
+ if shouldStop() {
+ return
+ }
+
+ for _, pc := range printableChars {
+ v[i] = pc
+ if try(v) {
+ // Successful. Move on to the next byte in v.
+ break
+ }
+ // Unsuccessful. Revert v[i] back to original value.
+ v[i] = b
+ }
+ }
}
func minimizeInteger(v uint, try func(interface{}) bool, shouldStop func() bool) {
"fmt"
"reflect"
"testing"
+ "unicode"
+ "unicode/utf8"
)
func TestMinimizeInput(t *testing.T) {
return fmt.Errorf("bad %v", e.Values[0])
},
input: []interface{}{[]byte{1, 2, 3, 4, 5}},
- expected: []interface{}{[]byte{2, 3}},
+ expected: []interface{}{[]byte("00")},
},
{
name: "set_of_bytes",
input: []interface{}{[]byte{0, 1, 2, 3, 4, 5}},
expected: []interface{}{[]byte{0, 4, 5}},
},
+ {
+ name: "non_ascii_bytes",
+ fn: func(e CorpusEntry) error {
+ b := e.Values[0].([]byte)
+ if len(b) == 3 {
+ return fmt.Errorf("bad %v", e.Values[0])
+ }
+ return nil
+ },
+ input: []interface{}{[]byte("ท")}, // ท is 3 bytes
+ expected: []interface{}{[]byte("000")},
+ },
{
name: "ones_string",
fn: func(e CorpusEntry) error {
input: []interface{}{"001010001000000000000000000"},
expected: []interface{}{"111"},
},
+ {
+ name: "string_length",
+ fn: func(e CorpusEntry) error {
+ b := e.Values[0].(string)
+ if len(b) == 5 {
+ return fmt.Errorf("bad %v", e.Values[0])
+ }
+ return nil
+ },
+ input: []interface{}{"zzzzz"},
+ expected: []interface{}{"00000"},
+ },
+ {
+ name: "string_with_letter",
+ fn: func(e CorpusEntry) error {
+ b := e.Values[0].(string)
+ r, _ := utf8.DecodeRune([]byte(b))
+ if unicode.IsLetter(r) {
+ return fmt.Errorf("bad %v", e.Values[0])
+ }
+ return nil
+ },
+ input: []interface{}{"ZZZZZ"},
+ expected: []interface{}{"A"},
+ },
{
name: "int",
fn: func(e CorpusEntry) error {