tpl/collections: Add float64 support to where

Fixes #5466
This commit is contained in:
Cameron Moore
2018-11-26 18:40:35 -06:00
committed by Bjørn Erik Pedersen
parent 94ab125b27
commit 112461fded
2 changed files with 145 additions and 15 deletions

View File

@@ -63,6 +63,48 @@ func TestWhere(t *testing.T) {
{"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": 5, "x": 4},
},
key: "b", match: 4.0, op: "<=",
expect: []map[string]float64{{"a": 1, "b": 2}, {"a": 3, "b": 4}},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3, "b": 3}, {"a": 5, "x": 4},
},
key: "b", match: 2.0, op: ">",
expect: []map[string]float64{{"a": 3, "b": 3}},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3, "b": 3}, {"a": 5, "x": 4},
},
key: "b", match: 2.0, op: ">=",
expect: []map[string]float64{{"a": 1, "b": 2}, {"a": 3, "b": 3}},
},
{
seq: []TstX{
{A: "a", B: "b"}, {A: "c", B: "d"}, {A: "e", B: "f"},
@@ -180,6 +222,15 @@ func TestWhere(t *testing.T) {
{"a": 3, "b": 4}, {"a": 5, "b": 6},
},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "b": 6},
},
key: "b", op: ">", match: 3.0,
expect: []map[string]float64{
{"a": 3, "b": 4}, {"a": 5, "b": 6},
},
},
{
seq: []TstX{
{A: "a", B: "b"}, {A: "c", B: "d"}, {A: "e", B: "f"},
@@ -198,6 +249,15 @@ func TestWhere(t *testing.T) {
{"a": 3, "b": 4},
},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "b": 6},
},
key: "b", op: "in", match: []float64{3, 4, 5},
expect: []map[string]float64{
{"a": 3, "b": 4},
},
},
{
seq: []map[string][]string{
{"a": []string{"A", "B", "C"}, "b": []string{"D", "E", "F"}}, {"a": []string{"G", "H", "I"}, "b": []string{"J", "K", "L"}}, {"a": []string{"M", "N", "O"}, "b": []string{"P", "Q", "R"}},
@@ -279,6 +339,15 @@ func TestWhere(t *testing.T) {
{"a": 3, "b": 4},
},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "b": 6},
},
key: "b", op: "in", match: ns.Slice(3.0, 4.0, 5.0),
expect: []map[string]float64{
{"a": 3, "b": 4},
},
},
{
seq: []map[string]time.Time{
{"a": d1, "b": d2}, {"a": d3, "b": d4}, {"a": d5, "b": d6},
@@ -331,6 +400,31 @@ func TestWhere(t *testing.T) {
key: "b", op: ">", match: nil,
expect: []map[string]int{},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3}, {"a": 5, "b": 6},
},
key: "b", op: "", match: nil,
expect: []map[string]float64{
{"a": 3},
},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3}, {"a": 5, "b": 6},
},
key: "b", op: "!=", match: nil,
expect: []map[string]float64{
{"a": 1, "b": 2}, {"a": 5, "b": 6},
},
},
{
seq: []map[string]float64{
{"a": 1, "b": 2}, {"a": 3}, {"a": 5, "b": 6},
},
key: "b", op: ">", match: nil,
expect: []map[string]float64{},
},
{
seq: []map[string]bool{
{"a": true, "b": false}, {"c": true, "b": true}, {"d": true, "b": false},