mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-14 19:16:35 +02:00
Added JsonVariant::operator[](int)
This commit is contained in:
32
test/JsonVariant_Subscript_Tests.cpp
Normal file
32
test/JsonVariant_Subscript_Tests.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright Benoit Blanchon 2014
|
||||
// MIT License
|
||||
//
|
||||
// Arduino JSON library
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson/StaticJsonBuffer.hpp>
|
||||
#include <ArduinoJson/JsonArray.hpp>
|
||||
#include <ArduinoJson/JsonObject.hpp>
|
||||
|
||||
using namespace ArduinoJson;
|
||||
|
||||
class JsonVariant_Subscript_Tests : public ::testing::Test {
|
||||
protected:
|
||||
StaticJsonBuffer<200> buffer;
|
||||
JsonVariant variant;
|
||||
};
|
||||
|
||||
TEST_F(JsonVariant_Subscript_Tests, Array) {
|
||||
JsonArray &array = buffer.createArray();
|
||||
array.add("element at index 0");
|
||||
array.add("element at index 1");
|
||||
|
||||
variant = array;
|
||||
|
||||
EXPECT_EQ(2, variant.size());
|
||||
EXPECT_STREQ("element at index 0", variant[0].asString());
|
||||
EXPECT_STREQ("element at index 1", variant[1].asString());
|
||||
EXPECT_FALSE(variant[-1].success());
|
||||
EXPECT_FALSE(variant[3].success());
|
||||
}
|
Reference in New Issue
Block a user