// 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 (
"fmt"
"reflect"
"testing"
"time"
"github.com/gohugoio/hugo/deps"
)
func TestWhere(t *testing.T) {
t.Parallel()
ns := New(&deps.Deps{})
type Mid struct {
Tst TstX
}
d1 := time.Now()
d2 := d1.Add(1 * time.Hour)
d3 := d2.Add(1 * time.Hour)
d4 := d3.Add(1 * time.Hour)
d5 := d4.Add(1 * time.Hour)
d6 := d5.Add(1 * time.Hour)
for i, test := range []struct {
seq interface{}
key interface{}
op string
match interface{}
expect interface{}
}{
{
seq: []map[int]string{
{1: "a", 2: "m"}, {1: "c", 2: "d"}, {1: "e", 3: "m"},
},
key: 2, match: "m",
expect: []map[int]string{
{1: "a", 2: "m"},
},
},
{
seq: []map[string]int{
{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "x": 4},
},
key: "b", match: 4,
expect: []map[string]int{
{"a": 3, "b": 4},
},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "x": 4},
},
key: "b", match: 4.0,
expect: []map[string]float64{{"a": 3, "b": 4}},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "x": 4},
},
key: "b", match: 4.0, op: "!=",
expect: []map[string]float64{{"a": 1, "b": 2}, {"a": 5, "x": 4}},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "x": 4},
},
key: "b", match: 4.0, op: "<",
expect: []map[string]float64{{"a": 1, "b": 2}},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a":