all: gofmt -w -r 'interface{} -> any' .

Updates #9687
This commit is contained in:
Bjørn Erik Pedersen
2022-03-17 22:03:27 +01:00
parent 423594e03a
commit b80853de90
342 changed files with 2118 additions and 2102 deletions

View File

@@ -40,7 +40,7 @@ type Namespace struct {
// is not. "Set" in this context means non-zero for numeric types and times;
// non-zero length for strings, arrays, slices, and maps;
// any boolean or struct value; or non-nil for any other types.
func (*Namespace) Default(dflt interface{}, given ...interface{}) (interface{}, error) {
func (*Namespace) Default(dflt any, given ...any) (any, error) {
// given is variadic because the following construct will not pass a piped
// argument when the key is missing: {{ index . "key" | default "foo" }}
// The Go template will complain that we got 1 argument when we expected 2.
@@ -91,12 +91,12 @@ func (*Namespace) Default(dflt interface{}, given ...interface{}) (interface{},
}
// Eq returns the boolean truth of arg1 == arg2 || arg1 == arg3 || arg1 == arg4.
func (n *Namespace) Eq(first interface{}, others ...interface{}) bool {
func (n *Namespace) Eq(first any, others ...any) bool {
if n.caseInsensitive {
panic("caseInsensitive not implemented for Eq")
}
n.checkComparisonArgCount(1, others...)
normalize := func(v interface{}) interface{} {
normalize := func(v any) any {
if types.IsNil(v) {
return nil
}
@@ -141,7 +141,7 @@ func (n *Namespace) Eq(first interface{}, others ...interface{}) bool {
}
// Ne returns the boolean truth of arg1 != arg2 && arg1 != arg3 && arg1 != arg4.
func (n *Namespace) Ne(first interface{}, others ...interface{}) bool {
func (n *Namespace) Ne(first any, others ...any) bool {
n.checkComparisonArgCount(1, others...)
for _, other := range others {
if n.Eq(first, other) {
@@ -152,7 +152,7 @@ func (n *Namespace) Ne(first interface{}, others ...interface{}) bool {
}
// Ge returns the boolean truth of arg1 >= arg2 && arg1 >= arg3 && arg1 >= arg4.
func (n *Namespace) Ge(first interface{}, others ...interface{}) bool {
func (n *Namespace) Ge(first any, others ...any) bool {
n.checkComparisonArgCount(1, others...)
for _, other := range others {
left, right := n.compareGet(first, other)
@@ -164,7 +164,7 @@ func (n *Namespace) Ge(first interface{}, others ...interface{}) bool {
}
// Gt returns the boolean truth of arg1 > arg2 && arg1 > arg3 && arg1 > arg4.
func (n *Namespace) Gt(first interface{}, others ...interface{}) bool {
func (n *Namespace) Gt(first any, others ...any) bool {
n.checkComparisonArgCount(1, others...)
for _, other := range others {
left, right := n.compareGet(first, other)
@@ -176,7 +176,7 @@ func (n *Namespace) Gt(first interface{}, others ...interface{}) bool {
}
// Le returns the boolean truth of arg1 <= arg2 && arg1 <= arg3 && arg1 <= arg4.
func (n *Namespace) Le(first interface{}, others ...interface{}) bool {
func (n *Namespace) Le(first any, others ...any) bool {
n.checkComparisonArgCount(1, others...)
for _, other := range others {
left, right := n.compareGet(first, other)
@@ -188,7 +188,7 @@ func (n *Namespace) Le(first interface{}, others ...interface{}) bool {
}
// Lt returns the boolean truth of arg1 < arg2 && arg1 < arg3 && arg1 < arg4.
func (n *Namespace) Lt(first interface{}, others ...interface{}) bool {
func (n *Namespace) Lt(first any, others ...any) bool {
n.checkComparisonArgCount(1, others...)
for _, other := range others {
left, right := n.compareGet(first, other)
@@ -199,7 +199,7 @@ func (n *Namespace) Lt(first interface{}, others ...interface{}) bool {
return true
}
func (n *Namespace) checkComparisonArgCount(min int, others ...interface{}) bool {
func (n *Namespace) checkComparisonArgCount(min int, others ...any) bool {
if len(others) < min {
panic("missing arguments for comparison")
}
@@ -208,14 +208,14 @@ func (n *Namespace) checkComparisonArgCount(min int, others ...interface{}) bool
// Conditional can be used as a ternary operator.
// It returns a if condition, else b.
func (n *Namespace) Conditional(condition bool, a, b interface{}) interface{} {
func (n *Namespace) Conditional(condition bool, a, b any) any {
if condition {
return a
}
return b
}
func (ns *Namespace) compareGet(a interface{}, b interface{}) (float64, float64) {
func (ns *Namespace) compareGet(a any, b any) (float64, float64) {
if ac, ok := a.(compare.Comparer); ok {
c := ac.Compare(b)
if c < 0 {

View File

@@ -49,7 +49,7 @@ type (
tstEqerType2 string
)
func (t tstEqerType2) Eq(other interface{}) bool {
func (t tstEqerType2) Eq(other any) bool {
return cast.ToString(t) == cast.ToString(other)
}
@@ -57,7 +57,7 @@ func (t tstEqerType2) String() string {
return string(t)
}
func (t tstEqerType1) Eq(other interface{}) bool {
func (t tstEqerType1) Eq(other any) bool {
return cast.ToString(t) == cast.ToString(other)
}
@@ -91,9 +91,9 @@ func TestDefaultFunc(t *testing.T) {
ns := New(false)
for i, test := range []struct {
dflt interface{}
given interface{}
expect interface{}
dflt any
given any
expect any
}{
{true, false, false},
{"5", 0, "5"},
@@ -149,33 +149,33 @@ func TestCompare(t *testing.T) {
n := New(false)
twoEq := func(a, b interface{}) bool {
twoEq := func(a, b any) bool {
return n.Eq(a, b)
}
twoGt := func(a, b interface{}) bool {
twoGt := func(a, b any) bool {
return n.Gt(a, b)
}
twoLt := func(a, b interface{}) bool {
twoLt := func(a, b any) bool {
return n.Lt(a, b)
}
twoGe := func(a, b interface{}) bool {
twoGe := func(a, b any) bool {
return n.Ge(a, b)
}
twoLe := func(a, b interface{}) bool {
twoLe := func(a, b any) bool {
return n.Le(a, b)
}
twoNe := func(a, b interface{}) bool {
twoNe := func(a, b any) bool {
return n.Ne(a, b)
}
for _, test := range []struct {
tstCompareType
funcUnderTest func(a, b interface{}) bool
funcUnderTest func(a, b any) bool
}{
{tstGt, twoGt},
{tstLt, twoLt},
@@ -188,10 +188,10 @@ func TestCompare(t *testing.T) {
}
}
func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b interface{}) bool) {
func doTestCompare(t *testing.T, tp tstCompareType, funcUnderTest func(a, b any) bool) {
for i, test := range []struct {
left interface{}
right interface{}
left any
right any
expectIndicator int
}{
{5, 8, -1},
@@ -272,16 +272,16 @@ func TestEqualExtend(t *testing.T) {
ns := New(false)
for _, test := range []struct {
first interface{}
others []interface{}
first any
others []any
expect bool
}{
{1, []interface{}{1, 2}, true},
{1, []interface{}{2, 1}, true},
{1, []interface{}{2, 3}, false},
{tstEqerType1("a"), []interface{}{tstEqerType1("a"), tstEqerType1("b")}, true},
{tstEqerType1("a"), []interface{}{tstEqerType1("b"), tstEqerType1("a")}, true},
{tstEqerType1("a"), []interface{}{tstEqerType1("b"), tstEqerType1("c")}, false},
{1, []any{1, 2}, true},
{1, []any{2, 1}, true},
{1, []any{2, 3}, false},
{tstEqerType1("a"), []any{tstEqerType1("a"), tstEqerType1("b")}, true},
{tstEqerType1("a"), []any{tstEqerType1("b"), tstEqerType1("a")}, true},
{tstEqerType1("a"), []any{tstEqerType1("b"), tstEqerType1("c")}, false},
} {
result := ns.Eq(test.first, test.others...)
@@ -297,13 +297,13 @@ func TestNotEqualExtend(t *testing.T) {
ns := New(false)
for _, test := range []struct {
first interface{}
others []interface{}
first any
others []any
expect bool
}{
{1, []interface{}{2, 3}, true},
{1, []interface{}{2, 1}, false},
{1, []interface{}{1, 2}, false},
{1, []any{2, 3}, true},
{1, []any{2, 1}, false},
{1, []any{1, 2}, false},
} {
result := ns.Ne(test.first, test.others...)
c.Assert(result, qt.Equals, test.expect)
@@ -317,14 +317,14 @@ func TestGreaterEqualExtend(t *testing.T) {
ns := New(false)
for _, test := range []struct {
first interface{}
others []interface{}
first any
others []any
expect bool
}{
{5, []interface{}{2, 3}, true},
{5, []interface{}{5, 5}, true},
{3, []interface{}{4, 2}, false},
{3, []interface{}{2, 4}, false},
{5, []any{2, 3}, true},
{5, []any{5, 5}, true},
{3, []any{4, 2}, false},
{3, []any{2, 4}, false},
} {
result := ns.Ge(test.first, test.others...)
c.Assert(result, qt.Equals, test.expect)
@@ -338,13 +338,13 @@ func TestGreaterThanExtend(t *testing.T) {
ns := New(false)
for _, test := range []struct {
first interface{}
others []interface{}
first any
others []any
expect bool
}{
{5, []interface{}{2, 3}, true},
{5, []interface{}{5, 4}, false},
{3, []interface{}{4, 2}, false},
{5, []any{2, 3}, true},
{5, []any{5, 4}, false},
{3, []any{4, 2}, false},
} {
result := ns.Gt(test.first, test.others...)
c.Assert(result, qt.Equals, test.expect)
@@ -358,14 +358,14 @@ func TestLessEqualExtend(t *testing.T) {
ns := New(false)
for _, test := range []struct {
first interface{}
others []interface{}
first any
others []any
expect bool
}{
{1, []interface{}{2, 3}, true},
{1, []interface{}{1, 2}, true},
{2, []interface{}{1, 2}, false},
{3, []interface{}{2, 4}, false},
{1, []any{2, 3}, true},
{1, []any{1, 2}, true},
{2, []any{1, 2}, false},
{3, []any{2, 4}, false},
} {
result := ns.Le(test.first, test.others...)
c.Assert(result, qt.Equals, test.expect)
@@ -379,14 +379,14 @@ func TestLessThanExtend(t *testing.T) {
ns := New(false)
for _, test := range []struct {
first interface{}
others []interface{}
first any
others []any
expect bool
}{
{1, []interface{}{2, 3}, true},
{1, []interface{}{1, 2}, false},
{2, []interface{}{1, 2}, false},
{3, []interface{}{2, 4}, false},
{1, []any{2, 3}, true},
{1, []any{1, 2}, false},
{2, []any{1, 2}, false},
{3, []any{2, 4}, false},
} {
result := ns.Lt(test.first, test.others...)
c.Assert(result, qt.Equals, test.expect)

View File

@@ -26,7 +26,7 @@ func init() {
ns := &internal.TemplateFuncsNamespace{
Name: name,
Context: func(args ...interface{}) (interface{}, error) { return ctx, nil },
Context: func(args ...any) (any, error) { return ctx, nil },
}
ns.AddMethodMapping(ctx.Default,