github.com/ethereum/go-ethereum@v1.16.1/cmd/abigen/namefilter_test.go (about)

     1  // Copyright 2022 The go-ethereum Authors
     2  // This file is part of go-ethereum.
     3  //
     4  // go-ethereum is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // go-ethereum is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package main
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/stretchr/testify/assert"
    23  	"github.com/stretchr/testify/require"
    24  )
    25  
    26  func TestNameFilter(t *testing.T) {
    27  	t.Parallel()
    28  	_, err := newNameFilter("Foo")
    29  	require.Error(t, err)
    30  	_, err = newNameFilter("too/many:colons:Foo")
    31  	require.Error(t, err)
    32  
    33  	f, err := newNameFilter("a/path:A", "*:B", "c/path:*")
    34  	require.NoError(t, err)
    35  
    36  	for _, tt := range []struct {
    37  		name  string
    38  		match bool
    39  	}{
    40  		{"a/path:A", true},
    41  		{"unknown/path:A", false},
    42  		{"a/path:X", false},
    43  		{"unknown/path:X", false},
    44  		{"any/path:B", true},
    45  		{"c/path:X", true},
    46  		{"c/path:foo:B", false},
    47  	} {
    48  		match := f.Matches(tt.name)
    49  		if tt.match {
    50  			assert.True(t, match, "expected match")
    51  		} else {
    52  			assert.False(t, match, "expected no match")
    53  		}
    54  	}
    55  }