1package name
2
3import (
4	"go/build"
5	"path/filepath"
6	"testing"
7
8	"github.com/stretchr/testify/require"
9)
10
11func Test_Package(t *testing.T) {
12	table := []tt{
13		{"Foo", "foo"},
14		{"Foo/Foo", "foo/foo"},
15		{"Foo_Foo", "foofoo"},
16		{"create_table", "createtable"},
17		{"admin/widget", "admin/widget"},
18		{"admin\\widget", "admin/widget"},
19	}
20
21	c := build.Default
22
23	for _, src := range c.SrcDirs() {
24		adds := []tt{
25			{filepath.Join(src, "admin/widget"), "admin/widget"},
26			{filepath.Join(src, "admin\\widget"), "admin/widget"},
27			{filepath.Join(filepath.Dir(src), "admin/widget"), "admin/widget"},
28			{filepath.Join(filepath.Dir(src), "admin\\widget"), "admin/widget"},
29		}
30		table = append(table, adds...)
31	}
32	for _, tt := range table {
33		t.Run(tt.act, func(st *testing.T) {
34			r := require.New(st)
35			r.Equal(tt.exp, Package(tt.act))
36			r.Equal(tt.exp, Package(tt.exp))
37		})
38	}
39}
40