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:
2026-12-01 18:43:01 +00:00
co-authored by Claude Sonnet 5.5
parent 83c905633c
commit 41f752e1c1
2 changed files with 31 additions and 4 deletions
+4 -4
View File
@@ -46,8 +46,8 @@ type HeaderInfo struct {
} }
// OpcodeInfo describes an opcode of the format. A name that stands for a // 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 // family has uppercase placeholders: N, X and Y stand for a number, as in
// loccN and egN_timeX, and * for any name, as in hint_*. // loccN and egN_timeX_onccY, and * for any name, as in hint_*.
type OpcodeInfo struct { type OpcodeInfo struct {
// Name is the opcode's own name. // Name is the opcode's own name.
Name string Name string
@@ -89,8 +89,8 @@ var (
headerByName map[string]*HeaderInfo headerByName map[string]*HeaderInfo
) )
// patternRE reads a name's placeholders: a run of N and X letters, or a *. // patternRE reads a name's placeholders: a run of N, X and Y letters, or a *.
var patternRE = regexp.MustCompile(`[NX]+|\*`) var patternRE = regexp.MustCompile(`[NXY]+|\*`)
// pattern returns the expression that matches the names a family name stands // pattern returns the expression that matches the names a family name stands
// for, or nil if the name is a single opcode's. // for, or nil if the name is a single opcode's.
+27
View File
@@ -4,6 +4,8 @@ import (
"flag" "flag"
"fmt" "fmt"
"os" "os"
"regexp"
"strconv"
"strings" "strings"
"testing" "testing"
) )
@@ -24,6 +26,8 @@ func TestLookup(t *testing.T) {
{"v064", "vNNN"}, {"v064", "vNNN"},
{"hint_anything_here", "hint_*"}, {"hint_anything_here", "hint_*"},
{"cutoff2_cc5", "cutoff2_ccN"}, {"cutoff2_cc5", "cutoff2_ccN"},
{"eg1_time2_oncc3", "egN_timeX_onccY"},
{"lfo01_freq_lfo2_oncc4", "lfoN_freq_lfoX_onccY"},
} { } {
info, ok := Lookup(tc.name) info, ok := Lookup(tc.name)
if !ok || info.Name != tc.canonical { 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)
}
}
}
}