From 890321214cc8340c9eb02712f63799085f3ea112 Mon Sep 17 00:00:00 2001 From: rsgowman Date: Tue, 17 Jul 2018 10:28:25 -0400 Subject: Port PrimitiveValueTest test for core::Query (#1530) (From java.) Also fix a bug uncovered by the test. (oops) --- Firestore/core/src/firebase/firestore/core/filter.cc | 4 ++-- Firestore/core/src/firebase/firestore/core/filter.h | 2 +- .../src/firebase/firestore/core/relation_filter.cc | 18 ++++++++++-------- .../core/src/firebase/firestore/core/relation_filter.h | 6 ++++-- 4 files changed, 17 insertions(+), 13 deletions(-) (limited to 'Firestore/core/src/firebase/firestore/core') diff --git a/Firestore/core/src/firebase/firestore/core/filter.cc b/Firestore/core/src/firebase/firestore/core/filter.cc index 4c27f27..ea0fab3 100644 --- a/Firestore/core/src/firebase/firestore/core/filter.cc +++ b/Firestore/core/src/firebase/firestore/core/filter.cc @@ -29,11 +29,11 @@ using model::FieldValue; std::shared_ptr Filter::Create(FieldPath path, Operator op, - FieldValue value) { + FieldValue value_rhs) { // TODO(rsgowman): Java performs a number of checks here, and then invokes the // ctor of the relevant Filter subclass. Port those checks here. return std::make_shared(std::move(path), op, - std::move(value)); + std::move(value_rhs)); } } // namespace core diff --git a/Firestore/core/src/firebase/firestore/core/filter.h b/Firestore/core/src/firebase/firestore/core/filter.h index 9f25a39..4748566 100644 --- a/Firestore/core/src/firebase/firestore/core/filter.h +++ b/Firestore/core/src/firebase/firestore/core/filter.h @@ -48,7 +48,7 @@ class Filter { */ static std::shared_ptr Create(model::FieldPath path, Operator op, - model::FieldValue value); + model::FieldValue value_rhs); virtual ~Filter() { } diff --git a/Firestore/core/src/firebase/firestore/core/relation_filter.cc b/Firestore/core/src/firebase/firestore/core/relation_filter.cc index a6ae916..07087e6 100644 --- a/Firestore/core/src/firebase/firestore/core/relation_filter.cc +++ b/Firestore/core/src/firebase/firestore/core/relation_filter.cc @@ -27,8 +27,10 @@ namespace core { using model::FieldPath; using model::FieldValue; -RelationFilter::RelationFilter(FieldPath field, Operator op, FieldValue value) - : field_(std::move(field)), op_(op), value_(std::move(value)) { +RelationFilter::RelationFilter(FieldPath field, + Operator op, + FieldValue value_rhs) + : field_(std::move(field)), op_(op), value_rhs_(std::move(value_rhs)) { } const FieldPath& RelationFilter::field() const { @@ -47,22 +49,22 @@ bool RelationFilter::Matches(const model::Document& doc) const { bool RelationFilter::MatchesValue(const FieldValue& other) const { // Only compare types with matching backend order (such as double and int). - return FieldValue::Comparable(value_.type(), other.type()) && + return FieldValue::Comparable(other.type(), value_rhs_.type()) && MatchesComparison(other); } bool RelationFilter::MatchesComparison(const FieldValue& other) const { switch (op_) { case Operator::LessThan: - return value_ < other; + return other < value_rhs_; case Operator::LessThanOrEqual: - return value_ <= other; + return other <= value_rhs_; case Operator::Equal: - return value_ == other; + return other == value_rhs_; case Operator::GreaterThan: - return value_ > other; + return other > value_rhs_; case Operator::GreaterThanOrEqual: - return value_ >= other; + return other >= value_rhs_; } UNREACHABLE(); } diff --git a/Firestore/core/src/firebase/firestore/core/relation_filter.h b/Firestore/core/src/firebase/firestore/core/relation_filter.h index 94da208..8110ac1 100644 --- a/Firestore/core/src/firebase/firestore/core/relation_filter.h +++ b/Firestore/core/src/firebase/firestore/core/relation_filter.h @@ -35,7 +35,9 @@ class RelationFilter : public Filter { * Creates a new filter that compares fields and values. Only intended to be * called from Filter::Create(). */ - RelationFilter(model::FieldPath field, Operator op, model::FieldValue value); + RelationFilter(model::FieldPath field, + Operator op, + model::FieldValue value_rhs); const model::FieldPath& field() const override; @@ -49,7 +51,7 @@ class RelationFilter : public Filter { const model::FieldPath field_; const Operator op_; - const model::FieldValue value_; + const model::FieldValue value_rhs_; }; } // namespace core -- cgit v1.2.3