mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
@@ -25,7 +25,7 @@ import (
|
||||
// Note that with 2 arguments where both are slices of the same type,
|
||||
// the first slice will be appended to the second:
|
||||
// {{ $pages = $pages | append .Site.RegularPages }}
|
||||
func (ns *Namespace) Append(args ...interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Append(args ...any) (any, error) {
|
||||
if len(args) < 2 {
|
||||
return nil, errors.New("need at least 2 arguments to append")
|
||||
}
|
||||
|
@@ -29,20 +29,20 @@ func TestAppend(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
start interface{}
|
||||
addend []interface{}
|
||||
expected interface{}
|
||||
start any
|
||||
addend []any
|
||||
expected any
|
||||
}{
|
||||
{[]string{"a", "b"}, []interface{}{"c"}, []string{"a", "b", "c"}},
|
||||
{[]string{"a", "b"}, []interface{}{"c", "d", "e"}, []string{"a", "b", "c", "d", "e"}},
|
||||
{[]string{"a", "b"}, []interface{}{[]string{"c", "d", "e"}}, []string{"a", "b", "c", "d", "e"}},
|
||||
{[]string{"a", "b"}, []any{"c"}, []string{"a", "b", "c"}},
|
||||
{[]string{"a", "b"}, []any{"c", "d", "e"}, []string{"a", "b", "c", "d", "e"}},
|
||||
{[]string{"a", "b"}, []any{[]string{"c", "d", "e"}}, []string{"a", "b", "c", "d", "e"}},
|
||||
// Errors
|
||||
{"", []interface{}{[]string{"a", "b"}}, false},
|
||||
{[]string{"a", "b"}, []interface{}{}, false},
|
||||
{"", []any{[]string{"a", "b"}}, false},
|
||||
{[]string{"a", "b"}, []any{}, false},
|
||||
// No string concatenation.
|
||||
{
|
||||
"ab",
|
||||
[]interface{}{"c"},
|
||||
[]any{"c"},
|
||||
false,
|
||||
},
|
||||
} {
|
||||
|
@@ -25,9 +25,9 @@ import (
|
||||
)
|
||||
|
||||
// Apply takes a map, array, or slice and returns a new slice with the function fname applied over it.
|
||||
func (ns *Namespace) Apply(ctx context.Context, seq interface{}, fname string, args ...interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Apply(ctx context.Context, seq any, fname string, args ...any) (any, error) {
|
||||
if seq == nil {
|
||||
return make([]interface{}, 0), nil
|
||||
return make([]any, 0), nil
|
||||
}
|
||||
|
||||
if fname == "apply" {
|
||||
@@ -47,7 +47,7 @@ func (ns *Namespace) Apply(ctx context.Context, seq interface{}, fname string, a
|
||||
|
||||
switch seqv.Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
r := make([]interface{}, seqv.Len())
|
||||
r := make([]any, seqv.Len())
|
||||
for i := 0; i < seqv.Len(); i++ {
|
||||
vv := seqv.Index(i)
|
||||
|
||||
@@ -65,10 +65,10 @@ func (ns *Namespace) Apply(ctx context.Context, seq interface{}, fname string, a
|
||||
}
|
||||
}
|
||||
|
||||
func applyFnToThis(ctx context.Context, fn, this reflect.Value, args ...interface{}) (reflect.Value, error) {
|
||||
func applyFnToThis(ctx context.Context, fn, this reflect.Value, args ...any) (reflect.Value, error) {
|
||||
num := fn.Type().NumIn()
|
||||
if num > 0 && fn.Type().In(0).Implements(hreflect.ContextInterface) {
|
||||
args = append([]interface{}{ctx}, args...)
|
||||
args = append([]any{ctx}, args...)
|
||||
}
|
||||
|
||||
n := make([]reflect.Value, len(args))
|
||||
@@ -120,7 +120,7 @@ func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) {
|
||||
return reflect.Value{}, false
|
||||
}
|
||||
|
||||
fn, ok := nv.Interface().(func(...interface{}) (interface{}, error))
|
||||
fn, ok := nv.Interface().(func(...any) (any, error))
|
||||
if !ok {
|
||||
return reflect.Value{}, false
|
||||
}
|
||||
|
@@ -48,11 +48,11 @@ func (templateFinder) LookupLayout(d output.LayoutDescriptor, f output.Format) (
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
func (templateFinder) Execute(t tpl.Template, wr io.Writer, data interface{}) error {
|
||||
func (templateFinder) Execute(t tpl.Template, wr io.Writer, data any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (templateFinder) ExecuteWithContext(ctx context.Context, t tpl.Template, wr io.Writer, data interface{}) error {
|
||||
func (templateFinder) ExecuteWithContext(ctx context.Context, t tpl.Template, wr io.Writer, data any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -71,13 +71,13 @@ func TestApply(t *testing.T) {
|
||||
d.SetTmpl(new(templateFinder))
|
||||
ns := New(d)
|
||||
|
||||
strings := []interface{}{"a\n", "b\n"}
|
||||
strings := []any{"a\n", "b\n"}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
result, err := ns.Apply(ctx, strings, "print", "a", "b", "c")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(result, qt.DeepEquals, []interface{}{"abc", "abc"})
|
||||
c.Assert(result, qt.DeepEquals, []any{"abc", "abc"})
|
||||
|
||||
_, err = ns.Apply(ctx, strings, "apply", ".")
|
||||
c.Assert(err, qt.Not(qt.IsNil))
|
||||
|
@@ -50,7 +50,7 @@ type Namespace struct {
|
||||
}
|
||||
|
||||
// After returns all the items after the first N in a rangeable list.
|
||||
func (ns *Namespace) After(index interface{}, seq interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) After(index any, seq any) (any, error) {
|
||||
if index == nil || seq == nil {
|
||||
return nil, errors.New("both limit and seq must be provided")
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func (ns *Namespace) After(index interface{}, seq interface{}) (interface{}, err
|
||||
|
||||
// Delimit takes a given sequence and returns a delimited HTML string.
|
||||
// If last is passed to the function, it will be used as the final delimiter.
|
||||
func (ns *Namespace) Delimit(seq, delimiter interface{}, last ...interface{}) (template.HTML, error) {
|
||||
func (ns *Namespace) Delimit(seq, delimiter any, last ...any) (template.HTML, error) {
|
||||
d, err := cast.ToStringE(delimiter)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -146,12 +146,12 @@ func (ns *Namespace) Delimit(seq, delimiter interface{}, last ...interface{}) (t
|
||||
// walking the parameters and treating them as key-value pairs. The number
|
||||
// of parameters must be even.
|
||||
// The keys can be string slices, which will create the needed nested structure.
|
||||
func (ns *Namespace) Dictionary(values ...interface{}) (map[string]interface{}, error) {
|
||||
func (ns *Namespace) Dictionary(values ...any) (map[string]any, error) {
|
||||
if len(values)%2 != 0 {
|
||||
return nil, errors.New("invalid dictionary call")
|
||||
}
|
||||
|
||||
root := make(map[string]interface{})
|
||||
root := make(map[string]any)
|
||||
|
||||
for i := 0; i < len(values); i += 2 {
|
||||
dict := root
|
||||
@@ -162,12 +162,12 @@ func (ns *Namespace) Dictionary(values ...interface{}) (map[string]interface{},
|
||||
case []string:
|
||||
for i := 0; i < len(v)-1; i++ {
|
||||
key = v[i]
|
||||
var m map[string]interface{}
|
||||
var m map[string]any
|
||||
v, found := dict[key]
|
||||
if found {
|
||||
m = v.(map[string]interface{})
|
||||
m = v.(map[string]any)
|
||||
} else {
|
||||
m = make(map[string]interface{})
|
||||
m = make(map[string]any)
|
||||
dict[key] = m
|
||||
}
|
||||
dict = m
|
||||
@@ -184,7 +184,7 @@ func (ns *Namespace) Dictionary(values ...interface{}) (map[string]interface{},
|
||||
|
||||
// EchoParam returns a given value if it is set; otherwise, it returns an
|
||||
// empty string.
|
||||
func (ns *Namespace) EchoParam(a, key interface{}) interface{} {
|
||||
func (ns *Namespace) EchoParam(a, key any) any {
|
||||
av, isNil := indirect(reflect.ValueOf(a))
|
||||
if isNil {
|
||||
return ""
|
||||
@@ -227,7 +227,7 @@ func (ns *Namespace) EchoParam(a, key interface{}) interface{} {
|
||||
}
|
||||
|
||||
// First returns the first N items in a rangeable list.
|
||||
func (ns *Namespace) First(limit interface{}, seq interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) First(limit any, seq any) (any, error) {
|
||||
if limit == nil || seq == nil {
|
||||
return nil, errors.New("both limit and seq must be provided")
|
||||
}
|
||||
@@ -262,7 +262,7 @@ func (ns *Namespace) First(limit interface{}, seq interface{}) (interface{}, err
|
||||
}
|
||||
|
||||
// In returns whether v is in the set l. l may be an array or slice.
|
||||
func (ns *Namespace) In(l interface{}, v interface{}) (bool, error) {
|
||||
func (ns *Namespace) In(l any, v any) (bool, error) {
|
||||
if l == nil || v == nil {
|
||||
return false, nil
|
||||
}
|
||||
@@ -301,9 +301,9 @@ func (ns *Namespace) In(l interface{}, v interface{}) (bool, error) {
|
||||
|
||||
// Intersect returns the common elements in the given sets, l1 and l2. l1 and
|
||||
// l2 must be of the same type and may be either arrays or slices.
|
||||
func (ns *Namespace) Intersect(l1, l2 interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Intersect(l1, l2 any) (any, error) {
|
||||
if l1 == nil || l2 == nil {
|
||||
return make([]interface{}, 0), nil
|
||||
return make([]any, 0), nil
|
||||
}
|
||||
|
||||
var ins *intersector
|
||||
@@ -313,19 +313,19 @@ func (ns *Namespace) Intersect(l1, l2 interface{}) (interface{}, error) {
|
||||
|
||||
switch l1v.Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
ins = &intersector{r: reflect.MakeSlice(l1v.Type(), 0, 0), seen: make(map[interface{}]bool)}
|
||||
ins = &intersector{r: reflect.MakeSlice(l1v.Type(), 0, 0), seen: make(map[any]bool)}
|
||||
switch l2v.Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
for i := 0; i < l1v.Len(); i++ {
|
||||
l1vv := l1v.Index(i)
|
||||
if !l1vv.Type().Comparable() {
|
||||
return make([]interface{}, 0), errors.New("intersect does not support slices or arrays of uncomparable types")
|
||||
return make([]any, 0), errors.New("intersect does not support slices or arrays of uncomparable types")
|
||||
}
|
||||
|
||||
for j := 0; j < l2v.Len(); j++ {
|
||||
l2vv := l2v.Index(j)
|
||||
if !l2vv.Type().Comparable() {
|
||||
return make([]interface{}, 0), errors.New("intersect does not support slices or arrays of uncomparable types")
|
||||
return make([]any, 0), errors.New("intersect does not support slices or arrays of uncomparable types")
|
||||
}
|
||||
|
||||
ins.handleValuePair(l1vv, l2vv)
|
||||
@@ -342,7 +342,7 @@ func (ns *Namespace) Intersect(l1, l2 interface{}) (interface{}, error) {
|
||||
|
||||
// Group groups a set of elements by the given key.
|
||||
// This is currently only supported for Pages.
|
||||
func (ns *Namespace) Group(key interface{}, items interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Group(key any, items any) (any, error) {
|
||||
if key == nil {
|
||||
return nil, errors.New("nil is not a valid key to group by")
|
||||
}
|
||||
@@ -362,7 +362,7 @@ func (ns *Namespace) Group(key interface{}, items interface{}) (interface{}, err
|
||||
|
||||
// IsSet returns whether a given array, channel, slice, or map has a key
|
||||
// defined.
|
||||
func (ns *Namespace) IsSet(a interface{}, key interface{}) (bool, error) {
|
||||
func (ns *Namespace) IsSet(a any, key any) (bool, error) {
|
||||
av := reflect.ValueOf(a)
|
||||
kv := reflect.ValueOf(key)
|
||||
|
||||
@@ -387,7 +387,7 @@ func (ns *Namespace) IsSet(a interface{}, key interface{}) (bool, error) {
|
||||
}
|
||||
|
||||
// Last returns the last N items in a rangeable list.
|
||||
func (ns *Namespace) Last(limit interface{}, seq interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Last(limit any, seq any) (any, error) {
|
||||
if limit == nil || seq == nil {
|
||||
return nil, errors.New("both limit and seq must be provided")
|
||||
}
|
||||
@@ -422,7 +422,7 @@ func (ns *Namespace) Last(limit interface{}, seq interface{}) (interface{}, erro
|
||||
}
|
||||
|
||||
// Querify encodes the given parameters in URL-encoded form ("bar=baz&foo=quux") sorted by key.
|
||||
func (ns *Namespace) Querify(params ...interface{}) (string, error) {
|
||||
func (ns *Namespace) Querify(params ...any) (string, error) {
|
||||
qs := url.Values{}
|
||||
|
||||
if len(params) == 1 {
|
||||
@@ -438,7 +438,7 @@ func (ns *Namespace) Querify(params ...interface{}) (string, error) {
|
||||
|
||||
return qs.Encode(), nil
|
||||
|
||||
case []interface{}:
|
||||
case []any:
|
||||
params = v
|
||||
|
||||
default:
|
||||
@@ -463,7 +463,7 @@ func (ns *Namespace) Querify(params ...interface{}) (string, error) {
|
||||
}
|
||||
|
||||
// Reverse creates a copy of slice and reverses it.
|
||||
func (ns *Namespace) Reverse(slice interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Reverse(slice any) (any, error) {
|
||||
if slice == nil {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -493,7 +493,7 @@ func (ns *Namespace) Reverse(slice interface{}) (interface{}, error) {
|
||||
// -3 => -1, -2, -3
|
||||
// 1 4 => 1, 2, 3, 4
|
||||
// 1 -2 => 1, 0, -1, -2
|
||||
func (ns *Namespace) Seq(args ...interface{}) ([]int, error) {
|
||||
func (ns *Namespace) Seq(args ...any) ([]int, error) {
|
||||
if len(args) < 1 || len(args) > 3 {
|
||||
return nil, errors.New("invalid number of arguments to Seq")
|
||||
}
|
||||
@@ -561,7 +561,7 @@ func (ns *Namespace) Seq(args ...interface{}) ([]int, error) {
|
||||
}
|
||||
|
||||
// Shuffle returns the given rangeable list in a randomised order.
|
||||
func (ns *Namespace) Shuffle(seq interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Shuffle(seq any) (any, error) {
|
||||
if seq == nil {
|
||||
return nil, errors.New("both count and seq must be provided")
|
||||
}
|
||||
@@ -591,7 +591,7 @@ func (ns *Namespace) Shuffle(seq interface{}) (interface{}, error) {
|
||||
}
|
||||
|
||||
// Slice returns a slice of all passed arguments.
|
||||
func (ns *Namespace) Slice(args ...interface{}) interface{} {
|
||||
func (ns *Namespace) Slice(args ...any) any {
|
||||
if len(args) == 0 {
|
||||
return args
|
||||
}
|
||||
@@ -601,7 +601,7 @@ func (ns *Namespace) Slice(args ...interface{}) interface{} {
|
||||
|
||||
type intersector struct {
|
||||
r reflect.Value
|
||||
seen map[interface{}]bool
|
||||
seen map[any]bool
|
||||
}
|
||||
|
||||
func (i *intersector) appendIfNotSeen(v reflect.Value) {
|
||||
@@ -638,9 +638,9 @@ func (i *intersector) handleValuePair(l1vv, l2vv reflect.Value) {
|
||||
// l2 must be of the same type and may be either arrays or slices.
|
||||
// If l1 and l2 aren't of the same type then l1 will be returned.
|
||||
// If either l1 or l2 is nil then the non-nil list will be returned.
|
||||
func (ns *Namespace) Union(l1, l2 interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Union(l1, l2 any) (any, error) {
|
||||
if l1 == nil && l2 == nil {
|
||||
return []interface{}{}, nil
|
||||
return []any{}, nil
|
||||
} else if l1 == nil && l2 != nil {
|
||||
return l2, nil
|
||||
} else if l1 != nil && l2 == nil {
|
||||
@@ -656,7 +656,7 @@ func (ns *Namespace) Union(l1, l2 interface{}) (interface{}, error) {
|
||||
case reflect.Array, reflect.Slice:
|
||||
switch l2v.Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
ins = &intersector{r: reflect.MakeSlice(l1v.Type(), 0, 0), seen: make(map[interface{}]bool)}
|
||||
ins = &intersector{r: reflect.MakeSlice(l1v.Type(), 0, 0), seen: make(map[any]bool)}
|
||||
|
||||
if l1v.Type() != l2v.Type() &&
|
||||
l1v.Type().Elem().Kind() != reflect.Interface &&
|
||||
@@ -673,7 +673,7 @@ func (ns *Namespace) Union(l1, l2 interface{}) (interface{}, error) {
|
||||
l1vv, isNil = indirectInterface(l1v.Index(i))
|
||||
|
||||
if !l1vv.Type().Comparable() {
|
||||
return []interface{}{}, errors.New("union does not support slices or arrays of uncomparable types")
|
||||
return []any{}, errors.New("union does not support slices or arrays of uncomparable types")
|
||||
}
|
||||
|
||||
if !isNil {
|
||||
@@ -721,9 +721,9 @@ func (ns *Namespace) Union(l1, l2 interface{}) (interface{}, error) {
|
||||
|
||||
// Uniq takes in a slice or array and returns a slice with subsequent
|
||||
// duplicate elements removed.
|
||||
func (ns *Namespace) Uniq(seq interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Uniq(seq any) (any, error) {
|
||||
if seq == nil {
|
||||
return make([]interface{}, 0), nil
|
||||
return make([]any, 0), nil
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(seq)
|
||||
@@ -739,7 +739,7 @@ func (ns *Namespace) Uniq(seq interface{}) (interface{}, error) {
|
||||
return nil, errors.Errorf("type %T not supported", seq)
|
||||
}
|
||||
|
||||
seen := make(map[interface{}]bool)
|
||||
seen := make(map[any]bool)
|
||||
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
ev, _ := indirectInterface(v.Index(i))
|
||||
@@ -756,7 +756,7 @@ func (ns *Namespace) Uniq(seq interface{}) (interface{}, error) {
|
||||
}
|
||||
|
||||
// KeyVals creates a key and values wrapper.
|
||||
func (ns *Namespace) KeyVals(key interface{}, vals ...interface{}) (types.KeyValues, error) {
|
||||
func (ns *Namespace) KeyVals(key any, vals ...any) (types.KeyValues, error) {
|
||||
return types.KeyValues{Key: key, Values: vals}, nil
|
||||
}
|
||||
|
||||
|
@@ -43,9 +43,9 @@ func TestAfter(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
index interface{}
|
||||
seq interface{}
|
||||
expect interface{}
|
||||
index any
|
||||
seq any
|
||||
expect any
|
||||
}{
|
||||
{int(2), []string{"a", "b", "c", "d"}, []string{"c", "d"}},
|
||||
{int32(3), []string{"a", "b"}, []string{}},
|
||||
@@ -81,7 +81,7 @@ type tstGrouper struct {
|
||||
|
||||
type tstGroupers []*tstGrouper
|
||||
|
||||
func (g tstGrouper) Group(key interface{}, items interface{}) (interface{}, error) {
|
||||
func (g tstGrouper) Group(key any, items any) (any, error) {
|
||||
ilen := reflect.ValueOf(items).Len()
|
||||
return fmt.Sprintf("%v(%d)", key, ilen), nil
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func (g tstGrouper) Group(key interface{}, items interface{}) (interface{}, erro
|
||||
type tstGrouper2 struct {
|
||||
}
|
||||
|
||||
func (g *tstGrouper2) Group(key interface{}, items interface{}) (interface{}, error) {
|
||||
func (g *tstGrouper2) Group(key any, items any) (any, error) {
|
||||
ilen := reflect.ValueOf(items).Len()
|
||||
return fmt.Sprintf("%v(%d)", key, ilen), nil
|
||||
}
|
||||
@@ -100,9 +100,9 @@ func TestGroup(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
key interface{}
|
||||
items interface{}
|
||||
expect interface{}
|
||||
key any
|
||||
items any
|
||||
expect any
|
||||
}{
|
||||
{"a", []*tstGrouper{{}, {}}, "a(2)"},
|
||||
{"b", tstGroupers{&tstGrouper{}, &tstGrouper{}}, "b(2)"},
|
||||
@@ -136,9 +136,9 @@ func TestDelimit(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
seq interface{}
|
||||
delimiter interface{}
|
||||
last interface{}
|
||||
seq any
|
||||
delimiter any
|
||||
last any
|
||||
expect template.HTML
|
||||
}{
|
||||
{[]string{"class1", "class2", "class3"}, " ", nil, "class1 class2 class3"},
|
||||
@@ -188,19 +188,19 @@ func TestDictionary(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
values []interface{}
|
||||
expect interface{}
|
||||
values []any
|
||||
expect any
|
||||
}{
|
||||
{[]interface{}{"a", "b"}, map[string]interface{}{"a": "b"}},
|
||||
{[]interface{}{[]string{"a", "b"}, "c"}, map[string]interface{}{"a": map[string]interface{}{"b": "c"}}},
|
||||
{[]any{"a", "b"}, map[string]any{"a": "b"}},
|
||||
{[]any{[]string{"a", "b"}, "c"}, map[string]any{"a": map[string]any{"b": "c"}}},
|
||||
{
|
||||
[]interface{}{[]string{"a", "b"}, "c", []string{"a", "b2"}, "c2", "b", "c"},
|
||||
map[string]interface{}{"a": map[string]interface{}{"b": "c", "b2": "c2"}, "b": "c"},
|
||||
[]any{[]string{"a", "b"}, "c", []string{"a", "b2"}, "c2", "b", "c"},
|
||||
map[string]any{"a": map[string]any{"b": "c", "b2": "c2"}, "b": "c"},
|
||||
},
|
||||
{[]interface{}{"a", 12, "b", []int{4}}, map[string]interface{}{"a": 12, "b": []int{4}}},
|
||||
{[]any{"a", 12, "b", []int{4}}, map[string]any{"a": 12, "b": []int{4}}},
|
||||
// errors
|
||||
{[]interface{}{5, "b"}, false},
|
||||
{[]interface{}{"a", "b", "c"}, false},
|
||||
{[]any{5, "b"}, false},
|
||||
{[]any{"a", "b", "c"}, false},
|
||||
} {
|
||||
i := i
|
||||
test := test
|
||||
@@ -246,9 +246,9 @@ func TestEchoParam(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
a interface{}
|
||||
key interface{}
|
||||
expect interface{}
|
||||
a any
|
||||
key any
|
||||
expect any
|
||||
}{
|
||||
{[]int{1, 2, 3}, 1, int64(2)},
|
||||
{[]uint{1, 2, 3}, 1, uint64(2)},
|
||||
@@ -260,7 +260,7 @@ func TestEchoParam(t *testing.T) {
|
||||
{map[string]float64{"foo": 1.1, "bar": 2.2, "baz": 3.3}, "bar", float64(2.2)},
|
||||
{map[string]string{"foo": "FOO", "bar": "BAR", "baz": "BAZ"}, "bar", "BAR"},
|
||||
{map[string]TstX{"foo": {A: "a", B: "b"}, "bar": {A: "c", B: "d"}, "baz": {A: "e", B: "f"}}, "bar", ""},
|
||||
{map[string]interface{}{"foo": nil}, "foo", ""},
|
||||
{map[string]any{"foo": nil}, "foo", ""},
|
||||
{(*[]string)(nil), "bar", ""},
|
||||
} {
|
||||
errMsg := qt.Commentf("[%d] %v", i, test)
|
||||
@@ -278,9 +278,9 @@ func TestFirst(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
limit interface{}
|
||||
seq interface{}
|
||||
expect interface{}
|
||||
limit any
|
||||
seq any
|
||||
expect any
|
||||
}{
|
||||
{int(2), []string{"a", "b", "c"}, []string{"a", "b"}},
|
||||
{int32(3), []string{"a", "b"}, []string{"a", "b"}},
|
||||
@@ -316,20 +316,20 @@ func TestIn(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
l1 interface{}
|
||||
l2 interface{}
|
||||
l1 any
|
||||
l2 any
|
||||
expect bool
|
||||
}{
|
||||
{[]string{"a", "b", "c"}, "b", true},
|
||||
{[]interface{}{"a", "b", "c"}, "b", true},
|
||||
{[]interface{}{"a", "b", "c"}, "d", false},
|
||||
{[]any{"a", "b", "c"}, "b", true},
|
||||
{[]any{"a", "b", "c"}, "d", false},
|
||||
{[]string{"a", "b", "c"}, "d", false},
|
||||
{[]string{"a", "12", "c"}, 12, false},
|
||||
{[]string{"a", "b", "c"}, nil, false},
|
||||
{[]int{1, 2, 4}, 2, true},
|
||||
{[]interface{}{1, 2, 4}, 2, true},
|
||||
{[]interface{}{1, 2, 4}, nil, false},
|
||||
{[]interface{}{nil}, nil, false},
|
||||
{[]any{1, 2, 4}, 2, true},
|
||||
{[]any{1, 2, 4}, nil, false},
|
||||
{[]any{nil}, nil, false},
|
||||
{[]int{1, 2, 4}, 3, false},
|
||||
{[]float64{1.23, 2.45, 4.67}, 1.23, true},
|
||||
{[]float64{1.234567, 2.45, 4.67}, 1.234568, false},
|
||||
@@ -392,16 +392,16 @@ func TestIntersect(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
l1, l2 interface{}
|
||||
expect interface{}
|
||||
l1, l2 any
|
||||
expect any
|
||||
}{
|
||||
{[]string{"a", "b", "c", "c"}, []string{"a", "b", "b"}, []string{"a", "b"}},
|
||||
{[]string{"a", "b"}, []string{"a", "b", "c"}, []string{"a", "b"}},
|
||||
{[]string{"a", "b", "c"}, []string{"d", "e"}, []string{}},
|
||||
{[]string{}, []string{}, []string{}},
|
||||
{[]string{"a", "b"}, nil, []interface{}{}},
|
||||
{nil, []string{"a", "b"}, []interface{}{}},
|
||||
{nil, nil, []interface{}{}},
|
||||
{[]string{"a", "b"}, nil, []any{}},
|
||||
{nil, []string{"a", "b"}, []any{}},
|
||||
{nil, nil, []any{}},
|
||||
{[]string{"1", "2"}, []int{1, 2}, []string{}},
|
||||
{[]int{1, 2}, []string{"1", "2"}, []int{}},
|
||||
{[]int{1, 2, 4}, []int{2, 4}, []int{2, 4}},
|
||||
@@ -410,45 +410,45 @@ func TestIntersect(t *testing.T) {
|
||||
{[]float64{2.2, 4.4}, []float64{1.1, 2.2, 4.4}, []float64{2.2, 4.4}},
|
||||
|
||||
// []interface{} ∩ []interface{}
|
||||
{[]interface{}{"a", "b", "c"}, []interface{}{"a", "b", "b"}, []interface{}{"a", "b"}},
|
||||
{[]interface{}{1, 2, 3}, []interface{}{1, 2, 2}, []interface{}{1, 2}},
|
||||
{[]interface{}{int8(1), int8(2), int8(3)}, []interface{}{int8(1), int8(2), int8(2)}, []interface{}{int8(1), int8(2)}},
|
||||
{[]interface{}{int16(1), int16(2), int16(3)}, []interface{}{int16(1), int16(2), int16(2)}, []interface{}{int16(1), int16(2)}},
|
||||
{[]interface{}{int32(1), int32(2), int32(3)}, []interface{}{int32(1), int32(2), int32(2)}, []interface{}{int32(1), int32(2)}},
|
||||
{[]interface{}{int64(1), int64(2), int64(3)}, []interface{}{int64(1), int64(2), int64(2)}, []interface{}{int64(1), int64(2)}},
|
||||
{[]interface{}{float32(1), float32(2), float32(3)}, []interface{}{float32(1), float32(2), float32(2)}, []interface{}{float32(1), float32(2)}},
|
||||
{[]interface{}{float64(1), float64(2), float64(3)}, []interface{}{float64(1), float64(2), float64(2)}, []interface{}{float64(1), float64(2)}},
|
||||
{[]any{"a", "b", "c"}, []any{"a", "b", "b"}, []any{"a", "b"}},
|
||||
{[]any{1, 2, 3}, []any{1, 2, 2}, []any{1, 2}},
|
||||
{[]any{int8(1), int8(2), int8(3)}, []any{int8(1), int8(2), int8(2)}, []any{int8(1), int8(2)}},
|
||||
{[]any{int16(1), int16(2), int16(3)}, []any{int16(1), int16(2), int16(2)}, []any{int16(1), int16(2)}},
|
||||
{[]any{int32(1), int32(2), int32(3)}, []any{int32(1), int32(2), int32(2)}, []any{int32(1), int32(2)}},
|
||||
{[]any{int64(1), int64(2), int64(3)}, []any{int64(1), int64(2), int64(2)}, []any{int64(1), int64(2)}},
|
||||
{[]any{float32(1), float32(2), float32(3)}, []any{float32(1), float32(2), float32(2)}, []any{float32(1), float32(2)}},
|
||||
{[]any{float64(1), float64(2), float64(3)}, []any{float64(1), float64(2), float64(2)}, []any{float64(1), float64(2)}},
|
||||
|
||||
// []interface{} ∩ []T
|
||||
{[]interface{}{"a", "b", "c"}, []string{"a", "b", "b"}, []interface{}{"a", "b"}},
|
||||
{[]interface{}{1, 2, 3}, []int{1, 2, 2}, []interface{}{1, 2}},
|
||||
{[]interface{}{int8(1), int8(2), int8(3)}, []int8{1, 2, 2}, []interface{}{int8(1), int8(2)}},
|
||||
{[]interface{}{int16(1), int16(2), int16(3)}, []int16{1, 2, 2}, []interface{}{int16(1), int16(2)}},
|
||||
{[]interface{}{int32(1), int32(2), int32(3)}, []int32{1, 2, 2}, []interface{}{int32(1), int32(2)}},
|
||||
{[]interface{}{int64(1), int64(2), int64(3)}, []int64{1, 2, 2}, []interface{}{int64(1), int64(2)}},
|
||||
{[]interface{}{uint(1), uint(2), uint(3)}, []uint{1, 2, 2}, []interface{}{uint(1), uint(2)}},
|
||||
{[]interface{}{float32(1), float32(2), float32(3)}, []float32{1, 2, 2}, []interface{}{float32(1), float32(2)}},
|
||||
{[]interface{}{float64(1), float64(2), float64(3)}, []float64{1, 2, 2}, []interface{}{float64(1), float64(2)}},
|
||||
{[]any{"a", "b", "c"}, []string{"a", "b", "b"}, []any{"a", "b"}},
|
||||
{[]any{1, 2, 3}, []int{1, 2, 2}, []any{1, 2}},
|
||||
{[]any{int8(1), int8(2), int8(3)}, []int8{1, 2, 2}, []any{int8(1), int8(2)}},
|
||||
{[]any{int16(1), int16(2), int16(3)}, []int16{1, 2, 2}, []any{int16(1), int16(2)}},
|
||||
{[]any{int32(1), int32(2), int32(3)}, []int32{1, 2, 2}, []any{int32(1), int32(2)}},
|
||||
{[]any{int64(1), int64(2), int64(3)}, []int64{1, 2, 2}, []any{int64(1), int64(2)}},
|
||||
{[]any{uint(1), uint(2), uint(3)}, []uint{1, 2, 2}, []any{uint(1), uint(2)}},
|
||||
{[]any{float32(1), float32(2), float32(3)}, []float32{1, 2, 2}, []any{float32(1), float32(2)}},
|
||||
{[]any{float64(1), float64(2), float64(3)}, []float64{1, 2, 2}, []any{float64(1), float64(2)}},
|
||||
|
||||
// []T ∩ []interface{}
|
||||
{[]string{"a", "b", "c"}, []interface{}{"a", "b", "b"}, []string{"a", "b"}},
|
||||
{[]int{1, 2, 3}, []interface{}{1, 2, 2}, []int{1, 2}},
|
||||
{[]int8{1, 2, 3}, []interface{}{int8(1), int8(2), int8(2)}, []int8{1, 2}},
|
||||
{[]int16{1, 2, 3}, []interface{}{int16(1), int16(2), int16(2)}, []int16{1, 2}},
|
||||
{[]int32{1, 2, 3}, []interface{}{int32(1), int32(2), int32(2)}, []int32{1, 2}},
|
||||
{[]int64{1, 2, 3}, []interface{}{int64(1), int64(2), int64(2)}, []int64{1, 2}},
|
||||
{[]float32{1, 2, 3}, []interface{}{float32(1), float32(2), float32(2)}, []float32{1, 2}},
|
||||
{[]float64{1, 2, 3}, []interface{}{float64(1), float64(2), float64(2)}, []float64{1, 2}},
|
||||
{[]string{"a", "b", "c"}, []any{"a", "b", "b"}, []string{"a", "b"}},
|
||||
{[]int{1, 2, 3}, []any{1, 2, 2}, []int{1, 2}},
|
||||
{[]int8{1, 2, 3}, []any{int8(1), int8(2), int8(2)}, []int8{1, 2}},
|
||||
{[]int16{1, 2, 3}, []any{int16(1), int16(2), int16(2)}, []int16{1, 2}},
|
||||
{[]int32{1, 2, 3}, []any{int32(1), int32(2), int32(2)}, []int32{1, 2}},
|
||||
{[]int64{1, 2, 3}, []any{int64(1), int64(2), int64(2)}, []int64{1, 2}},
|
||||
{[]float32{1, 2, 3}, []any{float32(1), float32(2), float32(2)}, []float32{1, 2}},
|
||||
{[]float64{1, 2, 3}, []any{float64(1), float64(2), float64(2)}, []float64{1, 2}},
|
||||
|
||||
// Structs
|
||||
{pagesPtr{p1, p4, p2, p3}, pagesPtr{p4, p2, p2}, pagesPtr{p4, p2}},
|
||||
{pagesVals{p1v, p4v, p2v, p3v}, pagesVals{p1v, p3v, p3v}, pagesVals{p1v, p3v}},
|
||||
{[]interface{}{p1, p4, p2, p3}, []interface{}{p4, p2, p2}, []interface{}{p4, p2}},
|
||||
{[]interface{}{p1v, p4v, p2v, p3v}, []interface{}{p1v, p3v, p3v}, []interface{}{p1v, p3v}},
|
||||
{[]any{p1, p4, p2, p3}, []any{p4, p2, p2}, []any{p4, p2}},
|
||||
{[]any{p1v, p4v, p2v, p3v}, []any{p1v, p3v, p3v}, []any{p1v, p3v}},
|
||||
{pagesPtr{p1, p4, p2, p3}, pagesPtr{}, pagesPtr{}},
|
||||
{pagesVals{}, pagesVals{p1v, p3v, p3v}, pagesVals{}},
|
||||
{[]interface{}{p1, p4, p2, p3}, []interface{}{}, []interface{}{}},
|
||||
{[]interface{}{}, []interface{}{p1v, p3v, p3v}, []interface{}{}},
|
||||
{[]any{p1, p4, p2, p3}, []any{}, []any{}},
|
||||
{[]any{}, []any{p1v, p3v, p3v}, []any{}},
|
||||
|
||||
// errors
|
||||
{"not array or slice", []string{"a"}, false},
|
||||
@@ -482,23 +482,23 @@ func TestIsSet(t *testing.T) {
|
||||
ns := newTestNs()
|
||||
|
||||
for i, test := range []struct {
|
||||
a interface{}
|
||||
key interface{}
|
||||
a any
|
||||
key any
|
||||
expect bool
|
||||
isErr bool
|
||||
}{
|
||||
{[]interface{}{1, 2, 3, 5}, 2, true, false},
|
||||
{[]interface{}{1, 2, 3, 5}, "2", true, false},
|
||||
{[]interface{}{1, 2, 3, 5}, 2.0, true, false},
|
||||
{[]any{1, 2, 3, 5}, 2, true, false},
|
||||
{[]any{1, 2, 3, 5}, "2", true, false},
|
||||
{[]any{1, 2, 3, 5}, 2.0, true, false},
|
||||
|
||||
{[]interface{}{1, 2, 3, 5}, 22, false, false},
|
||||
{[]any{1, 2, 3, 5}, 22, false, false},
|
||||
|
||||
{map[string]interface{}{"a": 1, "b": 2}, "b", true, false},
|
||||
{map[string]interface{}{"a": 1, "b": 2}, "bc", false, false},
|
||||
{map[string]any{"a": 1, "b": 2}, "b", true, false},
|
||||
{map[string]any{"a": 1, "b": 2}, "bc", false, false},
|
||||
|
||||
{time.Now(), "Day", false, false},
|
||||
{nil, "nil", false, false},
|
||||
{[]interface{}{1, 2, 3, 5}, TstX{}, false, true},
|
||||
{[]any{1, 2, 3, 5}, TstX{}, false, true},
|
||||
} {
|
||||
errMsg := qt.Commentf("[%d] %v", i, test)
|
||||
|
||||
@@ -519,9 +519,9 @@ func TestLast(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
limit interface{}
|
||||
seq interface{}
|
||||
expect interface{}
|
||||
limit any
|
||||
seq any
|
||||
expect any
|
||||
}{
|
||||
{int(2), []string{"a", "b", "c"}, []string{"b", "c"}},
|
||||
{int32(3), []string{"a", "b"}, []string{"a", "b"}},
|
||||
@@ -558,21 +558,21 @@ func TestQuerify(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
params []interface{}
|
||||
expect interface{}
|
||||
params []any
|
||||
expect any
|
||||
}{
|
||||
{[]interface{}{"a", "b"}, "a=b"},
|
||||
{[]interface{}{"a", "b", "c", "d", "f", " &"}, `a=b&c=d&f=+%26`},
|
||||
{[]interface{}{[]string{"a", "b"}}, "a=b"},
|
||||
{[]interface{}{[]string{"a", "b", "c", "d", "f", " &"}}, `a=b&c=d&f=+%26`},
|
||||
{[]interface{}{[]interface{}{"x", "y"}}, `x=y`},
|
||||
{[]interface{}{[]interface{}{"x", 5}}, `x=5`},
|
||||
{[]any{"a", "b"}, "a=b"},
|
||||
{[]any{"a", "b", "c", "d", "f", " &"}, `a=b&c=d&f=+%26`},
|
||||
{[]any{[]string{"a", "b"}}, "a=b"},
|
||||
{[]any{[]string{"a", "b", "c", "d", "f", " &"}}, `a=b&c=d&f=+%26`},
|
||||
{[]any{[]any{"x", "y"}}, `x=y`},
|
||||
{[]any{[]any{"x", 5}}, `x=5`},
|
||||
// errors
|
||||
{[]interface{}{5, "b"}, false},
|
||||
{[]interface{}{"a", "b", "c"}, false},
|
||||
{[]interface{}{[]string{"a", "b", "c"}}, false},
|
||||
{[]interface{}{[]string{"a", "b"}, "c"}, false},
|
||||
{[]interface{}{[]interface{}{"c", "d", "e"}}, false},
|
||||
{[]any{5, "b"}, false},
|
||||
{[]any{"a", "b", "c"}, false},
|
||||
{[]any{[]string{"a", "b", "c"}}, false},
|
||||
{[]any{[]string{"a", "b"}, "c"}, false},
|
||||
{[]any{[]any{"c", "d", "e"}}, false},
|
||||
} {
|
||||
errMsg := qt.Commentf("[%d] %v", i, test.params)
|
||||
|
||||
@@ -590,7 +590,7 @@ func TestQuerify(t *testing.T) {
|
||||
|
||||
func BenchmarkQuerify(b *testing.B) {
|
||||
ns := New(&deps.Deps{})
|
||||
params := []interface{}{"a", "b", "c", "d", "f", " &"}
|
||||
params := []any{"a", "b", "c", "d", "f", " &"}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
@@ -620,28 +620,28 @@ func TestSeq(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
args []interface{}
|
||||
expect interface{}
|
||||
args []any
|
||||
expect any
|
||||
}{
|
||||
{[]interface{}{-2, 5}, []int{-2, -1, 0, 1, 2, 3, 4, 5}},
|
||||
{[]interface{}{1, 2, 4}, []int{1, 3}},
|
||||
{[]interface{}{1}, []int{1}},
|
||||
{[]interface{}{3}, []int{1, 2, 3}},
|
||||
{[]interface{}{3.2}, []int{1, 2, 3}},
|
||||
{[]interface{}{0}, []int{}},
|
||||
{[]interface{}{-1}, []int{-1}},
|
||||
{[]interface{}{-3}, []int{-1, -2, -3}},
|
||||
{[]interface{}{3, -2}, []int{3, 2, 1, 0, -1, -2}},
|
||||
{[]interface{}{6, -2, 2}, []int{6, 4, 2}},
|
||||
{[]any{-2, 5}, []int{-2, -1, 0, 1, 2, 3, 4, 5}},
|
||||
{[]any{1, 2, 4}, []int{1, 3}},
|
||||
{[]any{1}, []int{1}},
|
||||
{[]any{3}, []int{1, 2, 3}},
|
||||
{[]any{3.2}, []int{1, 2, 3}},
|
||||
{[]any{0}, []int{}},
|
||||
{[]any{-1}, []int{-1}},
|
||||
{[]any{-3}, []int{-1, -2, -3}},
|
||||
{[]any{3, -2}, []int{3, 2, 1, 0, -1, -2}},
|
||||
{[]any{6, -2, 2}, []int{6, 4, 2}},
|
||||
// errors
|
||||
{[]interface{}{1, 0, 2}, false},
|
||||
{[]interface{}{1, -1, 2}, false},
|
||||
{[]interface{}{2, 1, 1}, false},
|
||||
{[]interface{}{2, 1, 1, 1}, false},
|
||||
{[]interface{}{2001}, false},
|
||||
{[]interface{}{}, false},
|
||||
{[]interface{}{0, -1000000}, false},
|
||||
{[]interface{}{tstNoStringer{}}, false},
|
||||
{[]any{1, 0, 2}, false},
|
||||
{[]any{1, -1, 2}, false},
|
||||
{[]any{2, 1, 1}, false},
|
||||
{[]any{2, 1, 1, 1}, false},
|
||||
{[]any{2001}, false},
|
||||
{[]any{}, false},
|
||||
{[]any{0, -1000000}, false},
|
||||
{[]any{tstNoStringer{}}, false},
|
||||
{nil, false},
|
||||
} {
|
||||
errMsg := qt.Commentf("[%d] %v", i, test)
|
||||
@@ -664,7 +664,7 @@ func TestShuffle(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
seq interface{}
|
||||
seq any
|
||||
success bool
|
||||
}{
|
||||
{[]string{"a", "b", "c", "d"}, true},
|
||||
@@ -735,14 +735,14 @@ func TestSlice(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
args []interface{}
|
||||
expected interface{}
|
||||
args []any
|
||||
expected any
|
||||
}{
|
||||
{[]interface{}{"a", "b"}, []string{"a", "b"}},
|
||||
{[]interface{}{}, []interface{}{}},
|
||||
{[]interface{}{nil}, []interface{}{nil}},
|
||||
{[]interface{}{5, "b"}, []interface{}{5, "b"}},
|
||||
{[]interface{}{tstNoStringer{}}, []tstNoStringer{{}}},
|
||||
{[]any{"a", "b"}, []string{"a", "b"}},
|
||||
{[]any{}, []any{}},
|
||||
{[]any{nil}, []any{nil}},
|
||||
{[]any{5, "b"}, []any{5, "b"}},
|
||||
{[]any{tstNoStringer{}}, []tstNoStringer{{}}},
|
||||
} {
|
||||
errMsg := qt.Commentf("[%d] %v", i, test.args)
|
||||
|
||||
@@ -759,12 +759,12 @@ func TestUnion(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
l1 interface{}
|
||||
l2 interface{}
|
||||
expect interface{}
|
||||
l1 any
|
||||
l2 any
|
||||
expect any
|
||||
isErr bool
|
||||
}{
|
||||
{nil, nil, []interface{}{}, false},
|
||||
{nil, nil, []any{}, false},
|
||||
{nil, []string{"a", "b"}, []string{"a", "b"}, false},
|
||||
{[]string{"a", "b"}, nil, []string{"a", "b"}, false},
|
||||
|
||||
@@ -783,36 +783,36 @@ func TestUnion(t *testing.T) {
|
||||
{[]int{2, 4}, []int{1, 2, 4}, []int{2, 4, 1}, false},
|
||||
{[]int{1, 2, 4}, []int{3, 6}, []int{1, 2, 4, 3, 6}, false},
|
||||
{[]float64{2.2, 4.4}, []float64{1.1, 2.2, 4.4}, []float64{2.2, 4.4, 1.1}, false},
|
||||
{[]interface{}{"a", "b", "c", "c"}, []interface{}{"a", "b", "b"}, []interface{}{"a", "b", "c"}, false},
|
||||
{[]any{"a", "b", "c", "c"}, []any{"a", "b", "b"}, []any{"a", "b", "c"}, false},
|
||||
|
||||
// []T ∪ []interface{}
|
||||
{[]string{"1", "2"}, []interface{}{"9"}, []string{"1", "2", "9"}, false},
|
||||
{[]int{2, 4}, []interface{}{1, 2, 4}, []int{2, 4, 1}, false},
|
||||
{[]int8{2, 4}, []interface{}{int8(1), int8(2), int8(4)}, []int8{2, 4, 1}, false},
|
||||
{[]int8{2, 4}, []interface{}{1, 2, 4}, []int8{2, 4, 1}, false},
|
||||
{[]int16{2, 4}, []interface{}{1, 2, 4}, []int16{2, 4, 1}, false},
|
||||
{[]int32{2, 4}, []interface{}{1, 2, 4}, []int32{2, 4, 1}, false},
|
||||
{[]int64{2, 4}, []interface{}{1, 2, 4}, []int64{2, 4, 1}, false},
|
||||
{[]string{"1", "2"}, []any{"9"}, []string{"1", "2", "9"}, false},
|
||||
{[]int{2, 4}, []any{1, 2, 4}, []int{2, 4, 1}, false},
|
||||
{[]int8{2, 4}, []any{int8(1), int8(2), int8(4)}, []int8{2, 4, 1}, false},
|
||||
{[]int8{2, 4}, []any{1, 2, 4}, []int8{2, 4, 1}, false},
|
||||
{[]int16{2, 4}, []any{1, 2, 4}, []int16{2, 4, 1}, false},
|
||||
{[]int32{2, 4}, []any{1, 2, 4}, []int32{2, 4, 1}, false},
|
||||
{[]int64{2, 4}, []any{1, 2, 4}, []int64{2, 4, 1}, false},
|
||||
|
||||
{[]float64{2.2, 4.4}, []interface{}{1.1, 2.2, 4.4}, []float64{2.2, 4.4, 1.1}, false},
|
||||
{[]float32{2.2, 4.4}, []interface{}{1.1, 2.2, 4.4}, []float32{2.2, 4.4, 1.1}, false},
|
||||
{[]float64{2.2, 4.4}, []any{1.1, 2.2, 4.4}, []float64{2.2, 4.4, 1.1}, false},
|
||||
{[]float32{2.2, 4.4}, []any{1.1, 2.2, 4.4}, []float32{2.2, 4.4, 1.1}, false},
|
||||
|
||||
// []interface{} ∪ []T
|
||||
{[]interface{}{"a", "b", "c", "c"}, []string{"a", "b", "d"}, []interface{}{"a", "b", "c", "d"}, false},
|
||||
{[]interface{}{}, []string{}, []interface{}{}, false},
|
||||
{[]interface{}{1, 2}, []int{2, 3}, []interface{}{1, 2, 3}, false},
|
||||
{[]interface{}{1, 2}, []int8{2, 3}, []interface{}{1, 2, 3}, false}, // 28
|
||||
{[]interface{}{uint(1), uint(2)}, []uint{2, 3}, []interface{}{uint(1), uint(2), uint(3)}, false},
|
||||
{[]interface{}{1.1, 2.2}, []float64{2.2, 3.3}, []interface{}{1.1, 2.2, 3.3}, false},
|
||||
{[]any{"a", "b", "c", "c"}, []string{"a", "b", "d"}, []any{"a", "b", "c", "d"}, false},
|
||||
{[]any{}, []string{}, []any{}, false},
|
||||
{[]any{1, 2}, []int{2, 3}, []any{1, 2, 3}, false},
|
||||
{[]any{1, 2}, []int8{2, 3}, []any{1, 2, 3}, false}, // 28
|
||||
{[]any{uint(1), uint(2)}, []uint{2, 3}, []any{uint(1), uint(2), uint(3)}, false},
|
||||
{[]any{1.1, 2.2}, []float64{2.2, 3.3}, []any{1.1, 2.2, 3.3}, false},
|
||||
|
||||
// Structs
|
||||
{pagesPtr{p1, p4}, pagesPtr{p4, p2, p2}, pagesPtr{p1, p4, p2}, false},
|
||||
{pagesVals{p1v}, pagesVals{p3v, p3v}, pagesVals{p1v, p3v}, false},
|
||||
{[]interface{}{p1, p4}, []interface{}{p4, p2, p2}, []interface{}{p1, p4, p2}, false},
|
||||
{[]interface{}{p1v}, []interface{}{p3v, p3v}, []interface{}{p1v, p3v}, false},
|
||||
{[]any{p1, p4}, []any{p4, p2, p2}, []any{p1, p4, p2}, false},
|
||||
{[]any{p1v}, []any{p3v, p3v}, []any{p1v, p3v}, false},
|
||||
// #3686
|
||||
{[]interface{}{p1v}, []interface{}{}, []interface{}{p1v}, false},
|
||||
{[]interface{}{}, []interface{}{p1v}, []interface{}{p1v}, false},
|
||||
{[]any{p1v}, []any{}, []any{p1v}, false},
|
||||
{[]any{}, []any{p1v}, []any{p1v}, false},
|
||||
{pagesPtr{p1}, pagesPtr{}, pagesPtr{p1}, false},
|
||||
{pagesVals{p1v}, pagesVals{}, pagesVals{p1v}, false},
|
||||
{pagesPtr{}, pagesPtr{p1}, pagesPtr{p1}, false},
|
||||
@@ -847,8 +847,8 @@ func TestUniq(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
ns := New(&deps.Deps{})
|
||||
for i, test := range []struct {
|
||||
l interface{}
|
||||
expect interface{}
|
||||
l any
|
||||
expect any
|
||||
isErr bool
|
||||
}{
|
||||
{[]string{"a", "b", "c"}, []string{"a", "b", "c"}, false},
|
||||
@@ -860,7 +860,7 @@ func TestUniq(t *testing.T) {
|
||||
{[]int{1, 2, 2, 3}, []int{1, 2, 3}, false},
|
||||
{[]int{1, 2, 3, 2}, []int{1, 2, 3}, false},
|
||||
{[4]int{1, 2, 3, 2}, []int{1, 2, 3}, false},
|
||||
{nil, make([]interface{}, 0), false},
|
||||
{nil, make([]any, 0), false},
|
||||
// Pointers
|
||||
{pagesPtr{p1, p2, p3, p2}, pagesPtr{p1, p2, p3}, false},
|
||||
{pagesPtr{}, pagesPtr{}, false},
|
||||
@@ -951,7 +951,7 @@ type TstXI interface {
|
||||
TstRv2() string
|
||||
}
|
||||
|
||||
func ToTstXIs(slice interface{}) []TstXI {
|
||||
func ToTstXIs(slice any) []TstXI {
|
||||
s := reflect.ValueOf(slice)
|
||||
if s.Kind() != reflect.Slice {
|
||||
return nil
|
||||
|
@@ -25,7 +25,7 @@ import (
|
||||
//
|
||||
// The reasoning behind this rather clumsy API is so we can do this in the templates:
|
||||
// {{ $c := .Pages | complement $last4 }}
|
||||
func (ns *Namespace) Complement(seqs ...interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Complement(seqs ...any) (any, error) {
|
||||
if len(seqs) < 2 {
|
||||
return nil, errors.New("complement needs at least two arguments")
|
||||
}
|
||||
|
@@ -48,27 +48,27 @@ func TestComplement(t *testing.T) {
|
||||
sp2_2 := StructWithSlicePointers{xb, xe}
|
||||
|
||||
for i, test := range []struct {
|
||||
s interface{}
|
||||
t []interface{}
|
||||
expected interface{}
|
||||
s any
|
||||
t []any
|
||||
expected any
|
||||
}{
|
||||
{[]string{"a", "b", "c"}, []interface{}{[]string{"c", "d"}}, []string{"a", "b"}},
|
||||
{[]string{"a", "b", "c"}, []interface{}{[]string{"c", "d"}, []string{"a", "b"}}, []string{}},
|
||||
{[]interface{}{"a", "b", nil}, []interface{}{[]string{"a", "d"}}, []interface{}{"b", nil}},
|
||||
{[]int{1, 2, 3, 4, 5}, []interface{}{[]int{1, 3}, []string{"a", "b"}, []int{1, 2}}, []int{4, 5}},
|
||||
{[]int{1, 2, 3, 4, 5}, []interface{}{[]int64{1, 3}}, []int{2, 4, 5}},
|
||||
{s1, []interface{}{s2}, []TstX{{A: "a"}, {A: "d"}}},
|
||||
{sp1, []interface{}{sp2}, []*StructWithSlice{xa, xd}},
|
||||
{sp1_2, []interface{}{sp2_2}, StructWithSlicePointers{xa, xd}},
|
||||
{[]string{"a", "b", "c"}, []any{[]string{"c", "d"}}, []string{"a", "b"}},
|
||||
{[]string{"a", "b", "c"}, []any{[]string{"c", "d"}, []string{"a", "b"}}, []string{}},
|
||||
{[]any{"a", "b", nil}, []any{[]string{"a", "d"}}, []any{"b", nil}},
|
||||
{[]int{1, 2, 3, 4, 5}, []any{[]int{1, 3}, []string{"a", "b"}, []int{1, 2}}, []int{4, 5}},
|
||||
{[]int{1, 2, 3, 4, 5}, []any{[]int64{1, 3}}, []int{2, 4, 5}},
|
||||
{s1, []any{s2}, []TstX{{A: "a"}, {A: "d"}}},
|
||||
{sp1, []any{sp2}, []*StructWithSlice{xa, xd}},
|
||||
{sp1_2, []any{sp2_2}, StructWithSlicePointers{xa, xd}},
|
||||
|
||||
// Errors
|
||||
{[]string{"a", "b", "c"}, []interface{}{"error"}, false},
|
||||
{"error", []interface{}{[]string{"c", "d"}, []string{"a", "b"}}, false},
|
||||
{[]string{"a", "b", "c"}, []interface{}{[][]string{{"c", "d"}}}, false},
|
||||
{[]string{"a", "b", "c"}, []any{"error"}, false},
|
||||
{"error", []any{[]string{"c", "d"}, []string{"a", "b"}}, false},
|
||||
{[]string{"a", "b", "c"}, []any{[][]string{{"c", "d"}}}, false},
|
||||
{
|
||||
[]interface{}{[][]string{{"c", "d"}}},
|
||||
[]interface{}{[]string{"c", "d"}, []string{"a", "b"}},
|
||||
[]interface{}{[][]string{{"c", "d"}}},
|
||||
[]any{[][]string{{"c", "d"}}},
|
||||
[]any{[]string{"c", "d"}, []string{"a", "b"}},
|
||||
[]any{[][]string{{"c", "d"}}},
|
||||
},
|
||||
} {
|
||||
|
||||
|
@@ -32,7 +32,7 @@ import (
|
||||
// We deviate from the stdlib due to https://github.com/golang/go/issues/14751.
|
||||
//
|
||||
// TODO(moorereason): merge upstream changes.
|
||||
func (ns *Namespace) Index(item interface{}, args ...interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Index(item any, args ...any) (any, error) {
|
||||
v := reflect.ValueOf(item)
|
||||
if !v.IsValid() {
|
||||
return nil, errors.New("index of untyped nil")
|
||||
@@ -43,7 +43,7 @@ func (ns *Namespace) Index(item interface{}, args ...interface{}) (interface{},
|
||||
return lowerm.Get(cast.ToStringSlice(args)...), nil
|
||||
}
|
||||
|
||||
var indices []interface{}
|
||||
var indices []any
|
||||
|
||||
if len(args) == 1 {
|
||||
v := reflect.ValueOf(args[0])
|
||||
|
@@ -29,28 +29,28 @@ func TestIndex(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
for i, test := range []struct {
|
||||
item interface{}
|
||||
indices []interface{}
|
||||
expect interface{}
|
||||
item any
|
||||
indices []any
|
||||
expect any
|
||||
isErr bool
|
||||
}{
|
||||
{[]int{0, 1}, []interface{}{0}, 0, false},
|
||||
{[]int{0, 1}, []interface{}{9}, nil, false}, // index out of range
|
||||
{[]int{0, 1}, []any{0}, 0, false},
|
||||
{[]int{0, 1}, []any{9}, nil, false}, // index out of range
|
||||
{[]uint{0, 1}, nil, []uint{0, 1}, false},
|
||||
{[][]int{{1, 2}, {3, 4}}, []interface{}{0, 0}, 1, false},
|
||||
{map[int]int{1: 10, 2: 20}, []interface{}{1}, 10, false},
|
||||
{map[int]int{1: 10, 2: 20}, []interface{}{0}, 0, false},
|
||||
{map[string]map[string]string{"a": {"b": "c"}}, []interface{}{"a", "b"}, "c", false},
|
||||
{[]map[string]map[string]string{{"a": {"b": "c"}}}, []interface{}{0, "a", "b"}, "c", false},
|
||||
{map[string]map[string]interface{}{"a": {"b": []string{"c", "d"}}}, []interface{}{"a", "b", 1}, "d", false},
|
||||
{map[string]map[string]string{"a": {"b": "c"}}, []interface{}{[]string{"a", "b"}}, "c", false},
|
||||
{maps.Params{"a": "av"}, []interface{}{"A"}, "av", false},
|
||||
{maps.Params{"a": map[string]interface{}{"b": "bv"}}, []interface{}{"A", "B"}, "bv", false},
|
||||
{[][]int{{1, 2}, {3, 4}}, []any{0, 0}, 1, false},
|
||||
{map[int]int{1: 10, 2: 20}, []any{1}, 10, false},
|
||||
{map[int]int{1: 10, 2: 20}, []any{0}, 0, false},
|
||||
{map[string]map[string]string{"a": {"b": "c"}}, []any{"a", "b"}, "c", false},
|
||||
{[]map[string]map[string]string{{"a": {"b": "c"}}}, []any{0, "a", "b"}, "c", false},
|
||||
{map[string]map[string]any{"a": {"b": []string{"c", "d"}}}, []any{"a", "b", 1}, "d", false},
|
||||
{map[string]map[string]string{"a": {"b": "c"}}, []any{[]string{"a", "b"}}, "c", false},
|
||||
{maps.Params{"a": "av"}, []any{"A"}, "av", false},
|
||||
{maps.Params{"a": map[string]any{"b": "bv"}}, []any{"A", "B"}, "bv", false},
|
||||
// errors
|
||||
{nil, nil, nil, true},
|
||||
{[]int{0, 1}, []interface{}{"1"}, nil, true},
|
||||
{[]int{0, 1}, []interface{}{nil}, nil, true},
|
||||
{tstNoStringer{}, []interface{}{0}, nil, true},
|
||||
{[]int{0, 1}, []any{"1"}, nil, true},
|
||||
{[]int{0, 1}, []any{nil}, nil, true},
|
||||
{tstNoStringer{}, []any{0}, nil, true},
|
||||
} {
|
||||
c.Run(fmt.Sprint(i), func(c *qt.C) {
|
||||
errMsg := qt.Commentf("[%d] %v", i, test)
|
||||
|
@@ -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.After,
|
||||
|
@@ -26,7 +26,7 @@ import (
|
||||
// Merge creates a copy of the final parameter and merges the preceding
|
||||
// parameters into it in reverse order.
|
||||
// Currently only maps are supported. Key handling is case insensitive.
|
||||
func (ns *Namespace) Merge(params ...interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Merge(params ...any) (any, error) {
|
||||
if len(params) < 2 {
|
||||
return nil, errors.New("merge requires at least two parameters")
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func (ns *Namespace) Merge(params ...interface{}) (interface{}, error) {
|
||||
}
|
||||
|
||||
// merge creates a copy of dst and merges src into it.
|
||||
func (ns *Namespace) merge(src, dst interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) merge(src, dst any) (any, error) {
|
||||
vdst, vsrc := reflect.ValueOf(dst), reflect.ValueOf(src)
|
||||
|
||||
if vdst.Kind() != reflect.Map {
|
||||
|
@@ -29,56 +29,56 @@ import (
|
||||
func TestMerge(t *testing.T) {
|
||||
ns := New(&deps.Deps{})
|
||||
|
||||
simpleMap := map[string]interface{}{"a": 1, "b": 2}
|
||||
simpleMap := map[string]any{"a": 1, "b": 2}
|
||||
|
||||
for i, test := range []struct {
|
||||
name string
|
||||
params []interface{}
|
||||
expect interface{}
|
||||
params []any
|
||||
expect any
|
||||
isErr bool
|
||||
}{
|
||||
{
|
||||
"basic",
|
||||
[]interface{}{
|
||||
map[string]interface{}{"a": 42, "c": 3},
|
||||
map[string]interface{}{"a": 1, "b": 2},
|
||||
[]any{
|
||||
map[string]any{"a": 42, "c": 3},
|
||||
map[string]any{"a": 1, "b": 2},
|
||||
},
|
||||
map[string]interface{}{"a": 1, "b": 2, "c": 3},
|
||||
map[string]any{"a": 1, "b": 2, "c": 3},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"multi",
|
||||
[]interface{}{
|
||||
map[string]interface{}{"a": 42, "c": 3, "e": 11},
|
||||
map[string]interface{}{"a": 1, "b": 2},
|
||||
map[string]interface{}{"a": 9, "c": 4, "d": 7},
|
||||
[]any{
|
||||
map[string]any{"a": 42, "c": 3, "e": 11},
|
||||
map[string]any{"a": 1, "b": 2},
|
||||
map[string]any{"a": 9, "c": 4, "d": 7},
|
||||
},
|
||||
map[string]interface{}{"a": 9, "b": 2, "c": 4, "d": 7, "e": 11},
|
||||
map[string]any{"a": 9, "b": 2, "c": 4, "d": 7, "e": 11},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"basic case insensitive",
|
||||
[]interface{}{
|
||||
map[string]interface{}{"A": 42, "c": 3},
|
||||
map[string]interface{}{"a": 1, "b": 2},
|
||||
[]any{
|
||||
map[string]any{"A": 42, "c": 3},
|
||||
map[string]any{"a": 1, "b": 2},
|
||||
},
|
||||
map[string]interface{}{"a": 1, "b": 2, "c": 3},
|
||||
map[string]any{"a": 1, "b": 2, "c": 3},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"nested",
|
||||
[]interface{}{
|
||||
map[string]interface{}{"a": 42, "c": 3, "b": map[string]interface{}{"d": 55, "e": 66, "f": 3}},
|
||||
map[string]interface{}{"a": 1, "b": map[string]interface{}{"d": 1, "e": 2}},
|
||||
[]any{
|
||||
map[string]any{"a": 42, "c": 3, "b": map[string]any{"d": 55, "e": 66, "f": 3}},
|
||||
map[string]any{"a": 1, "b": map[string]any{"d": 1, "e": 2}},
|
||||
},
|
||||
map[string]interface{}{"a": 1, "b": map[string]interface{}{"d": 1, "e": 2, "f": 3}, "c": 3},
|
||||
map[string]any{"a": 1, "b": map[string]any{"d": 1, "e": 2, "f": 3}, "c": 3},
|
||||
false,
|
||||
},
|
||||
{
|
||||
// https://github.com/gohugoio/hugo/issues/6633
|
||||
"params dst",
|
||||
[]interface{}{
|
||||
map[string]interface{}{"a": 42, "c": 3},
|
||||
[]any{
|
||||
map[string]any{"a": 42, "c": 3},
|
||||
maps.Params{"a": 1, "b": 2},
|
||||
},
|
||||
maps.Params{"a": int(1), "b": int(2), "c": int(3)},
|
||||
@@ -86,8 +86,8 @@ func TestMerge(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"params dst, upper case src",
|
||||
[]interface{}{
|
||||
map[string]interface{}{"a": 42, "C": 3},
|
||||
[]any{
|
||||
map[string]any{"a": 42, "C": 3},
|
||||
maps.Params{"a": 1, "b": 2},
|
||||
},
|
||||
maps.Params{"a": int(1), "b": int(2), "c": int(3)},
|
||||
@@ -95,26 +95,26 @@ func TestMerge(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"params src",
|
||||
[]interface{}{
|
||||
[]any{
|
||||
maps.Params{"a": 42, "c": 3},
|
||||
map[string]interface{}{"a": 1, "c": 2},
|
||||
map[string]any{"a": 1, "c": 2},
|
||||
},
|
||||
map[string]interface{}{"a": int(1), "c": int(2)},
|
||||
map[string]any{"a": int(1), "c": int(2)},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"params src, upper case dst",
|
||||
[]interface{}{
|
||||
[]any{
|
||||
maps.Params{"a": 42, "c": 3},
|
||||
map[string]interface{}{"a": 1, "C": 2},
|
||||
map[string]any{"a": 1, "C": 2},
|
||||
},
|
||||
map[string]interface{}{"a": int(1), "C": int(2)},
|
||||
map[string]any{"a": int(1), "C": int(2)},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"nested, params dst",
|
||||
[]interface{}{
|
||||
map[string]interface{}{"a": 42, "c": 3, "b": map[string]interface{}{"d": 55, "e": 66, "f": 3}},
|
||||
[]any{
|
||||
map[string]any{"a": 42, "c": 3, "b": map[string]any{"d": 55, "e": 66, "f": 3}},
|
||||
maps.Params{"a": 1, "b": maps.Params{"d": 1, "e": 2}},
|
||||
},
|
||||
maps.Params{"a": 1, "b": maps.Params{"d": 1, "e": 2, "f": 3}, "c": 3},
|
||||
@@ -123,19 +123,19 @@ func TestMerge(t *testing.T) {
|
||||
{
|
||||
// https://github.com/gohugoio/hugo/issues/7899
|
||||
"matching keys with non-map src value",
|
||||
[]interface{}{
|
||||
map[string]interface{}{"k": "v"},
|
||||
map[string]interface{}{"k": map[string]interface{}{"k2": "v2"}},
|
||||
[]any{
|
||||
map[string]any{"k": "v"},
|
||||
map[string]any{"k": map[string]any{"k2": "v2"}},
|
||||
},
|
||||
map[string]interface{}{"k": map[string]interface{}{"k2": "v2"}},
|
||||
map[string]any{"k": map[string]any{"k2": "v2"}},
|
||||
false,
|
||||
},
|
||||
{"src nil", []interface{}{nil, simpleMap}, simpleMap, false},
|
||||
{"src nil", []any{nil, simpleMap}, simpleMap, false},
|
||||
// Error cases.
|
||||
{"dst not a map", []interface{}{nil, "not a map"}, nil, true},
|
||||
{"src not a map", []interface{}{"not a map", simpleMap}, nil, true},
|
||||
{"different map types", []interface{}{map[int]interface{}{32: "a"}, simpleMap}, nil, true},
|
||||
{"all nil", []interface{}{nil, nil}, nil, true},
|
||||
{"dst not a map", []any{nil, "not a map"}, nil, true},
|
||||
{"src not a map", []any{"not a map", simpleMap}, nil, true},
|
||||
{"different map types", []any{map[int]any{32: "a"}, simpleMap}, nil, true},
|
||||
{"all nil", []any{nil, nil}, nil, true},
|
||||
} {
|
||||
|
||||
test := test
|
||||
@@ -205,9 +205,9 @@ V22 = "v22_2"
|
||||
c.Assert(
|
||||
merged,
|
||||
qt.DeepEquals,
|
||||
map[string]interface{}{
|
||||
map[string]any{
|
||||
"V1": "v1_1", "V2": "v2_2",
|
||||
"V2s": map[string]interface{}{"V21": "v21_1", "V22": "v22_2"},
|
||||
"V2s": map[string]any{"V21": "v21_1", "V22": "v22_2"},
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -215,12 +215,12 @@ V22 = "v22_2"
|
||||
func TestCaseInsensitiveMapLookup(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
m1 := reflect.ValueOf(map[string]interface{}{
|
||||
m1 := reflect.ValueOf(map[string]any{
|
||||
"a": 1,
|
||||
"B": 2,
|
||||
})
|
||||
|
||||
m2 := reflect.ValueOf(map[int]interface{}{
|
||||
m2 := reflect.ValueOf(map[int]any{
|
||||
1: 1,
|
||||
2: 2,
|
||||
})
|
||||
|
@@ -46,7 +46,7 @@ func numberToFloat(v reflect.Value) (float64, error) {
|
||||
// normalizes different numeric types if isNumber
|
||||
// or get the hash values if not Comparable (such as map or struct)
|
||||
// to make them comparable
|
||||
func normalize(v reflect.Value) interface{} {
|
||||
func normalize(v reflect.Value) any {
|
||||
k := v.Kind()
|
||||
|
||||
switch {
|
||||
@@ -67,8 +67,8 @@ func normalize(v reflect.Value) interface{} {
|
||||
|
||||
// collects identities from the slices in seqs into a set. Numeric values are normalized,
|
||||
// pointers unwrapped.
|
||||
func collectIdentities(seqs ...interface{}) (map[interface{}]bool, error) {
|
||||
seen := make(map[interface{}]bool)
|
||||
func collectIdentities(seqs ...any) (map[any]bool, error) {
|
||||
seen := make(map[any]bool)
|
||||
for _, seq := range seqs {
|
||||
v := reflect.ValueOf(seq)
|
||||
switch v.Kind() {
|
||||
@@ -167,7 +167,7 @@ func convertNumber(v reflect.Value, to reflect.Kind) (reflect.Value, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func newSliceElement(items interface{}) interface{} {
|
||||
func newSliceElement(items any) any {
|
||||
tp := reflect.TypeOf(items)
|
||||
if tp == nil {
|
||||
return nil
|
||||
|
@@ -27,7 +27,7 @@ import (
|
||||
var sortComp = compare.New(true)
|
||||
|
||||
// Sort returns a sorted sequence.
|
||||
func (ns *Namespace) Sort(seq interface{}, args ...interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Sort(seq any, args ...any) (any, error) {
|
||||
if seq == nil {
|
||||
return nil, errors.New("sequence must be provided")
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func (p pairList) Less(i, j int) bool {
|
||||
}
|
||||
|
||||
// sorts a pairList and returns a slice of sorted values
|
||||
func (p pairList) sort() interface{} {
|
||||
func (p pairList) sort() any {
|
||||
if p.SortAsc {
|
||||
sort.Sort(p)
|
||||
} else {
|
||||
|
@@ -40,10 +40,10 @@ func TestSort(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, test := range []struct {
|
||||
seq interface{}
|
||||
sortByField interface{}
|
||||
seq any
|
||||
sortByField any
|
||||
sortAsc string
|
||||
expect interface{}
|
||||
expect any
|
||||
}{
|
||||
{[]string{"class1", "class2", "class3"}, nil, "asc", []string{"class1", "class2", "class3"}},
|
||||
{[]string{"class3", "class1", "class2"}, nil, "asc", []string{"class1", "class2", "class3"}},
|
||||
@@ -205,17 +205,17 @@ func TestSort(t *testing.T) {
|
||||
},
|
||||
// interface slice with missing elements
|
||||
{
|
||||
[]interface{}{
|
||||
map[interface{}]interface{}{"Title": "Foo", "Weight": 10},
|
||||
map[interface{}]interface{}{"Title": "Bar"},
|
||||
map[interface{}]interface{}{"Title": "Zap", "Weight": 5},
|
||||
[]any{
|
||||
map[any]any{"Title": "Foo", "Weight": 10},
|
||||
map[any]any{"Title": "Bar"},
|
||||
map[any]any{"Title": "Zap", "Weight": 5},
|
||||
},
|
||||
"Weight",
|
||||
"asc",
|
||||
[]interface{}{
|
||||
map[interface{}]interface{}{"Title": "Bar"},
|
||||
map[interface{}]interface{}{"Title": "Zap", "Weight": 5},
|
||||
map[interface{}]interface{}{"Title": "Foo", "Weight": 10},
|
||||
[]any{
|
||||
map[any]any{"Title": "Bar"},
|
||||
map[any]any{"Title": "Zap", "Weight": 5},
|
||||
map[any]any{"Title": "Foo", "Weight": 10},
|
||||
},
|
||||
},
|
||||
// test boolean values
|
||||
@@ -239,7 +239,7 @@ func TestSort(t *testing.T) {
|
||||
{nil, nil, "asc", false},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("test%d", i), func(t *testing.T) {
|
||||
var result interface{}
|
||||
var result any
|
||||
var err error
|
||||
if test.sortByField == nil {
|
||||
result, err = ns.Sort(test.seq)
|
||||
|
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
// SymDiff returns the symmetric difference of s1 and s2.
|
||||
// Arguments must be either a slice or an array of comparable types.
|
||||
func (ns *Namespace) SymDiff(s2, s1 interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) SymDiff(s2, s1 any) (any, error) {
|
||||
ids1, err := collectIdentities(s1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -35,7 +35,7 @@ func (ns *Namespace) SymDiff(s2, s1 interface{}) (interface{}, error) {
|
||||
var slice reflect.Value
|
||||
var sliceElemType reflect.Type
|
||||
|
||||
for i, s := range []interface{}{s1, s2} {
|
||||
for i, s := range []any{s1, s2} {
|
||||
v := reflect.ValueOf(s)
|
||||
|
||||
switch v.Kind() {
|
||||
|
@@ -38,13 +38,13 @@ func TestSymDiff(t *testing.T) {
|
||||
sp2 := []*StructWithSlice{xb, xe}
|
||||
|
||||
for i, test := range []struct {
|
||||
s1 interface{}
|
||||
s2 interface{}
|
||||
expected interface{}
|
||||
s1 any
|
||||
s2 any
|
||||
expected any
|
||||
}{
|
||||
{[]string{"a", "x", "b", "c"}, []string{"a", "b", "y", "c"}, []string{"x", "y"}},
|
||||
{[]string{"a", "b", "c"}, []string{"a", "b", "c"}, []string{}},
|
||||
{[]interface{}{"a", "b", nil}, []interface{}{"a"}, []interface{}{"b", nil}},
|
||||
{[]any{"a", "b", nil}, []any{"a"}, []any{"b", nil}},
|
||||
{[]int{1, 2, 3}, []int{3, 4}, []int{1, 2, 4}},
|
||||
{[]int{1, 2, 3}, []int64{3, 4}, []int{1, 2, 4}},
|
||||
{s1, s2, []TstX{{A: "b"}, {A: "e"}}},
|
||||
|
@@ -24,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
// Where returns a filtered subset of a given data type.
|
||||
func (ns *Namespace) Where(seq, key interface{}, args ...interface{}) (interface{}, error) {
|
||||
func (ns *Namespace) Where(seq, key any, args ...any) (any, error) {
|
||||
seqv, isNil := indirect(reflect.ValueOf(seq))
|
||||
if isNil {
|
||||
return nil, errors.New("can't iterate over a nil value of type " + reflect.ValueOf(seq).Type().String())
|
||||
@@ -84,7 +84,7 @@ func (ns *Namespace) checkCondition(v, mv reflect.Value, op string) (bool, error
|
||||
var ivp, imvp *int64
|
||||
var fvp, fmvp *float64
|
||||
var svp, smvp *string
|
||||
var slv, slmv interface{}
|
||||
var slv, slmv any
|
||||
var ima []int64
|
||||
var fma []float64
|
||||
var sma []string
|
||||
@@ -353,7 +353,7 @@ func evaluateSubElem(obj reflect.Value, elemName string) (reflect.Value, error)
|
||||
|
||||
// parseWhereArgs parses the end arguments to the where function. Return a
|
||||
// match value and an operator, if one is defined.
|
||||
func parseWhereArgs(args ...interface{}) (mv reflect.Value, op string, err error) {
|
||||
func parseWhereArgs(args ...any) (mv reflect.Value, op string, err error) {
|
||||
switch len(args) {
|
||||
case 1:
|
||||
mv = reflect.ValueOf(args[0])
|
||||
@@ -373,7 +373,7 @@ func parseWhereArgs(args ...interface{}) (mv reflect.Value, op string, err error
|
||||
|
||||
// checkWhereArray handles the where-matching logic when the seqv value is an
|
||||
// Array or Slice.
|
||||
func (ns *Namespace) checkWhereArray(seqv, kv, mv reflect.Value, path []string, op string) (interface{}, error) {
|
||||
func (ns *Namespace) checkWhereArray(seqv, kv, mv reflect.Value, path []string, op string) (any, error) {
|
||||
rv := reflect.MakeSlice(seqv.Type(), 0, 0)
|
||||
|
||||
for i := 0; i < seqv.Len(); i++ {
|
||||
@@ -419,7 +419,7 @@ func (ns *Namespace) checkWhereArray(seqv, kv, mv reflect.Value, path []string,
|
||||
}
|
||||
|
||||
// checkWhereMap handles the where-matching logic when the seqv value is a Map.
|
||||
func (ns *Namespace) checkWhereMap(seqv, kv, mv reflect.Value, path []string, op string) (interface{}, error) {
|
||||
func (ns *Namespace) checkWhereMap(seqv, kv, mv reflect.Value, path []string, op string) (any, error) {
|
||||
rv := reflect.MakeMap(seqv.Type())
|
||||
keys := seqv.MapKeys()
|
||||
for _, k := range keys {
|
||||
|
@@ -43,11 +43,11 @@ func TestWhere(t *testing.T) {
|
||||
d6 := d5.Add(1 * time.Hour)
|
||||
|
||||
type testt struct {
|
||||
seq interface{}
|
||||
key interface{}
|
||||
seq any
|
||||
key any
|
||||
op string
|
||||
match interface{}
|
||||
expect interface{}
|
||||
match any
|
||||
expect any
|
||||
}
|
||||
|
||||
createTestVariants := func(test testt) []testt {
|
||||
@@ -150,11 +150,11 @@ func TestWhere(t *testing.T) {
|
||||
// Issue #8353
|
||||
// String type mismatch.
|
||||
{
|
||||
seq: []map[string]interface{}{
|
||||
seq: []map[string]any{
|
||||
{"a": "1", "b": "2"}, {"a": "3", "b": template.HTML("4")}, {"a": "5", "x": "4"},
|
||||
},
|
||||
key: "b", match: "4",
|
||||
expect: []map[string]interface{}{
|
||||
expect: []map[string]any{
|
||||
{"a": "3", "b": template.HTML("4")},
|
||||
},
|
||||
},
|
||||
@@ -184,9 +184,9 @@ func TestWhere(t *testing.T) {
|
||||
expect: []TstParams{{params: maps.Params{"i": 1, "color": "blue"}}, {params: maps.Params{"i": 3, "color": "blue"}}},
|
||||
},
|
||||
{
|
||||
seq: []TstParams{{params: maps.Params{"nested": map[string]interface{}{"color": "indigo"}}}, {params: maps.Params{"nested": map[string]interface{}{"color": "blue"}}}},
|
||||
seq: []TstParams{{params: maps.Params{"nested": map[string]any{"color": "indigo"}}}, {params: maps.Params{"nested": map[string]any{"color": "blue"}}}},
|
||||
key: ".Params.NEsTED.COLOR", match: "blue",
|
||||
expect: []TstParams{{params: maps.Params{"nested": map[string]interface{}{"color": "blue"}}}},
|
||||
expect: []TstParams{{params: maps.Params{"nested": map[string]any{"color": "blue"}}}},
|
||||
},
|
||||
{
|
||||
seq: []TstParams{{params: maps.Params{"i": 0, "color": "indigo"}}, {params: maps.Params{"i": 1, "color": "blue"}}, {params: maps.Params{"i": 2, "color": "green"}}, {params: maps.Params{"i": 3, "color": "blue"}}},
|
||||
@@ -206,12 +206,12 @@ func TestWhere(t *testing.T) {
|
||||
{
|
||||
seq: []maps.Params{
|
||||
{
|
||||
"a": map[string]interface{}{
|
||||
"a": map[string]any{
|
||||
"b": "b1",
|
||||
},
|
||||
},
|
||||
{
|
||||
"a": map[string]interface{}{
|
||||
"a": map[string]any{
|
||||
"b": "b2",
|
||||
},
|
||||
},
|
||||
@@ -219,7 +219,7 @@ func TestWhere(t *testing.T) {
|
||||
key: "A.B", match: "b2",
|
||||
expect: []maps.Params{
|
||||
{
|
||||
"a": map[string]interface{}{
|
||||
"a": map[string]any{
|
||||
"b": "b2",
|
||||
},
|
||||
},
|
||||
@@ -598,38 +598,38 @@ func TestWhere(t *testing.T) {
|
||||
expect: false,
|
||||
},
|
||||
{
|
||||
seq: map[string]interface{}{
|
||||
"foo": []interface{}{map[interface{}]interface{}{"a": 1, "b": 2}},
|
||||
"bar": []interface{}{map[interface{}]interface{}{"a": 3, "b": 4}},
|
||||
"zap": []interface{}{map[interface{}]interface{}{"a": 5, "b": 6}},
|
||||
seq: map[string]any{
|
||||
"foo": []any{map[any]any{"a": 1, "b": 2}},
|
||||
"bar": []any{map[any]any{"a": 3, "b": 4}},
|
||||
"zap": []any{map[any]any{"a": 5, "b": 6}},
|
||||
},
|
||||
key: "b", op: "in", match: ns.Slice(3, 4, 5),
|
||||
expect: map[string]interface{}{
|
||||
"bar": []interface{}{map[interface{}]interface{}{"a": 3, "b": 4}},
|
||||
expect: map[string]any{
|
||||
"bar": []any{map[any]any{"a": 3, "b": 4}},
|
||||
},
|
||||
},
|
||||
{
|
||||
seq: map[string]interface{}{
|
||||
"foo": []interface{}{map[interface{}]interface{}{"a": 1, "b": 2}},
|
||||
"bar": []interface{}{map[interface{}]interface{}{"a": 3, "b": 4}},
|
||||
"zap": []interface{}{map[interface{}]interface{}{"a": 5, "b": 6}},
|
||||
seq: map[string]any{
|
||||
"foo": []any{map[any]any{"a": 1, "b": 2}},
|
||||
"bar": []any{map[any]any{"a": 3, "b": 4}},
|
||||
"zap": []any{map[any]any{"a": 5, "b": 6}},
|
||||
},
|
||||
key: "b", op: ">", match: 3,
|
||||
expect: map[string]interface{}{
|
||||
"bar": []interface{}{map[interface{}]interface{}{"a": 3, "b": 4}},
|
||||
"zap": []interface{}{map[interface{}]interface{}{"a": 5, "b": 6}},
|
||||
expect: map[string]any{
|
||||
"bar": []any{map[any]any{"a": 3, "b": 4}},
|
||||
"zap": []any{map[any]any{"a": 5, "b": 6}},
|
||||
},
|
||||
},
|
||||
{
|
||||
seq: map[string]interface{}{
|
||||
"foo": []interface{}{maps.Params{"a": 1, "b": 2}},
|
||||
"bar": []interface{}{maps.Params{"a": 3, "b": 4}},
|
||||
"zap": []interface{}{maps.Params{"a": 5, "b": 6}},
|
||||
seq: map[string]any{
|
||||
"foo": []any{maps.Params{"a": 1, "b": 2}},
|
||||
"bar": []any{maps.Params{"a": 3, "b": 4}},
|
||||
"zap": []any{maps.Params{"a": 5, "b": 6}},
|
||||
},
|
||||
key: "B", op: ">", match: 3,
|
||||
expect: map[string]interface{}{
|
||||
"bar": []interface{}{maps.Params{"a": 3, "b": 4}},
|
||||
"zap": []interface{}{maps.Params{"a": 5, "b": 6}},
|
||||
expect: map[string]any{
|
||||
"bar": []any{maps.Params{"a": 3, "b": 4}},
|
||||
"zap": []any{maps.Params{"a": 5, "b": 6}},
|
||||
},
|
||||
},
|
||||
} {
|
||||
@@ -639,7 +639,7 @@ func TestWhere(t *testing.T) {
|
||||
name := fmt.Sprintf("%d/%d %T %s %s", i, j, test.seq, test.op, test.key)
|
||||
name = strings.ReplaceAll(name, "[]", "slice-of-")
|
||||
t.Run(name, func(t *testing.T) {
|
||||
var results interface{}
|
||||
var results any
|
||||
var err error
|
||||
|
||||
if len(test.op) > 0 {
|
||||
@@ -788,10 +788,10 @@ func TestCheckCondition(t *testing.T) {
|
||||
{reflect.ValueOf(123), reflect.ValueOf(123), "op", expect{false, true}},
|
||||
|
||||
// Issue #3718
|
||||
{reflect.ValueOf([]interface{}{"a"}), reflect.ValueOf([]string{"a", "b"}), "intersect", expect{true, false}},
|
||||
{reflect.ValueOf([]string{"a"}), reflect.ValueOf([]interface{}{"a", "b"}), "intersect", expect{true, false}},
|
||||
{reflect.ValueOf([]interface{}{1, 2}), reflect.ValueOf([]int{1}), "intersect", expect{true, false}},
|
||||
{reflect.ValueOf([]int{1}), reflect.ValueOf([]interface{}{1, 2}), "intersect", expect{true, false}},
|
||||
{reflect.ValueOf([]any{"a"}), reflect.ValueOf([]string{"a", "b"}), "intersect", expect{true, false}},
|
||||
{reflect.ValueOf([]string{"a"}), reflect.ValueOf([]any{"a", "b"}), "intersect", expect{true, false}},
|
||||
{reflect.ValueOf([]any{1, 2}), reflect.ValueOf([]int{1}), "intersect", expect{true, false}},
|
||||
{reflect.ValueOf([]int{1}), reflect.ValueOf([]any{1, 2}), "intersect", expect{true, false}},
|
||||
} {
|
||||
result, err := ns.checkCondition(test.value, test.match, test.op)
|
||||
if test.expect.isError {
|
||||
@@ -822,7 +822,7 @@ func TestEvaluateSubElem(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
value reflect.Value
|
||||
key string
|
||||
expect interface{}
|
||||
expect any
|
||||
}{
|
||||
{reflect.ValueOf(tstx), "A", "foo"},
|
||||
{reflect.ValueOf(&tstx), "TstRp", "rfoo"},
|
||||
|
Reference in New Issue
Block a user