You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1004 B
Go

package matcher
import (
"testing"
ctxpkg "github.com/noahlann/nnet/pkg/context"
routerpkg "github.com/noahlann/nnet/pkg/router"
"github.com/stretchr/testify/assert"
)
type dummyContext struct {
ctxpkg.Context
}
func TestCompositeMatcher_AND(t *testing.T) {
m1 := routerpkg.NewStringMatcher("hello")
m2 := routerpkg.NewStringMatcher("hello*")
and := routerpkg.NewAndMatcher(m1, m2)
assert.True(t, and.Match(routerpkg.MatchInput{Raw: []byte("hello")}, &dummyContext{}))
assert.False(t, and.Match(routerpkg.MatchInput{Raw: []byte("hi")}, &dummyContext{}))
}
func TestCompositeMatcher_OR(t *testing.T) {
m1 := routerpkg.NewStringMatcher("hello")
m2 := routerpkg.NewStringMatcher("ping")
or := routerpkg.NewOrMatcher(m1, m2)
assert.True(t, or.Match(routerpkg.MatchInput{Raw: []byte("hello")}, &dummyContext{}))
assert.True(t, or.Match(routerpkg.MatchInput{Raw: []byte("ping")}, &dummyContext{}))
assert.False(t, or.Match(routerpkg.MatchInput{Raw: []byte("other")}, &dummyContext{}))
}