Read Y as a placeholder in opcode family names
Names such as egN_timeX_onccY have a second number, so eg1_time2_oncc3 was reported as unknown. Check that a name made from each family is found. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -24,6 +26,8 @@ func TestLookup(t *testing.T) {
|
||||
{"v064", "vNNN"},
|
||||
{"hint_anything_here", "hint_*"},
|
||||
{"cutoff2_cc5", "cutoff2_ccN"},
|
||||
{"eg1_time2_oncc3", "egN_timeX_onccY"},
|
||||
{"lfo01_freq_lfo2_oncc4", "lfoN_freq_lfoX_onccY"},
|
||||
} {
|
||||
info, ok := Lookup(tc.name)
|
||||
if !ok || info.Name != tc.canonical {
|
||||
@@ -202,3 +206,26 @@ func TestTypedOpcodesKnown(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestFamiliesMatchTheirNames checks that a name made from each family's, with
|
||||
// numbers where its placeholders are, is found as that family, or as another
|
||||
// that is as specific.
|
||||
func TestFamiliesMatchTheirNames(t *testing.T) {
|
||||
placeholderRE := regexp.MustCompile(`[NXY]+`)
|
||||
for info := range KnownOpcodes() {
|
||||
for _, name := range append([]string{info.Name}, info.Aliases...) {
|
||||
if !strings.ContainsAny(name, "NXY*") {
|
||||
continue
|
||||
}
|
||||
digit := 0
|
||||
made := placeholderRE.ReplaceAllStringFunc(name, func(string) string { digit++; return strconv.Itoa(digit + 10) })
|
||||
made = strings.ReplaceAll(made, "*", "anything")
|
||||
got, ok := Lookup(made)
|
||||
if !ok {
|
||||
t.Errorf("%s: Lookup(%q) found nothing", name, made)
|
||||
} else if got.Name != info.Name && !strings.ContainsAny(got.Name, "NXY*") {
|
||||
t.Errorf("%s: Lookup(%q) found %q", name, made, got.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user