-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscale_test.go
57 lines (46 loc) · 1.26 KB
/
scale_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
package balafon_test
import (
"bytes"
"fmt"
"testing"
"github.com/mgnsk/balafon"
. "github.com/onsi/gomega"
)
func TestKeyAccidentalsPitch(t *testing.T) {
for _, tc := range []struct {
input string
// MIDI:
key uint8
// MusicXML:
alter int
step string
}{
{":assign f 65; :key G; f", 66, 1, "F"},
{":assign f 65; :key G; f#", 66, 1, "F"}, // courtesy accidental
{":assign f 65; :key G; f$", 64, -1, "F"},
{":assign f 66; :key G; f", 66, 1, "F"},
{":assign b 71; :key Dm; b", 70, -1, "B"},
{":assign b 71; :key Dm; b$", 70, -1, "B"}, // courtesy accidental
{":assign b 71; :key Dm; b#", 72, 1, "B"},
{":assign b 70; :key Dm; b", 70, -1, "B"},
} {
t.Run(tc.input, func(t *testing.T) {
g := NewWithT(t)
{
it := balafon.New()
g.Expect(it.EvalString(tc.input)).To(Succeed())
bars := it.Flush()
g.Expect(bars).To(HaveLen(1))
_, key, _, ok := FindNote(bars[0])
g.Expect(ok).To(BeTrue())
g.Expect(key).To(Equal(tc.key))
}
{
var buf bytes.Buffer
g.Expect(balafon.ToXML(&buf, []byte(tc.input))).To(Succeed())
g.Expect(buf.String()).To(ContainSubstring(fmt.Sprintf("<alter>%d</alter>", tc.alter)))
g.Expect(buf.String()).To(ContainSubstring(fmt.Sprintf("<step>%s</step>", tc.step)))
}
})
}
}