Keep = signs in opcode values
An opcode's value now ends at whitespace followed by the next opcode, so sample=A=440.wav is one value. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,9 +16,10 @@ var (
|
||||
// includeRE reads an #include's quoted path.
|
||||
includeRE = regexp.MustCompile(`^#include[ \t]+"([^"\r\n]*)"`)
|
||||
// breakRE finds where an opcode's value ends: at a header, the next
|
||||
// opcode, a comment, a directive after whitespace, or the end of the line,
|
||||
// so that a value can hold spaces, as a sample's path can.
|
||||
breakRE = regexp.MustCompile(`<[A-Za-z_]+>|[A-Za-z0-9_$]+=|//|/\*|\s#(?:define|include)\b|\n`)
|
||||
// opcode after whitespace, a comment, a directive after whitespace, or the
|
||||
// end of the line, so that a value can hold spaces and = signs, as a
|
||||
// sample's path can.
|
||||
breakRE = regexp.MustCompile(`<[A-Za-z_]+>|\s[A-Za-z0-9_$]+=|//|/\*|\s#(?:define|include)\b|\n`)
|
||||
)
|
||||
|
||||
// byteOrderMark is the UTF-8 mark some editors put at the start of a file. It
|
||||
|
||||
@@ -285,3 +285,27 @@ func TestBuildVariablesWithAbsoluteSamples(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestEqualsInValue checks that a value may hold =, and that the next opcode
|
||||
// starts only after whitespace.
|
||||
func TestEqualsInValue(t *testing.T) {
|
||||
for text, want := range map[string][]string{
|
||||
"<region> sample=A=440.wav lokey=1": {"sample=A=440.wav", "lokey=1"},
|
||||
"<region> sample=a b=c.wav": {"sample=a", "b=c.wav"},
|
||||
"<region>sample=x.wav\n lokey=1\thikey=2": {"sample=x.wav", "lokey=1", "hikey=2"},
|
||||
"label_cc1=Volume=Loud // note": {"label_cc1=Volume=Loud"},
|
||||
// Without whitespace, what follows is part of the value.
|
||||
"lokey=1hikey=2": {"lokey=1hikey=2"},
|
||||
} {
|
||||
doc := mustParse(t, text, nil)
|
||||
var got []string
|
||||
for _, n := range doc.Root.Nodes {
|
||||
if n.Kind == KindOpcode {
|
||||
got = append(got, n.Name+"="+n.Value)
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) || doc.String() != text {
|
||||
t.Errorf("%q: opcodes %q, want %q", text, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user