Remove unused code from templates
This commit is contained in:
parent
b34a8e3212
commit
c278bb6667
6 changed files with 5 additions and 104 deletions
|
@ -69,26 +69,6 @@ func SetComplement(a []string, b []string) []string {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetIntersect returns the elements that are common in a and b
|
|
||||||
func SetIntersect(a []string, b []string) []string {
|
|
||||||
c := make([]string, 0, len(a))
|
|
||||||
|
|
||||||
for _, aVal := range a {
|
|
||||||
found := false
|
|
||||||
for _, bVal := range b {
|
|
||||||
if aVal == bVal {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if found {
|
|
||||||
c = append(c, aVal)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMerge will return a merged slice without duplicates
|
// SetMerge will return a merged slice without duplicates
|
||||||
func SetMerge(a []string, b []string) []string {
|
func SetMerge(a []string, b []string) []string {
|
||||||
var x, merged []string
|
var x, merged []string
|
||||||
|
|
|
@ -135,44 +135,6 @@ func TestSetComplement(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetIntersect(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
A []string
|
|
||||||
B []string
|
|
||||||
C []string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
[]string{"thing1", "thing2", "thing3"},
|
|
||||||
[]string{"thing2", "otherthing", "stuff"},
|
|
||||||
[]string{"thing2"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{},
|
|
||||||
[]string{"thing1", "thing2"},
|
|
||||||
[]string{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{"thing1", "thing2"},
|
|
||||||
[]string{},
|
|
||||||
[]string{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]string{"thing1", "thing2"},
|
|
||||||
[]string{"thing1", "thing2"},
|
|
||||||
[]string{"thing1", "thing2"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, test := range tests {
|
|
||||||
c := SetIntersect(test.A, test.B)
|
|
||||||
if !reflect.DeepEqual(test.C, c) {
|
|
||||||
t.Errorf("[%d] mismatch:\nWant: %#v\nGot: %#v", i, test.C, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSetMerge(t *testing.T) {
|
func TestSetMerge(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
|
@ -295,12 +295,6 @@ func WhereClause(start int, cols []string) string {
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Substring returns a substring of str starting at index start and going
|
|
||||||
// to end-1.
|
|
||||||
func Substring(start, end int, str string) string {
|
|
||||||
return str[start:end]
|
|
||||||
}
|
|
||||||
|
|
||||||
// JoinSlices merges two string slices of equal length
|
// JoinSlices merges two string slices of equal length
|
||||||
func JoinSlices(sep string, a, b []string) []string {
|
func JoinSlices(sep string, a, b []string) []string {
|
||||||
lna, lnb := len(a), len(b)
|
lna, lnb := len(a), len(b)
|
||||||
|
|
|
@ -264,25 +264,6 @@ func TestWhereClause(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSubstring(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
str := "hello"
|
|
||||||
|
|
||||||
if got := Substring(0, 5, str); got != "hello" {
|
|
||||||
t.Errorf("substring was wrong: %q", got)
|
|
||||||
}
|
|
||||||
if got := Substring(1, 4, str); got != "ell" {
|
|
||||||
t.Errorf("substring was wrong: %q", got)
|
|
||||||
}
|
|
||||||
if got := Substring(2, 3, str); got != "l" {
|
|
||||||
t.Errorf("substring was wrong: %q", got)
|
|
||||||
}
|
|
||||||
if got := Substring(5, 5, str); got != "" {
|
|
||||||
t.Errorf("substring was wrong: %q", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJoinSlices(t *testing.T) {
|
func TestJoinSlices(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
24
templates.go
24
templates.go
|
@ -111,13 +111,7 @@ var templateStringMappers = map[string]func(string) string{
|
||||||
// String ops
|
// String ops
|
||||||
"quoteWrap": func(a string) string { return fmt.Sprintf(`"%s"`, a) },
|
"quoteWrap": func(a string) string { return fmt.Sprintf(`"%s"`, a) },
|
||||||
|
|
||||||
// Pluralization
|
|
||||||
"singular": strmangle.Singular,
|
|
||||||
"plural": strmangle.Plural,
|
|
||||||
|
|
||||||
// Casing
|
// Casing
|
||||||
"toLower": strings.ToLower,
|
|
||||||
"toUpper": strings.ToUpper,
|
|
||||||
"titleCase": strmangle.TitleCase,
|
"titleCase": strmangle.TitleCase,
|
||||||
"camelCase": strmangle.CamelCase,
|
"camelCase": strmangle.CamelCase,
|
||||||
}
|
}
|
||||||
|
@ -127,21 +121,14 @@ var templateStringMappers = map[string]func(string) string{
|
||||||
// add a function pointer here.
|
// add a function pointer here.
|
||||||
var templateFunctions = template.FuncMap{
|
var templateFunctions = template.FuncMap{
|
||||||
// String ops
|
// String ops
|
||||||
"trimPrefix": func(pre, str string) string { return strings.TrimPrefix(str, pre) },
|
"quoteWrap": func(a string) string { return fmt.Sprintf(`"%s"`, a) },
|
||||||
"remove": func(rem, str string) string { return strings.Replace(str, rem, "", -1) },
|
"id": strmangle.Identifier,
|
||||||
"replace": func(rep, with, str string) string { return strings.Replace(str, rep, with, -1) },
|
|
||||||
"prefix": func(add, str string) string { return fmt.Sprintf("%s%s", add, str) },
|
|
||||||
"quoteWrap": func(a string) string { return fmt.Sprintf(`"%s"`, a) },
|
|
||||||
"substring": strmangle.Substring,
|
|
||||||
"id": strmangle.Identifier,
|
|
||||||
|
|
||||||
// Pluralization
|
// Pluralization
|
||||||
"singular": strmangle.Singular,
|
"singular": strmangle.Singular,
|
||||||
"plural": strmangle.Plural,
|
"plural": strmangle.Plural,
|
||||||
|
|
||||||
// Casing
|
// Casing
|
||||||
"toLower": strings.ToLower,
|
|
||||||
"toUpper": strings.ToUpper,
|
|
||||||
"titleCase": strmangle.TitleCase,
|
"titleCase": strmangle.TitleCase,
|
||||||
"camelCase": strmangle.CamelCase,
|
"camelCase": strmangle.CamelCase,
|
||||||
|
|
||||||
|
@ -155,13 +142,10 @@ var templateFunctions = template.FuncMap{
|
||||||
"makeStringMap": strmangle.MakeStringMap,
|
"makeStringMap": strmangle.MakeStringMap,
|
||||||
|
|
||||||
// Set operations
|
// Set operations
|
||||||
"setInclude": strmangle.SetInclude,
|
"setInclude": strmangle.SetInclude,
|
||||||
"setIntersect": strmangle.SetIntersect,
|
|
||||||
|
|
||||||
// Database related mangling
|
// Database related mangling
|
||||||
"whereClause": strmangle.WhereClause,
|
"whereClause": strmangle.WhereClause,
|
||||||
"identQuote": strmangle.IdentQuote,
|
|
||||||
"identQuoteSlice": strmangle.IdentQuoteSlice,
|
|
||||||
|
|
||||||
// Text helpers
|
// Text helpers
|
||||||
"textsFromForeignKey": textsFromForeignKey,
|
"textsFromForeignKey": textsFromForeignKey,
|
||||||
|
|
|
@ -50,7 +50,7 @@ func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
|
||||||
}
|
}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{$varname := $rel.ForeignTable.NamePluralGo | toLower -}}
|
{{$varname := .ForeignTable | singular | camelCase -}}
|
||||||
{{$varname}}, err := a.{{$rel.Function.Name}}(tx)
|
{{$varname}}, err := a.{{$rel.Function.Name}}(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue