github.1485827954.workers.dev/ethereum/go-ethereum@v1.14.3/cmd/abigen/namefilter_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestNameFilter(t *testing.T) {
    11  	t.Parallel()
    12  	_, err := newNameFilter("Foo")
    13  	require.Error(t, err)
    14  	_, err = newNameFilter("too/many:colons:Foo")
    15  	require.Error(t, err)
    16  
    17  	f, err := newNameFilter("a/path:A", "*:B", "c/path:*")
    18  	require.NoError(t, err)
    19  
    20  	for _, tt := range []struct {
    21  		name  string
    22  		match bool
    23  	}{
    24  		{"a/path:A", true},
    25  		{"unknown/path:A", false},
    26  		{"a/path:X", false},
    27  		{"unknown/path:X", false},
    28  		{"any/path:B", true},
    29  		{"c/path:X", true},
    30  		{"c/path:foo:B", false},
    31  	} {
    32  		match := f.Matches(tt.name)
    33  		if tt.match {
    34  			assert.True(t, match, "expected match")
    35  		} else {
    36  			assert.False(t, match, "expected no match")
    37  		}
    38  	}
    39  }