github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/internal/output_test.go (about)

     1  package internal
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/go-quicktest/qt"
     7  )
     8  
     9  func TestIdentifier(t *testing.T) {
    10  	testcases := []struct {
    11  		in, out string
    12  	}{
    13  		{".rodata", "Rodata"},
    14  		{"_foo_bar_", "FooBar"},
    15  		{"ipv6_test", "Ipv6Test"},
    16  		{"FOO_BAR", "FOO_BAR"},
    17  		{"FOO_", "FOO_"},
    18  		{"FOO__BAR", "FOO__BAR"},
    19  		{"FOO___BAR", "FOO___BAR"},
    20  		{"_FOO__BAR", "FOO__BAR"},
    21  		{"__FOO__BAR", "FOO__BAR"},
    22  	}
    23  
    24  	for _, tc := range testcases {
    25  		have := Identifier(tc.in)
    26  		if have != tc.out {
    27  			t.Errorf("Expected %q as output of %q, got %q", tc.out, tc.in, have)
    28  		}
    29  	}
    30  }
    31  
    32  func TestGoTypeName(t *testing.T) {
    33  	type foo struct{}
    34  	type bar[T any] struct{}
    35  	qt.Assert(t, qt.Equals(GoTypeName(foo{}), "foo"))
    36  	qt.Assert(t, qt.Equals(GoTypeName(new(foo)), "foo"))
    37  	qt.Assert(t, qt.Equals(GoTypeName(new(*foo)), "foo"))
    38  	qt.Assert(t, qt.Equals(GoTypeName(bar[int]{}), "bar[int]"))
    39  	// Broken in the stdlib, see GoTypeName for details.
    40  	// qt.Assert(t, GoTypeName(bar[qt.C]{}), qt.Equals, "bar[quicktest.C]")
    41  }