github.com/blueinnovationsgroup/can-go@v0.0.0-20230518195432-d0567cda0028/pkg/dbc/identifier_test.go (about)

     1  package dbc
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"testing"
     7  
     8  	"gotest.tools/v3/assert"
     9  )
    10  
    11  func TestIdentifier_Validate(t *testing.T) {
    12  	for _, tt := range []Identifier{
    13  		"_",
    14  		"_foo",
    15  		"foo",
    16  		"foo32",
    17  		"_43",
    18  		Identifier(strings.Repeat("a", maxIdentifierLength)),
    19  	} {
    20  		tt := tt
    21  		t.Run(fmt.Sprintf("%v", tt), func(t *testing.T) {
    22  			assert.NilError(t, tt.Validate())
    23  		})
    24  	}
    25  }
    26  
    27  func TestIdentifier_Validate_Error(t *testing.T) {
    28  	for _, tt := range []Identifier{
    29  		"42",
    30  		"",
    31  		"42foo",
    32  		"☃",
    33  		"foo☃",
    34  		"foo bar",
    35  		Identifier(strings.Repeat("a", maxIdentifierLength+1)),
    36  	} {
    37  		tt := tt
    38  		t.Run(fmt.Sprintf("%v", tt), func(t *testing.T) {
    39  			assert.ErrorContains(t, tt.Validate(), "invalid identifier")
    40  		})
    41  	}
    42  }