Skip to content

Commit

Permalink
add tests for OSC Message match function
Browse files Browse the repository at this point in the history
  • Loading branch information
hypebeast committed Dec 2, 2019
1 parent 3ab1234 commit e4d823f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion osc/osc.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (msg *Message) ClearData() {
msg.Arguments = msg.Arguments[len(msg.Arguments):]
}

// Match returns true, if the address of the OSC Message matches the given
// Match returns true, if the OSC address pattern of the OSC Message matches the given
// address. The match is case sensitive!
func (msg *Message) Match(addr string) bool {
exp := getRegEx(msg.Address)
Expand Down
43 changes: 43 additions & 0 deletions osc/osc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,49 @@ func TestParsePacket(t *testing.T) {
}
}

func TestOscMessageMatch(t *testing.T) {
tc := []struct {
desc string
addr string
addrPattern string
want bool
}{
{
"match everything",
"*",
"/a/b",
true,
},
{
"don't match",
"/a/b",
"/a",
false,
},
{
"match alternatives",
"/a/{foo,bar}",
"/a/foo",
true,
},
{
"don't match if address is not part of the alternatives",
"/a/{foo,bar}",
"/a/bob",
false,
},
}

for _, tt := range tc {
msg := NewMessage(tt.addr)

got := msg.Match(tt.addrPattern)
if got != tt.want {
t.Errorf("%s: msg.Match('%s') = '%t', want = '%t'", tt.desc, tt.addrPattern, got, tt.want)
}
}
}

const zero = string(byte(0))

// nulls returns a string of `i` nulls.
Expand Down

0 comments on commit e4d823f

Please sign in to comment.