diff --git a/registry.go b/registry.go index bf64aa2..46a1429 100644 --- a/registry.go +++ b/registry.go @@ -46,8 +46,8 @@ type HeaderInfo struct { } // OpcodeInfo describes an opcode of the format. A name that stands for a -// family has uppercase placeholders: N and X stand for a number, as in -// loccN and egN_timeX, and * for any name, as in hint_*. +// family has uppercase placeholders: N, X and Y stand for a number, as in +// loccN and egN_timeX_onccY, and * for any name, as in hint_*. type OpcodeInfo struct { // Name is the opcode's own name. Name string @@ -89,8 +89,8 @@ var ( headerByName map[string]*HeaderInfo ) -// patternRE reads a name's placeholders: a run of N and X letters, or a *. -var patternRE = regexp.MustCompile(`[NX]+|\*`) +// patternRE reads a name's placeholders: a run of N, X and Y letters, or a *. +var patternRE = regexp.MustCompile(`[NXY]+|\*`) // pattern returns the expression that matches the names a family name stands // for, or nil if the name is a single opcode's. diff --git a/registry_test.go b/registry_test.go index f32f3b6..9c579b3 100644 --- a/registry_test.go +++ b/registry_test.go @@ -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) + } + } + } +}