forked from dhowden/tag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
id3v2_test.go
155 lines (135 loc) · 3.01 KB
/
id3v2_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2015, David Howden
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tag
import (
"bytes"
"reflect"
"testing"
)
func TestUnsynchroniser(t *testing.T) {
tests := []struct {
input []byte
output []byte
}{
{
input: []byte{},
output: []byte{},
},
{
input: []byte{0x00},
output: []byte{0x00},
},
{
input: []byte{0xFF},
output: []byte{0xFF},
},
{
input: []byte{0xFF, 0x00},
output: []byte{0xFF},
},
{
input: []byte{0xFF, 0x00, 0x00},
output: []byte{0xFF, 0x00},
},
{
input: []byte{0xFF, 0x00, 0x01},
output: []byte{0xFF, 0x01},
},
{
input: []byte{0xFF, 0x00, 0xFF, 0x00},
output: []byte{0xFF, 0xFF},
},
{
input: []byte{0xFF, 0x00, 0xFF, 0xFF, 0x00},
output: []byte{0xFF, 0xFF, 0xFF},
},
{
input: []byte{0x00, 0x01, 0x02},
output: []byte{0x00, 0x01, 0x02},
},
}
for ii, tt := range tests {
r := bytes.NewReader(tt.input)
ur := unsynchroniser{Reader: r}
got := make([]byte, len(tt.output))
n, err := ur.Read(got)
if n != len(got) || err != nil {
t.Errorf("[%d] got: n = %d, err = %v, expected: n = %d, err = nil", ii, n, err, len(got))
}
if !reflect.DeepEqual(got, tt.output) {
t.Errorf("[%d] got: %v, expected %v", ii, got, tt.output)
}
}
}
func TestUnsynchroniserSplitReads(t *testing.T) {
tests := []struct {
input []byte
output []byte
split []int
}{
{
input: []byte{0x00, 0xFF, 0x00},
output: []byte{0x00, 0xFF},
split: []int{1, 1},
},
{
input: []byte{0xFF, 0x00, 0x01},
output: []byte{0xFF, 0x01},
split: []int{1, 1},
},
{
input: []byte{0xFF, 0x00, 0x01, 0x02},
output: []byte{0xFF, 0x01, 0x02},
split: []int{1, 1, 1},
},
{
input: []byte{0xFF, 0x00, 0x01, 0x02},
output: []byte{0xFF, 0x01, 0x02},
split: []int{2, 1},
},
{
input: []byte{0xFF, 0x00, 0x01, 0x02},
output: []byte{0xFF, 0x01, 0x02},
split: []int{1, 2},
},
}
for ii, tt := range tests {
r := bytes.NewReader(tt.input)
ur := unsynchroniser{Reader: r}
var got []byte
for i, l := range tt.split {
chunk := make([]byte, l)
n, err := ur.Read(chunk)
if n != len(chunk) || err != nil {
t.Errorf("[%d : %d] got: n = %d, err = %v, expected: n = %d, err = nil", ii, i, n, err, l)
}
got = append(got, chunk...)
}
if !reflect.DeepEqual(got, tt.output) {
t.Errorf("[%d] got: %v, expected %v", ii, got, tt.output)
}
}
}
func TestGenreExpension(t *testing.T) {
var tests = map[string]string{
"Test": "Test",
"((17)": "(17)",
"(17) Test": "Rock Test",
"(17)Test": "Rock Test",
"(17)": "Rock",
"Test(17)": "Test Rock",
"Test (17)": "Test Rock",
"(17)(93)": "Rock Psychedelic Rock",
"(17)Test(93)": "Rock Test Psychedelic Rock",
"(175)": "Post-Punk",
"(187)": "Indie Rock",
"(191)": "Psybient",
}
for g, r := range tests {
got := id3v2genre(g)
if got != r {
t.Errorf("[%v] got: %v, expected %v", g, got, r)
}
}
}