@@ -2,8 +2,6 @@ package gitdiff
2
2
3
3
import (
4
4
"bytes"
5
- "fmt"
6
- "math/rand"
7
5
"testing"
8
6
)
9
7
@@ -98,23 +96,22 @@ func TestBase85Encode(t *testing.T) {
98
96
}
99
97
}
100
98
101
- func TestBase85Roundtrip (t * testing.T ) {
102
- r := rand .New (rand .NewSource (72 )) // chosen by fair dice roll
99
+ func FuzzBase85Roundtrip (f * testing.F ) {
100
+ f .Add ([]byte {0x2b , 0x0d })
101
+ f .Add ([]byte {0xbc , 0xb4 , 0x3f })
102
+ f .Add ([]byte {0xfa , 0x62 , 0x05 , 0x83 , 0x24 , 0x39 , 0xd5 , 0x25 })
103
+ f .Add ([]byte {0x31 , 0x59 , 0x02 , 0xa0 , 0x61 , 0x12 , 0xd9 , 0x43 , 0xb8 , 0x23 , 0x1a , 0xb4 , 0x02 , 0xae , 0xfa , 0xcc , 0x22 , 0xad , 0x41 , 0xb9 , 0xb8 })
103
104
104
- for _ , size := range [] int { 64 , 85 , 1025 } {
105
- t . Run ( fmt . Sprintf ( "size%d" , size ), func ( t * testing. T ) {
106
- in := make ([]byte , size )
107
- r . Read ( in )
105
+ f . Fuzz ( func ( t * testing. T , in [] byte ) {
106
+ n := len ( in )
107
+ dst := make ([]byte , base85Len ( n ) )
108
+ out := make ([] byte , n )
108
109
109
- dst := make ([] byte , base85Len ( size ) )
110
- out := make ([] byte , size )
110
+ base85Encode ( dst , in )
111
+ base85Decode ( out , dst )
111
112
112
- base85Encode (dst , in )
113
- base85Decode (out , dst )
114
-
115
- if ! bytes .Equal (in , out ) {
116
- t .Errorf ("decoded data differed from input data:\n input: %x\n output: %x\n encoding: %s\n " , in , out , string (dst ))
117
- }
118
- })
119
- }
113
+ if ! bytes .Equal (in , out ) {
114
+ t .Errorf ("decoded data differed from input data:\n input: %x\n output: %x\n encoding: %s\n " , in , out , string (dst ))
115
+ }
116
+ })
120
117
}
0 commit comments