-
Notifications
You must be signed in to change notification settings - Fork 6
/
corediff_test.go
55 lines (48 loc) · 1.15 KB
/
corediff_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func digest(b uint64) string {
return fmt.Sprintf("%x", b)
}
func Test_parseFile(t *testing.T) {
hdb := hashDB{}
updateDB := true
hits, lines := parseFile("fixture/docroot/odd-encoding.js", hdb, updateDB)
assert.Equal(t, 220, len(hdb))
assert.Equal(t, 220, len(hits))
assert.Equal(t, 220, len(lines))
}
func Test_hash(t *testing.T) {
tests := []struct {
args []byte
want string
}{
{[]byte("banaan"), "acfb1ff4438e39f3"},
}
for _, tt := range tests {
t.Run(string(tt.args), func(t *testing.T) {
if got := digest(hash(tt.args)); got != tt.want {
t.Errorf("hash() = %x (%v), want %x", got, got, tt.want)
}
})
}
}
func Test_vendor_bug(t *testing.T) {
db := loadDB("fixture/sample.db")
assert.Len(t, db, 238)
wantHash := uint64(3900178074848893275)
if _, ok := db[wantHash]; !ok {
t.Error("hash not in db")
}
}
// Too slow to run in testing.B
// func Test_loadFile(t *testing.T) {
// for i := 0; i < 10; i++ {
// start := time.Now()
// loadDB("m2.db") // pre-allocating fixed map size saves 20% time
// fmt.Println(time.Since(start))
// }
// }