// Copyright 2017 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package collections
import (
"errors"
"fmt"
"html/template"
"io/ioutil"
"log"
"math/rand"
"os"
"reflect"
"testing"
"time"
"github.com/gohugoio/hugo/common/collections"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/langs"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type tstNoStringer struct{}
func TestAfter(t *testing.T) {
t.Parallel()
ns := New(&deps.Deps{})
for i, test := range []struct {
index interface{}
seq interface{}
expect interface{}
}{
{int(2), []string{"a", "b", "c", "d"}, []string{"c", "d"}},
{int32(3), []string{"a", "b"}, []string{}},
{int64(2), []int{100, 200, 300}, []int{300}},
{100, []int{100, 200}, []int{}},
{"1", []int{100, 200, 300}, []int{200, 300}},
{int64(-1), []int{100, 200, 300}, false},
{"noint", []int{100, 200, 300}, false},
{2, []string{}, []string{}},
{1, nil, false},
{nil, []int{100}, false},
{1, t, false},
{1, (*string)(nil), false},
} {
errMsg := fmt.Sprintf("[%d] %v", i, test)
result, err := ns.After(test.index, test.seq)
if b, ok := test.expect.(bool); ok && !b {
require.Error(t, err, errMsg)
continue
}
require.NoError(t, err, errMsg)
require.Equal(t, test.expect, result, errMsg)
}
}
type tstGrouper struct {
}
type tstGroupers []*tstGrouper
func (g tstGrouper) Group(key interface{}, items interface{}) (interface{}, error) {
ilen := reflect.ValueOf(items).Len()
return fmt.Sprintf("%v(%d)", key, ilen), nil
}
type tstGrouper2 struct {
}
func (g *tstGrouper2) Group(key interface{}, items interface{}) (interface{}, error) {
ilen := reflect.ValueOf(items).Len()
return fmt.Sprintf("%v(%d)", key,