Skip to content

Commit

Permalink
Add arrays with NaN, double and nested empty array to tests' shar…
Browse files Browse the repository at this point in the history
…ed data (#728)

This PR provides additional examples for tests' shared data composites. 

These examples will help to cover more test cases. 
For example, they are helpful for #724.
Also, `array-empty-nested` reveals a bug described in #732.
  • Loading branch information
rumyantseva committed Jun 10, 2022
1 parent a2eb5a4 commit 2354780
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 34 deletions.
8 changes: 4 additions & 4 deletions integration/query_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestQueryArrayDotNotation(t *testing.T) {
},
"PositionIndexAtTheEndOfArray": {
filter: bson.D{{"value.1", bson.D{{"$type", "double"}}}},
expectedIDs: []any{},
expectedIDs: []any{"array-two"},
},

"PositionTypeNull": {
Expand Down Expand Up @@ -244,7 +244,7 @@ func TestQueryElemMatchOperator(t *testing.T) {
},
"GtZero": {
filter: bson.D{{"value", bson.D{{"$elemMatch", bson.D{{"$gt", int32(0)}}}}}},
expectedIDs: []any{"array", "array-three", "array-three-reverse"},
expectedIDs: []any{"array", "array-three", "array-three-reverse", "array-two"},
},
"GtZeroWithTypeArray": {
filter: bson.D{
Expand All @@ -255,7 +255,7 @@ func TestQueryElemMatchOperator(t *testing.T) {
{"$type", "array"},
}},
},
expectedIDs: []any{"array", "array-three", "array-three-reverse"},
expectedIDs: []any{"array", "array-three", "array-three-reverse", "array-two"},
},
"GtZeroWithTypeString": {
filter: bson.D{
Expand All @@ -277,7 +277,7 @@ func TestQueryElemMatchOperator(t *testing.T) {
}},
}},
},
expectedIDs: []any{"array", "array-three", "array-three-reverse"},
expectedIDs: []any{"array", "array-three", "array-three-reverse", "array-two"},
},

