diff --git a/include/mapnik/value.hpp b/include/mapnik/value.hpp index cfa86fa5e..a595fabba 100644 --- a/include/mapnik/value.hpp +++ b/include/mapnik/value.hpp @@ -72,42 +72,41 @@ using value_base = util::variant(rhs); + return static_cast(lhs) == rhs; } bool operator() (value_bool lhs, value_double rhs) const { - return lhs == static_cast(rhs); + return static_cast(lhs) == rhs; } bool operator() (value_double lhs, value_integer rhs) const { - return lhs == static_cast(rhs); + return lhs == static_cast(rhs); } bool operator() (value_bool lhs, value_integer rhs) const { - return lhs == static_cast(rhs); + return static_cast(lhs) == rhs; } bool operator() (value_integer lhs, value_bool rhs) const { - return lhs == static_cast(rhs); + return lhs == static_cast(rhs); } bool operator() (value_double lhs, value_bool rhs) const { - return lhs == static_cast(rhs); + return static_cast(lhs) == rhs; } bool operator() (value_unicode_string const& lhs, value_unicode_string const& rhs) const { - return (lhs == rhs) ? true: false; + return (lhs == rhs) ? true: false; } template @@ -140,12 +139,12 @@ struct not_equals bool operator() (value_integer lhs, value_double rhs) const { - return lhs != rhs; + return static_cast(lhs) != rhs; } bool operator() (value_bool lhs, value_double rhs) const { - return lhs != static_cast(rhs); + return static_cast(lhs) != rhs; } bool operator() (value_double lhs, value_integer rhs) const @@ -155,12 +154,12 @@ struct not_equals bool operator() (value_bool lhs, value_integer rhs) const { - return lhs != static_cast(rhs); + return static_cast(lhs) != rhs; } bool operator() (value_integer lhs, value_bool rhs) const { - return lhs != static_cast(rhs); + return lhs != static_cast(rhs); } bool operator() (value_double lhs, value_bool rhs) const diff --git a/test/unit/core/comparison_test.cpp b/test/unit/core/comparison_test.cpp new file mode 100644 index 000000000..2cfbc08fd --- /dev/null +++ b/test/unit/core/comparison_test.cpp @@ -0,0 +1,49 @@ +#include "catch.hpp" + +#include +#include +#include + +TEST_CASE("comparison") +{ + SECTION("operator==()") + { + mapnik::value v0 = 1; // mapnik::value_integer + mapnik::value v1 = 1.001; // mapnik::value_double + mapnik::value v2 = true; // mapnik::value_boolean + + REQUIRE(!(v0 == v1)); + REQUIRE(!(v1 == v0)); + + REQUIRE(!(v1 == v2)); + REQUIRE(!(v2 == v1)); + + REQUIRE(v2 == v0); + REQUIRE(v0 == v2); + } + + SECTION("operator!=()") + { + mapnik::value v0 = 1; // mapnik::value_integer + mapnik::value v1 = 1.001; // mapnik::value_double + mapnik::value v2 = true; // mapnik::value_boolean + mapnik::value v3 = mapnik::value_null(); // + + REQUIRE(v0 != v1); + REQUIRE(v1 != v0); + + REQUIRE(v1 != v2); + REQUIRE(v2 != v1); + + REQUIRE(!(v2 != v0)); + REQUIRE(!(v0 != v2)); + + REQUIRE(v3 != v0); + REQUIRE(v3 != v1); + REQUIRE(v3 != v2); + REQUIRE(v0 != v3); + REQUIRE(v1 != v3); + REQUIRE(v2 != v3); + + } +}