@@ -50,3 +50,34 @@ func Test_GetGistIDFromURL(t *testing.T) {
5050 })
5151 }
5252}
53+
54+ func TestIsBinaryContents (t * testing.T ) {
55+ tests := []struct {
56+ fileContent []byte
57+ want bool
58+ }{
59+ {
60+ want : false ,
61+ fileContent : []byte ("package main" ),
62+ },
63+ {
64+ want : true ,
65+ fileContent : []byte {239 , 191 , 189 , 239 , 191 , 189 , 239 , 191 , 189 , 239 ,
66+ 191 , 189 , 239 , 191 , 189 , 16 , 74 , 70 , 73 , 70 , 239 , 191 , 189 , 1 , 1 , 1 ,
67+ 1 , 44 , 1 , 44 , 239 , 191 , 189 , 239 , 191 , 189 , 239 , 191 , 189 , 239 , 191 ,
68+ 189 , 239 , 191 , 189 , 67 , 239 , 191 , 189 , 8 , 6 , 6 , 7 , 6 , 5 , 8 , 7 , 7 , 7 ,
69+ 9 , 9 , 8 , 10 , 12 , 20 , 10 , 12 , 11 , 11 , 12 , 25 , 18 , 19 , 15 , 20 , 29 , 26 ,
70+ 31 , 30 , 29 , 26 , 28 , 28 , 32 , 36 , 46 , 39 , 32 , 34 , 44 , 35 , 28 , 28 , 40 ,
71+ 55 , 41 , 44 , 48 , 49 , 52 , 52 , 52 , 31 , 39 , 57 , 61 , 56 , 50 , 60 , 46 , 51 ,
72+ 52 , 50 , 239 , 191 , 189 , 239 , 191 , 189 , 239 , 191 , 189 , 67 , 1 , 9 , 9 , 9 , 12 },
73+ },
74+ }
75+
76+ for _ , tt := range tests {
77+ isBinary , err := IsBinaryContents (tt .fileContent )
78+ if err != nil {
79+ t .Fatal (err )
80+ }
81+ assert .Equal (t , tt .want , isBinary )
82+ }
83+ }
0 commit comments