forked from bblanchon/ArduinoJson
Added operator ==
to compare JsonVariant
and strings (issue #402)
This commit is contained in:
@ -5,8 +5,8 @@
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
// If you like this project, please add a star!
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
class JsonVariant_Comparison_Tests : public ::testing::Test {
|
||||
protected:
|
||||
@ -92,3 +92,37 @@ TEST_F(JsonVariant_Comparison_Tests, ULong) {
|
||||
TEST_F(JsonVariant_Comparison_Tests, UShort) {
|
||||
testValue<unsigned short>(122, 123, 124);
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_Comparison_Tests, StringLiteral) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonVariant variant = jsonBuffer.parse("\"hello\"");
|
||||
|
||||
ASSERT_TRUE(variant == "hello");
|
||||
ASSERT_FALSE(variant != "hello");
|
||||
|
||||
ASSERT_TRUE(variant != "world");
|
||||
ASSERT_FALSE(variant == "world");
|
||||
|
||||
ASSERT_TRUE("hello" == variant);
|
||||
ASSERT_FALSE("hello" != variant);
|
||||
|
||||
ASSERT_TRUE("world" != variant);
|
||||
ASSERT_FALSE("world" == variant);
|
||||
}
|
||||
|
||||
TEST_F(JsonVariant_Comparison_Tests, String) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonVariant variant = jsonBuffer.parse("\"hello\"");
|
||||
|
||||
ASSERT_TRUE(variant == std::string("hello"));
|
||||
ASSERT_FALSE(variant != std::string("hello"));
|
||||
|
||||
ASSERT_TRUE(variant != std::string("world"));
|
||||
ASSERT_FALSE(variant == std::string("world"));
|
||||
|
||||
ASSERT_TRUE(std::string("hello") == variant);
|
||||
ASSERT_FALSE(std::string("hello") != variant);
|
||||
|
||||
ASSERT_TRUE(std::string("world") != variant);
|
||||
ASSERT_FALSE(std::string("world") == variant);
|
||||
}
|
||||
|
Reference in New Issue
Block a user