Skip to content

Commit 40d5e88

Browse files
authored
Port Query::testNaNFilter() from java (#1549)
Note that this works even though we haven't ported the NanFilter class yet. (The RelationFilter handles nan's just fine. Though also doesn't restrict nan's in cases where they shouldn't be used, i.e. anything except equality.)
1 parent d6d273a commit 40d5e88

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Firestore/core/test/firebase/firestore/core/query_test.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "Firestore/core/src/firebase/firestore/core/query.h"
1818

19+
#include <cmath>
20+
1921
#include "Firestore/core/src/firebase/firestore/model/document.h"
2022
#include "Firestore/core/src/firebase/firestore/model/field_path.h"
2123
#include "Firestore/core/src/firebase/firestore/model/field_value.h"
@@ -97,6 +99,26 @@ TEST(QueryTest, PrimitiveValueFilter) {
9799
EXPECT_FALSE(query2.Matches(doc5));
98100
}
99101

102+
TEST(QueryTest, NanFilter) {
103+
Query query = Query::AtPath(ResourcePath::FromString("collection"))
104+
.Filter(Filter("sort", "==", NAN));
105+
106+
Document doc1 = Doc("collection/1", 0, {{"sort", FieldValue::NanValue()}});
107+
Document doc2 =
108+
Doc("collection/2", 0, {{"sort", FieldValue::IntegerValue(2)}});
109+
Document doc3 =
110+
Doc("collection/3", 0, {{"sort", FieldValue::DoubleValue(3.1)}});
111+
Document doc4 = Doc("collection/4", 0, {{"sort", FieldValue::FalseValue()}});
112+
Document doc5 =
113+
Doc("collection/5", 0, {{"sort", FieldValue::StringValue("string")}});
114+
115+
EXPECT_TRUE(query.Matches(doc1));
116+
EXPECT_FALSE(query.Matches(doc2));
117+
EXPECT_FALSE(query.Matches(doc3));
118+
EXPECT_FALSE(query.Matches(doc4));
119+
EXPECT_FALSE(query.Matches(doc5));
120+
}
121+
100122
} // namespace core
101123
} // namespace firestore
102124
} // namespace firebase

Firestore/core/test/firebase/firestore/testutil/testutil.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ inline std::shared_ptr<core::Filter> Filter(absl::string_view key,
111111
return Filter(key, op, model::FieldValue::IntegerValue(value));
112112
}
113113

114+
inline std::shared_ptr<core::Filter> Filter(absl::string_view key,
115+
absl::string_view op,
116+
double value) {
117+
return Filter(key, op, model::FieldValue::DoubleValue(value));
118+
}
119+
114120
// Add a non-inline function to make this library buildable.
115121
// TODO(zxu123): remove once there is non-inline function.
116122
void dummy();

0 commit comments

Comments
 (0)