Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 113: list enhancements #127

Merged
merged 7 commits into from
Oct 22, 2024
Merged
Prev Previous commit
Next Next commit
Make LIST test cases common to LIST and PROTOLIST
  • Loading branch information
michael-projectx authored and jayv committed Oct 22, 2024
commit 32c607984d18469a230477686a27721bc28a716e
93 changes: 29 additions & 64 deletions tests/config_grammar_test.cpp
Original file line number Diff line number Diff line change
@@ -376,78 +376,40 @@ TEST(ConfigGrammar, STRING) {
}
}

const std::vector<std::string> list_test_cases = {
"[1, 2, 3]", "[1.0, 2., -3.3]", R"(["one", "two", "three"])", "[0x123, 0Xabc, 0xA1B2F9]",
"[0.123, $(ref.var), 3.456]",
// TODO: Add support for expressions in lists
// R"([12, {{ 2^14 - 1}}, 0.32])", // Expressions in lists

// Verify that lists can contain newlines
R"([1,
2,
3])",
// Verify that a list can contain leading and trailing comments:
R"([# comment
1, 2, 3 # comment
# comment
])",
"[]", // Empty lists are supported
// Verify that an empty list containing a comment is supported
R"([
# This is a multi-line
# comment
])",
"[$(ref.var2), $(ref.var1), 3.456]"};

TEST(ConfigGrammar, LIST) {
auto checkList = [](const std::string& input) {
std::optional<flexi_cfg::config::ActionData> out;
checkResult<peg::must<flexi_cfg::config::LIST, peg::eolf>,
flexi_cfg::config::types::ConfigList>(input, flexi_cfg::config::types::Type::kList,
out);
};
{
const std::string content = "[1, 2, 3]";
checkList(content);
}
{
const std::string content = "[1.0, 2., -3.3]";
checkList(content);
}
{
const std::string content = R"(["one", "two", "three"])";
checkList(content);
}
{
const std::string content = "[0x123, 0Xabc, 0xA1B2F9]";
checkList(content);
}
{
const std::string content = "[0.123, $(ref.var), 3.456]";
checkList(content);
}
// TODO: Add support for expressions in lists
// {
// const std::string content = R"([12, {{ 2^14 - 1}}, 0.32])";
// checkList(content);
// }
{
// Verify that a list can contain newlines:
const std::string content = R"([1,
2,
3])";
checkList(content);
}
{
// Verify that a list can contain leading and trailing comments:
const std::string content = R"([# comment
1, 2, 3 # comment
# comment
])";
checkList(content);
}
{
// Verify that a list can contain trailing comments within the list:
const std::string content = R"([1, 2, # comment here
3 # comment
# comment
])";
checkList(content);
}
{
// Verify that an empty list is supported
const std::string content = "[]";
checkList(content);
}
{
// Verify that an empty list containing a comment is supported
const std::string content = R"([
# This is a multi-line
# comment
])";
checkList(content);
}
{
const std::string content = "[$(ref.var2), $(ref.var1), 3.456]";
for (const auto& content : list_test_cases) {
checkList(content);
}

{
// Non-homogeneous lists are not allowed
const std::string content = R"([12, "two", 10.2])";
@@ -630,8 +592,11 @@ TEST(ConfigGrammar, PROTOLIST) {
checkResult<peg::must<flexi_cfg::config::PROTO_LIST, peg::eolf>,
flexi_cfg::config::types::ConfigList>(input, flexi_cfg::config::types::Type::kList,
out);
out->print(std::cout);
};
// All valid "LIST" cases are also valid "PROTO_LIST" cases
for (const auto& content : list_test_cases) {
checkProtoList(content);
}
{
const std::string content = "[3, 4, ${TEST}]";
checkProtoList(content);