mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
refactor: Clio Config (#1593)
Add constraint + parse json into Config Second part of refactoring Clio Config; First PR found [here](https://github.com/XRPLF/clio/pull/1544) Steps that are left to implement: - Replacing all the places where we fetch config values (by using config.valueOr/MaybeValue) to instead get it from Config Definition - Generate markdown file using Clio Config Description
This commit is contained in:
@@ -18,33 +18,69 @@
|
||||
//==============================================================================
|
||||
|
||||
#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, testConfigArray)
|
||||
TEST(ArrayTest, addSingleValue)
|
||||
{
|
||||
auto arr = Array{
|
||||
ConfigValue{ConfigType::Boolean}.defaultValue(false),
|
||||
ConfigValue{ConfigType::Integer}.defaultValue(1234),
|
||||
ConfigValue{ConfigType::Double}.defaultValue(22.22),
|
||||
};
|
||||
auto cv = arr.at(0);
|
||||
ValueView const vv{cv};
|
||||
EXPECT_EQ(vv.asBool(), false);
|
||||
auto arr = Array{ConfigValue{ConfigType::Double}};
|
||||
arr.addValue(111.11);
|
||||
EXPECT_EQ(arr.size(), 1);
|
||||
}
|
||||
|
||||
auto cv2 = arr.at(1);
|
||||
ValueView const vv2{cv2};
|
||||
EXPECT_EQ(vv2.asIntType<int>(), 1234);
|
||||
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 vv{cv};
|
||||
EXPECT_EQ(vv.asDouble(), 111.11);
|
||||
|
||||
auto const cv2 = arr.at(1);
|
||||
ValueView vv2{cv2};
|
||||
EXPECT_EQ(vv2.asDouble(), 222.22);
|
||||
|
||||
EXPECT_EQ(arr.size(), 3);
|
||||
arr.emplaceBack(ConfigValue{ConfigType::String}.defaultValue("false"));
|
||||
arr.addValue(444.44);
|
||||
|
||||
EXPECT_EQ(arr.size(), 4);
|
||||
auto cv4 = arr.at(3);
|
||||
ValueView const vv4{cv4};
|
||||
EXPECT_EQ(vv4.asString(), "false");
|
||||
auto const cv4 = arr.at(3);
|
||||
ValueView 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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user