"UnexpectedFilterString": {
Expand Down
42 changes: 22 additions & 20 deletions integration/query_comparison_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestQueryComparisonImplicit(t *testing.T) {

"Double": {
filter: bson.D{{"value", 42.13}},
expectedIDs: []any{"double"},
expectedIDs: []any{"array-two", "double"},
},
"DoubleNegativeInfinity": {
filter: bson.D{{"value", math.Inf(-1)}},
Expand All @@ -135,7 +135,7 @@ func TestQueryComparisonImplicit(t *testing.T) {
},
"DoubleNaN": {
filter: bson.D{{"value", math.NaN()}},
expectedIDs: []any{"double-nan"},
expectedIDs: []any{"array-two", "double-nan"},
},

"String": {
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestQueryComparisonImplicit(t *testing.T) {
"NoSuchFieldNull": {
filter: bson.D{{"no-such-field", nil}},
expectedIDs: []any{
"array", "array-embedded", "array-empty", "array-null", "array-three", "array-three-reverse",
"array", "array-embedded", "array-empty", "array-null", "array-three", "array-three-reverse", "array-two",
"binary", "binary-empty",
"bool-false", "bool-true",
"datetime", "datetime-epoch", "datetime-year-max", "datetime-year-min",
Expand Down Expand Up @@ -287,7 +287,7 @@ func TestQueryComparisonEq(t *testing.T) {

"Double": {
filter: bson.D{{"value", bson.D{{"$eq", 42.13}}}},
expectedIDs: []any{"double"},
expectedIDs: []any{"array-two", "double"},
},
"DoubleWhole": {
filter: bson.D{{"value", bson.D{{"$eq", 42.0}}}},
Expand Down Expand Up @@ -319,7 +319,7 @@ func TestQueryComparisonEq(t *testing.T) {
},
"DoubleNaN": {
filter: bson.D{{"value", bson.D{{"$eq", math.NaN()}}}},
expectedIDs: []any{"double-nan"},
expectedIDs: []any{"array-two", "double-nan"},
},
"DoubleBigInt64": {
filter: bson.D{{"value", bson.D{{"$eq", float64(2 << 61)}}}},
Expand Down Expand Up @@ -467,7 +467,7 @@ func TestQueryComparisonEq(t *testing.T) {
"NoSuchFieldNull": {
filter: bson.D{{"no-such-field", bson.D{{"$eq", nil}}}},
expectedIDs: []any{
"array", "array-embedded", "array-empty", "array-null", "array-three", "array-three-reverse",
"array", "array-embedded", "array-empty", "array-null", "array-three", "array-three-reverse", "array-two",
"binary", "binary-empty",
"bool-false", "bool-true",
"datetime", "datetime-epoch", "datetime-year-max", "datetime-year-min",
Expand Down Expand Up @@ -514,7 +514,7 @@ func TestQueryComparisonGt(t *testing.T) {
"Double": {
value: 41.13,
expectedIDs: []any{
"array", "array-three", "array-three-reverse",
"array", "array-three", "array-three-reverse", "array-two",
"double", "double-big", "double-max", "double-positive-infinity", "double-whole",
"int32", "int32-max",
"int64", "int64-big", "int64-max",
Expand All @@ -523,7 +523,7 @@ func TestQueryComparisonGt(t *testing.T) {
"DoubleNegativeZero": {
value: math.Copysign(0, -1),
expectedIDs: []any{
"array", "array-three", "array-three-reverse",
"array", "array-three", "array-three-reverse", "array-two",
"double", "double-big", "double-max", "double-positive-infinity", "double-smallest", "double-whole",
"int32", "int32-max",
"int64", "int64-big", "int64-max",
Expand Down Expand Up @@ -604,6 +604,7 @@ func TestQueryComparisonGt(t *testing.T) {
"Int32": {
value: int32(42),
expectedIDs: []any{
"array-two",
"double", "double-big", "double-max", "double-positive-infinity",
"int32-max",
"int64-big", "int64-max",
Expand Down Expand Up @@ -633,6 +634,7 @@ func TestQueryComparisonGt(t *testing.T) {
"Int64": {
value: int64(42),
expectedIDs: []any{
"array-two",
"double", "double-big", "double-max", "double-positive-infinity",
"int32-max",
"int64-big", "int64-max",
Expand Down Expand Up @@ -686,13 +688,13 @@ func TestQueryComparisonGte(t *testing.T) {
"Double": {
value: 42.13,
expectedIDs: []any{
"double", "double-big", "double-max", "double-positive-infinity", "int32-max", "int64-big", "int64-max",
"array-two", "double", "double-big", "double-max", "double-positive-infinity", "int32-max", "int64-big", "int64-max",
},
},
"DoubleNegativeZero": {
value: math.Copysign(0, -1),
expectedIDs: []any{
"array", "array-three", "array-three-reverse",
"array", "array-three", "array-three-reverse", "array-two",
"double", "double-big", "double-max", "double-negative-zero", "double-positive-infinity", "double-smallest", "double-whole", "double-zero",
"int32", "int32-max", "int32-zero",
"int64", "int64-big", "int64-max", "int64-zero",
Expand All @@ -708,7 +710,7 @@ func TestQueryComparisonGte(t *testing.T) {
},
"DoubleNaN": {
value: math.NaN(),
expectedIDs: []any{"double-nan"},
expectedIDs: []any{"array-two", "double-nan"},
},

"String": {
Expand Down Expand Up @@ -773,7 +775,7 @@ func TestQueryComparisonGte(t *testing.T) {
"Int32": {
value: int32(42),
expectedIDs: []any{
"array", "array-three", "array-three-reverse",
"array", "array-three", "array-three-reverse", "array-two",
"double", "double-big", "double-max", "double-positive-infinity", "double-whole",
"int32", "int32-max",
"int64", "int64-big", "int64-max",
Expand All @@ -800,7 +802,7 @@ func TestQueryComparisonGte(t *testing.T) {
"Int64": {
value: int64(42),
expectedIDs: []any{
"array", "array-three", "array-three-reverse",
"array", "array-three", "array-three-reverse", "array-two",
"double", "double-big", "double-max", "double-positive-infinity", "double-whole",
"int32", "int32-max",
"int64", "int64-big", "int64-max",
Expand Down Expand Up @@ -847,7 +849,7 @@ func TestQueryComparisonLt(t *testing.T) {
"Double": {
value: 43.13,
expectedIDs: []any{
"array", "array-three", "array-three-reverse",
"array", "array-three", "array-three-reverse", "array-two",
"double", "double-negative-infinity", "double-negative-zero", "double-smallest", "double-whole", "double-zero",
"int32", "int32-min", "int32-zero",
"int64", "int64-min", "int64-zero",
Expand Down Expand Up @@ -974,7 +976,7 @@ func TestQueryComparisonLt(t *testing.T) {
"Int64Big": {
value: int64(2<<60 + 1),
expectedIDs: []any{
"array", "array-three", "array-three-reverse",
"array", "array-three", "array-three-reverse", "array-two",
"double", "double-big", "double-negative-infinity", "double-negative-zero", "double-smallest", "double-whole", "double-zero",
"int32", "int32-max", "int32-min", "int32-zero",
"int64", "int64-min", "int64-zero",
Expand Down Expand Up @@ -1017,7 +1019,7 @@ func TestQueryComparisonLte(t *testing.T) {
"Double": {
value: 42.13,
expectedIDs: []any{
"array", "array-three", "array-three-reverse",
"array", "array-three", "array-three-reverse", "array-two",
"double", "double-negative-infinity", "double-negative-zero", "double-smallest", "double-whole", "double-zero",
"int32", "int32-min", "int32-zero",
"int64", "int64-min", "int64-zero",
Expand Down Expand Up @@ -1045,7 +1047,7 @@ func TestQueryComparisonLte(t *testing.T) {
},
"DoubleNaN": {
value: math.NaN(),
expectedIDs: []any{"double-nan"},
expectedIDs: []any{"array-two", "double-nan"},
},

"String": {
Expand Down Expand Up @@ -1222,7 +1224,7 @@ func TestQueryComparisonNin(t *testing.T) {
"Regex": {
value: bson.A{primitive.Regex{Pattern: "foo", Options: "i"}},
expectedIDs: []any{
"array", "array-embedded", "array-empty", "array-null",
"array", "array-embedded", "array-empty", "array-null", "array-two",
"binary", "binary-empty",
"bool-false", "bool-true",
"datetime", "datetime-epoch", "datetime-year-max", "datetime-year-min",
Expand Down Expand Up @@ -1300,7 +1302,7 @@ func TestQueryComparisonIn(t *testing.T) {
"ForScalarDataTypes": {
value: scalarDataTypesFilter,
expectedIDs: []any{
"array", "array-embedded", "array-null", "array-three", "array-three-reverse",
"array", "array-embedded", "array-null", "array-three", "array-three-reverse", "array-two",
"binary", "binary-empty",
"bool-false", "bool-true",
"datetime", "datetime-epoch", "datetime-year-max", "datetime-year-min",
Expand All @@ -1318,7 +1320,7 @@ func TestQueryComparisonIn(t *testing.T) {
"ForCompositeDataTypes": {
value: compositeDataTypesFilter,
expectedIDs: []any{
"array", "array-embedded", "array-empty", "array-null", "array-three", "array-three-reverse",
"array", "array-embedded", "array-empty", "array-null", "array-three", "array-three-reverse", "array-two",
"document", "document-composite", "document-composite-reverse", "document-empty", "document-null",
},
},
Expand Down
6 changes: 3 additions & 3 deletions integration/query_element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ func TestQueryElementType(t *testing.T) {
},
"Array": {
v: "array",
expectedIDs: []any{"array", "array-embedded", "array-empty", "array-null", "array-three", "array-three-reverse"},
expectedIDs: []any{"array", "array-embedded", "array-empty", "array-null", "array-three", "array-three-reverse", "array-two"},
},
"Double": {
v: "double",
expectedIDs: []any{
"double", "double-big", "double-max", "double-nan",
"array-two", "double", "double-big", "double-max", "double-nan",
"double-negative-infinity", "double-negative-zero", "double-positive-infinity",
"double-smallest", "double-whole", "double-zero",
},
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestQueryElementType(t *testing.T) {
"Number": {
v: "number",
expectedIDs: []any{
"array", "array-three", "array-three-reverse",
"array", "array-three", "array-three-reverse", "array-two",
"double", "double-big", "double-max", "double-nan",
"double-negative-infinity", "double-negative-zero",
"double-positive-infinity", "double-smallest",
Expand Down
8 changes: 4 additions & 4 deletions integration/query_logical_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func TestQueryLogicalNot(t *testing.T) {
"Not": {
filter: bson.D{{"value", bson.D{{"$not", bson.D{{"$eq", 42}}}}}},
expectedIDs: []any{
"array-embedded", "array-empty", "array-null",
"array-embedded", "array-empty", "array-null", "array-two",
"binary", "binary-empty",
"bool-false", "bool-true",
"datetime", "datetime-epoch", "datetime-year-max", "datetime-year-min",
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestQueryLogicalNot(t *testing.T) {
"NotEqNull": {
filter: bson.D{{"value", bson.D{{"$not", bson.D{{"$eq", nil}}}}}},
expectedIDs: []any{
"array", "array-empty",
"array", "array-empty", "array-two",
"binary", "binary-empty",
"bool-false", "bool-true",
"datetime", "datetime-epoch", "datetime-year-max", "datetime-year-min",
Expand All @@ -325,7 +325,7 @@ func TestQueryLogicalNot(t *testing.T) {
"ValueRegex": {
filter: bson.D{{"value", bson.D{{"$not", primitive.Regex{Pattern: "^fo"}}}}},
expectedIDs: []any{
"array", "array-embedded", "array-empty", "array-null",
"array", "array-embedded", "array-empty", "array-null", "array-two",
"binary", "binary-empty",
"bool-false", "bool-true",
"datetime", "datetime-epoch", "datetime-year-max", "datetime-year-min",
Expand All @@ -344,7 +344,7 @@ func TestQueryLogicalNot(t *testing.T) {
"NoSuchFieldRegex": {
filter: bson.D{{"no-such-field", bson.D{{"$not", primitive.Regex{Pattern: "/someregex/"}}}}},
expectedIDs: []any{
"array", "array-embedded", "array-empty", "array-null", "array-three", "array-three-reverse",
"array", "array-embedded", "array-empty", "array-null", "array-three", "array-three-reverse", "array-two",
"binary", "binary-empty",
"bool-false", "bool-true",
"datetime", "datetime-epoch", "datetime-year-max", "datetime-year-min",
Expand Down
4 changes: 2 additions & 2 deletions integration/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func TestQueryCount(t *testing.T) {
}{
"CountAllDocuments": {
command: bson.D{{"count", collection.Name()}},
response: 49,
response: 50,
},
"CountExactlyOneDocument": {
command: bson.D{
Expand All @@ -332,7 +332,7 @@ func TestQueryCount(t *testing.T) {
{"count", collection.Name()},
{"query", bson.D{{"value", bson.D{{"$type", "array"}}}}},
},
response: 6,
response: 7,
},
"CountNonExistingCollection": {
command: bson.D{
Expand Down
10 changes: 9 additions & 1 deletion integration/shareddata/composites.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package shareddata

import "go.mongodb.org/mongo-driver/bson"
import (
"math"

"go.mongodb.org/mongo-driver/bson"
)

// Composites contain composite values for tests.
//
Expand All @@ -28,10 +32,14 @@ var Composites = &Values[string]{
"document-empty": bson.D{},

"array": bson.A{int32(42)},
"array-two": bson.A{42.13, math.NaN()},
"array-three": bson.A{int32(42), "foo", nil},
"array-three-reverse": bson.A{nil, "foo", int32(42)},
"array-embedded": bson.A{bson.A{int32(42), "foo"}, nil},
"array-empty": bson.A{},
"array-null": bson.A{nil},

// TODO: This case demonstrates a bug, see https://github.com/FerretDB/FerretDB/issues/732
// "array-empty-nested": bson.A{bson.A{}},
},
}

0 comments on commit 2354780

Please sign in to comment.