Remove unused code from templates

This commit is contained in:
Aaron L 2016-08-14 00:43:30 -07:00
parent b34a8e3212
commit c278bb6667
6 changed files with 5 additions and 104 deletions

View file

@ -69,26 +69,6 @@ func SetComplement(a []string, b []string) []string {
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
func SetMerge(a []string, b []string) []string {
var x, merged []string

View file

@ -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) {
t.Parallel()

View file

@ -295,12 +295,6 @@ func WhereClause(start int, cols []string) 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
func JoinSlices(sep string, a, b []string) []string {
lna, lnb := len(a), len(b)

View file

@ -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) {
t.Parallel()

View file

@ -111,13 +111,7 @@ var templateStringMappers = map[string]func(string) string{
// String ops
"quoteWrap": func(a string) string { return fmt.Sprintf(`"%s"`, a) },
// Pluralization
"singular": strmangle.Singular,
"plural": strmangle.Plural,
// Casing
"toLower": strings.ToLower,
"toUpper": strings.ToUpper,
"titleCase": strmangle.TitleCase,
"camelCase": strmangle.CamelCase,
}
@ -127,21 +121,14 @@ var templateStringMappers = map[string]func(string) string{
// add a function pointer here.
var templateFunctions = template.FuncMap{
// String ops
"trimPrefix": func(pre, str string) string { return strings.TrimPrefix(str, pre) },
"remove": func(rem, str string) string { return strings.Replace(str, rem, "", -1) },
"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,
"quoteWrap": func(a string) string { return fmt.Sprintf(`"%s"`, a) },
"id": strmangle.Identifier,
// Pluralization
"singular": strmangle.Singular,
"plural": strmangle.Plural,
// Casing
"toLower": strings.ToLower,
"toUpper": strings.ToUpper,
"titleCase": strmangle.TitleCase,
"camelCase": strmangle.CamelCase,
@ -155,13 +142,10 @@ var templateFunctions = template.FuncMap{
"makeStringMap": strmangle.MakeStringMap,
// Set operations
"setInclude": strmangle.SetInclude,
"setIntersect": strmangle.SetIntersect,
"setInclude": strmangle.SetInclude,
// Database related mangling
"whereClause": strmangle.WhereClause,
"identQuote": strmangle.IdentQuote,
"identQuoteSlice": strmangle.IdentQuoteSlice,
"whereClause": strmangle.WhereClause,
// Text helpers
"textsFromForeignKey": textsFromForeignKey,

View file

@ -50,7 +50,7 @@ func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
}
{{end}}
{{$varname := $rel.ForeignTable.NamePluralGo | toLower -}}
{{$varname := .ForeignTable | singular | camelCase -}}
{{$varname}}, err := a.{{$rel.Function.Name}}(tx)
if err != nil {
t.Fatal(err)