mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
Fixes #1658. Please review and commit clang-tidy fixes. Co-authored-by: kuznetsss <15742918+kuznetsss@users.noreply.github.com>
87 lines
2.7 KiB
C++
87 lines
2.7 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of clio: https://github.com/XRPLF/clio
|
|
Copyright (c) 2024, the clio developers.
|
|
|
|
Permission to use, copy, modify, and distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#include "util/newconfig/Array.hpp"
|
|
#include "util/newconfig/ConfigConstraints.hpp"
|
|
#include "util/newconfig/ConfigValue.hpp"
|
|
#include "util/newconfig/Types.hpp"
|
|
#include "util/newconfig/ValueView.hpp"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
using namespace util::config;
|
|
|
|
TEST(ArrayTest, addSingleValue)
|
|
{
|
|
auto arr = Array{ConfigValue{ConfigType::Double}};
|
|
arr.addValue(111.11);
|
|
EXPECT_EQ(arr.size(), 1);
|
|
}
|
|
|
|
TEST(ArrayTest, addAndCheckMultipleValues)
|
|
{
|
|
auto arr = Array{ConfigValue{ConfigType::Double}};
|
|
arr.addValue(111.11);
|
|
arr.addValue(222.22);
|
|
arr.addValue(333.33);
|
|
EXPECT_EQ(arr.size(), 3);
|
|
|
|
auto const cv = arr.at(0);
|
|
ValueView const vv{cv};
|
|
EXPECT_EQ(vv.asDouble(), 111.11);
|
|
|
|
auto const cv2 = arr.at(1);
|
|
ValueView const vv2{cv2};
|
|
EXPECT_EQ(vv2.asDouble(), 222.22);
|
|
|
|
EXPECT_EQ(arr.size(), 3);
|
|
arr.addValue(444.44);
|
|
|
|
EXPECT_EQ(arr.size(), 4);
|
|
auto const cv4 = arr.at(3);
|
|
ValueView const vv4{cv4};
|
|
EXPECT_EQ(vv4.asDouble(), 444.44);
|
|
}
|
|
|
|
TEST(ArrayTest, testArrayPattern)
|
|
{
|
|
auto const arr = Array{ConfigValue{ConfigType::String}};
|
|
auto const arrPattern = arr.getArrayPattern();
|
|
EXPECT_EQ(arrPattern.type(), ConfigType::String);
|
|
}
|
|
|
|
TEST(ArrayTest, iterateValueArray)
|
|
{
|
|
auto arr = Array{ConfigValue{ConfigType::Integer}.withConstraint(validateUint16)};
|
|
std::vector<int64_t> const expected{543, 123, 909};
|
|
|
|
for (auto const num : expected)
|
|
arr.addValue(num);
|
|
|
|
std::vector<int64_t> actual;
|
|
for (auto it = arr.begin(); it != arr.end(); ++it)
|
|
actual.emplace_back(std::get<int64_t>(it->getValue()));
|
|
|
|
EXPECT_TRUE(std::ranges::equal(expected, actual));
|
|
}
|