-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriter_test.go
More file actions
137 lines (130 loc) · 2.8 KB
/
writer_test.go
File metadata and controls
137 lines (130 loc) · 2.8 KB
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
package ultrastar
import (
"bytes"
"io"
"os"
"strings"
"testing"
)
func TestWriteNote(t *testing.T) {
n := Note{
Type: NoteTypeRap,
Start: 15,
Duration: 4,
Pitch: -3,
Text: " hello ",
}
expected := "R 15 4 -3 hello \n"
b := &strings.Builder{}
err := NewWriter(b, Version120).WriteNote(n, P1)
actual := b.String()
if err != nil {
t.Errorf("WriteNote(b, %v) caused an unexpected error: %s", n, err)
}
if actual != expected {
t.Errorf("WriteNote(b, %v) resulted in %q, expected %q", n, actual, expected)
}
}
func TestWriter_WriteNote(t *testing.T) {
n := Note{
Type: NoteTypeRap,
Start: 15,
Duration: 4,
Pitch: -3,
Text: " hello ",
}
expected := "R 15 4 -3 hello \n"
b := &strings.Builder{}
w := NewWriter(b, Version120)
err := w.WriteNote(n, P1)
actual := b.String()
if err != nil {
t.Errorf("WriteNote(b, %v) caused an unexpected error: %s", n, err)
}
if actual != expected {
t.Errorf("WriteNote(b, %v) resulted in %q, expected %q", n, actual, expected)
}
}
func TestWriteNotes(t *testing.T) {
t.Run("notes formatting", func(t *testing.T) {
ns := Voice{
Name: "A Voice",
Notes: []Note{
{
Type: NoteTypeRegular,
Start: 2,
Duration: 4,
Pitch: 8,
Text: "some",
},
{
Type: NoteTypeRegular,
Start: 8,
Duration: 4,
Pitch: 8,
Text: "body",
},
{
Type: NoteTypeEndOfPhrase,
Start: 13,
},
{
Type: NoteTypeGolden,
Start: 14,
Duration: 4,
Pitch: 1,
Text: "once",
},
{
Type: NoteTypeGolden,
Start: 20,
Duration: 4,
Pitch: 1,
Text: " told",
},
{
Type: NoteTypeFreestyle,
Start: 26,
Duration: 4,
Pitch: 1,
Text: " me,",
},
},
}
b := &strings.Builder{}
w := NewWriter(b, Version120)
for _, n := range ns.Notes {
if err := w.WriteNote(n, P1); err != nil {
t.Errorf("WriteNote(n, 1) caused an unexpected error: %s", err)
return
}
}
actual := b.String()
expected := `: 2 4 8 some
: 8 4 8 body
- 13
* 14 4 1 once
* 20 4 1 told
F 26 4 1 me,
`
if actual != expected {
t.Errorf("WriteNotes(b, ns) resulted in %q, expected %q", actual, expected)
}
})
}
func TestReadWriteSong(t *testing.T) {
f, _ := os.Open("testdata/Smash Mouth - All Star.txt")
defer f.Close()
expected := &bytes.Buffer{}
r, _ := NewReader(io.TeeReader(f, expected))
s, _ := r.ReadSong()
actual := &strings.Builder{}
err := WriteSong(actual, s, r.Version)
if err != nil {
t.Errorf("WriteSong(b, ns) caused an unexpected error: %s", err)
}
actualStr, expectedStr := actual.String(), expected.String()
if actualStr != expectedStr {
t.Errorf("WriteNotes(b, ns) resulted in %q, expected %q", actualStr, expectedStr)
}
}