-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbdump_test.go
125 lines (116 loc) · 2.4 KB
/
dbdump_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package freedb
import (
"encoding/hex"
"os"
"path"
"reflect"
"testing"
"github.com/davecgh/go-spew/spew"
)
func TestParseOffset(t *testing.T) {
line := `# 139870`
offset, err := parseOffset(line)
if err != nil {
t.Fatal(err)
}
t.Log(offset)
}
func TestParsePair(t *testing.T) {
testPair := "key=value"
kv, err := parsePair(testPair)
if err != nil {
t.Fatal(err)
}
logTmpl := "expected:%s got:%s"
expected := pair{"key", "value"}
if !reflect.DeepEqual(kv, expected) {
t.Fatalf(logTmpl, expected, kv)
}
t.Logf(logTmpl, expected, kv)
expectedKey := "key"
if kv.key() != expectedKey {
t.Fatalf(logTmpl, expectedKey, kv.key())
}
t.Logf(logTmpl, expectedKey, kv.key())
expectedValue := "value"
if kv.value() != expectedValue {
t.Fatalf(logTmpl, expectedValue, kv.value())
}
t.Logf(logTmpl, expectedValue, kv.value())
}
func TestExtractPosNumber(t *testing.T) {
test := "SOMETHING3"
expected := 3
got, err := extractPosNum(test)
if err != nil {
t.Fatal(err)
}
logTmpl := "expected:%d got:%d"
if expected != got {
t.Fatalf(logTmpl, expected, got)
}
t.Logf(logTmpl, expected, got)
}
func TestHex(t *testing.T) {
id := "decafbad"
f, err := os.Open(path.Join("test", id))
if err != nil {
t.Fatal(err)
}
shard, err := ShardPos("soundtrack")
if err != nil {
t.Fatal(err)
}
disc, err := ParseDump(f, shard)
if err != nil {
t.Fatal(err)
}
tmpl := "expected:%s got:%s"
enc := hex.EncodeToString(disc.IDs[0])
if id != enc {
t.Fatalf(tmpl, id, enc)
}
t.Logf(tmpl, id, enc)
}
func TestParseDump(t *testing.T) {
testDump := "decafbad"
f, err := os.Open(path.Join("test", testDump))
if err != nil {
t.Fatal(err)
}
shard, err := ShardPos("soundtrack")
if err != nil {
t.Fatal(err)
}
disc, err := ParseDump(f, shard)
if err != nil {
t.Fatal(err)
}
exID, err := hex.DecodeString(testDump)
if err != nil {
t.Fatal(err)
}
exGenre := "Math Rock"
exYear := uint16(2005)
if err != nil {
t.Fatal(err)
}
expected := &Disc{
IDs: [][]uint8{exID},
Shard: 10,
Genre: &exGenre,
Year: &exYear,
Title: "The Nameless Faceless Many / dot dot E.P.",
Offsets: []uint32{100, 200, 60000},
Duration: uint16(2000),
Tracks: []string{
"Introduction",
"So Long That It Wraps Around",
},
}
tmpl := "expected:%s got:%s"
if !reflect.DeepEqual(expected, disc) {
t.Fatalf(tmpl, spew.Sdump(expected), spew.Sdump(disc))
}
t.Log(spew.Sdump(disc))
}