diff --git a/strmangle/sets.go b/strmangle/sets.go index b60dc39..d2873ec 100644 --- a/strmangle/sets.go +++ b/strmangle/sets.go @@ -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 diff --git a/strmangle/sets_test.go b/strmangle/sets_test.go index 34e5a22..88cdf68 100644 --- a/strmangle/sets_test.go +++ b/strmangle/sets_test.go @@ -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() diff --git a/strmangle/strmangle.go b/strmangle/strmangle.go index 7e2d110..4079242 100644 --- a/strmangle/strmangle.go +++ b/strmangle/strmangle.go @@ -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) diff --git a/strmangle/strmangle_test.go b/strmangle/strmangle_test.go index 3194665..bc224ca 100644 --- a/strmangle/strmangle_test.go +++ b/strmangle/strmangle_test.go @@ -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() diff --git a/templates.go b/templates.go index 2f736d6..5f402dd 100644 --- a/templates.go +++ b/templates.go @@ -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, diff --git a/templates_test/relationship_to_many.tpl b/templates_test/relationship_to_many.tpl index ae82dba..496464c 100644 --- a/templates_test/relationship_to_many.tpl +++ b/templates_test/relationship_to_many.tpl @@ -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)