diff --git a/lex.go b/lex.go index aa1c359..220b740 100644 --- a/lex.go +++ b/lex.go @@ -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 diff --git a/robust_test.go b/robust_test.go index ef31fc7..d7c9e0d 100644 --- a/robust_test.go +++ b/robust_test.go @@ -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{ + " sample=A=440.wav lokey=1": {"sample=A=440.wav", "lokey=1"}, + " sample=a b=c.wav": {"sample=a", "b=c.wav"}, + "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) + } + } +}