mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-08-30 12:15:12 +00:00
connection between 2 systems and bug fixes (#14)
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
# Erik Verhoeven - writing TOML and whitespace preservation
|
||||
#*******************************************************************************
|
||||
|
||||
# Define project
|
||||
project (UnitTest_TOMLParser VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Character Reader executable
|
||||
add_executable(UnitTest_TOMLParser
|
||||
"character_reader_tests.cpp"
|
||||
@@ -19,13 +22,17 @@ add_executable(UnitTest_TOMLParser
|
||||
"parser_tests.cpp"
|
||||
"main.cpp"
|
||||
"generate_toml_tests.cpp"
|
||||
"generate_toml_delete_node.cpp"
|
||||
"delete_node.cpp"
|
||||
"statement_boundary_detection.cpp"
|
||||
"miscellaneous_tests.cpp"
|
||||
"miscellaneous.cpp"
|
||||
"generate_toml_with_transfer.cpp"
|
||||
"generate_toml_switch_inline.cpp"
|
||||
"generate_toml_getset_comment.cpp"
|
||||
"generate_toml_insert_node.cpp" "generate_toml_miscellaneous.cpp" "generate_toml_combine_reduce.cpp")
|
||||
"getset_comment.cpp"
|
||||
"insert_node.cpp"
|
||||
"combine_reduce.cpp"
|
||||
"comparison_tests.cpp"
|
||||
"make_inline_standard.cpp"
|
||||
"indexer_tests.cpp" "cascade_insert_node.cpp")
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
target_link_libraries(UnitTest_TOMLParser GTest::GTest ${CMAKE_THREAD_LIBS_INIT})
|
||||
if (WIN32)
|
||||
|
||||
536
tests/unit_tests/toml_parser/cascade_insert_node.cpp
Normal file
536
tests/unit_tests/toml_parser/cascade_insert_node.cpp
Normal file
@@ -0,0 +1,536 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
#include <support/toml.h>
|
||||
|
||||
TEST(CascadeInsertNode, InsertValueInStandardTable)
|
||||
{
|
||||
// Insert a standard table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
|
||||
// Insert the value into the new table
|
||||
EXPECT_TRUE(root.InsertValue("", "standard_table.value_int", 10));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_int = 10)toml");
|
||||
|
||||
// Insert the values into the existing table
|
||||
EXPECT_TRUE(root.InsertValue("", "standard_table.value_str", u8"abc"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_int = 10
|
||||
value_str = "abc")toml");
|
||||
EXPECT_TRUE(root.InsertValue("standard_table.value_int", "standard_table.value_float", 123.456));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_float = 123.456
|
||||
value_int = 10
|
||||
value_str = "abc")toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertTableInStandardTable)
|
||||
{
|
||||
// Insert a standard table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTable("", "standard_table", false));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
|
||||
// Insert a standard table
|
||||
EXPECT_TRUE(root.InsertTable("", "standard_table.table1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table.table1])toml");
|
||||
|
||||
// Insert an inline table before
|
||||
EXPECT_TRUE(root.InsertTable("standard_table.table1", "standard_table.table2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table2 = {}
|
||||
[standard_table.table1])toml");
|
||||
|
||||
// Insert an inline table behind -> this will have to be printed before the standard table
|
||||
EXPECT_TRUE(root.InsertTable("", "standard_table.table3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table2 = {}
|
||||
table3 = {}
|
||||
[standard_table.table1])toml");
|
||||
|
||||
// Insert a standard table in front -> this will have to be printed behind the inline table relative to the elements of the
|
||||
// standard_table.
|
||||
EXPECT_TRUE(root.InsertTable("standard_table.table2", "standard_table.table4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table2 = {}
|
||||
table3 = {}
|
||||
[standard_table.table4]
|
||||
[standard_table.table1])toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertArrayInStandardTable)
|
||||
{
|
||||
// Insert a standard table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTable("", "standard_table", false));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
|
||||
// Insert arrays
|
||||
EXPECT_TRUE(root.InsertArray("", "standard_table.value_array1"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_array1 = [])toml");
|
||||
EXPECT_TRUE(root.InsertArray("", "standard_table.value_array2"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_array1 = []
|
||||
value_array2 = [])toml");
|
||||
EXPECT_TRUE(root.InsertArray("standard_table.value_array1", "standard_table.value_array3"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_array3 = []
|
||||
value_array1 = []
|
||||
value_array2 = [])toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertTableArrayInStandardTable)
|
||||
{
|
||||
// Insert a standard table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTable("", "standard_table", false));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
|
||||
// Insert standard table array
|
||||
EXPECT_TRUE(root.InsertTableArray("", "standard_table.table_array1",
|
||||
false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[standard_table.table_array1]])toml");
|
||||
|
||||
// Insert an inline table array before
|
||||
EXPECT_TRUE(root.InsertTableArray("standard_table.table_array1", "standard_table.table_array2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table_array2 = [{}]
|
||||
[[standard_table.table_array1]])toml");
|
||||
|
||||
// Insert an inline table array behind -> this will have to be printed before the standard table array
|
||||
EXPECT_TRUE(root.InsertTableArray("", "standard_table.table_array3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[standard_table.table_array1]])toml");
|
||||
|
||||
// Insert a standard table array in front -> this will have to be printed behind the inline table array relative to the elements
|
||||
// of the standard_table.
|
||||
EXPECT_TRUE(root.InsertTableArray("standard_table.table_array2", "standard_table.table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[standard_table.table_array4]]
|
||||
[[standard_table.table_array1]])toml");
|
||||
|
||||
// Add an additional table array entry for table array #4
|
||||
EXPECT_TRUE(root.InsertTableArray("", "standard_table.table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[standard_table.table_array4]]
|
||||
[[standard_table.table_array1]]
|
||||
[[standard_table.table_array4]])toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertValueInInlineTable)
|
||||
{
|
||||
// Insert an inline table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTable("", "inline_table", true));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {})toml");
|
||||
|
||||
// Insert the values into the table
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_table.value_int", 10));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_int = 10})toml");
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_table.value_str", u8"abc"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_int = 10, value_str = "abc"})toml");
|
||||
EXPECT_TRUE(root.InsertValue("inline_table.value_int", "inline_table.value_float", 123.456));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_float = 123.456, value_int = 10, value_str = "abc"})toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertTableInInlineTable)
|
||||
{
|
||||
// Insert an inline table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTable("", "inline_table", true));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {})toml");
|
||||
|
||||
// Insert a standard table
|
||||
EXPECT_TRUE(root.InsertTable("", "inline_table.table1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table1 = {}})toml");
|
||||
|
||||
// Insert an inline table before
|
||||
EXPECT_TRUE(root.InsertTable("inline_table.table1", "inline_table.table2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table2 = {}, table1 = {}})toml");
|
||||
|
||||
// Insert an inline table behind -> this will have to be printed before the standard table
|
||||
EXPECT_TRUE(root.InsertTable("", "inline_table.table3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table2 = {}, table1 = {}, table3 = {}})toml");
|
||||
|
||||
// Insert a standard table in front -> this will have to be printed behind the inline table
|
||||
EXPECT_TRUE(root.InsertTable("inline_table.table2", "inline_table.table4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table4 = {}, table2 = {}, table1 = {}, table3 = {}})toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertArrayInInlineTable)
|
||||
{
|
||||
// Insert an inline table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTable("", "inline_table",
|
||||
true));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {})toml");
|
||||
|
||||
// Insert arrays
|
||||
EXPECT_TRUE(root.InsertArray("", "inline_table.value_array1"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_array1 = []})toml");
|
||||
EXPECT_TRUE(root.InsertArray("", "inline_table.value_array2"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_array1 = [], value_array2 = []})toml");
|
||||
EXPECT_TRUE(root.InsertArray("inline_table.value_array1", "inline_table.value_array3"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_array3 = [], value_array1 = [], value_array2 = []})toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertTableArrayInInlineTable)
|
||||
{
|
||||
// Insert an inline table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTable("", "inline_table", true));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {})toml");
|
||||
|
||||
// Insert standard table array
|
||||
EXPECT_TRUE(root.InsertTableArray("", "inline_table.table_array1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table_array1 = [{}]})toml");
|
||||
|
||||
// Insert an inline table array before
|
||||
EXPECT_TRUE(root.InsertTableArray("inline_table.table_array1", "inline_table.table_array2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table_array2 = [{}], table_array1 = [{}]})toml");
|
||||
|
||||
// Insert an inline table array behind -> this will have to be printed before the standard table array
|
||||
EXPECT_TRUE(root.InsertTableArray("", "inline_table.table_array3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table_array2 = [{}], table_array1 = [{}], table_array3 = [{}]})toml");
|
||||
|
||||
// Insert a standard table array in front -> this will have to be printed behind the inline table array
|
||||
EXPECT_TRUE(root.InsertTableArray("inline_table.table_array2", "inline_table.table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML,
|
||||
R"toml(inline_table = {table_array4 = [{}], table_array2 = [{}], table_array1 = [{}], table_array3 = [{}]})toml");
|
||||
|
||||
// Add an additional table array entry for table array #4
|
||||
EXPECT_TRUE(root.InsertTableArray("", "inline_table.table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML,
|
||||
R"toml(inline_table = {table_array4 = [{}, {}], table_array2 = [{}], table_array1 = [{}], table_array3 = [{}]})toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertValueInArray)
|
||||
{
|
||||
// Insert an array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertArray("", "inline_array"));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [])toml");
|
||||
|
||||
// Insert the values into the table (with or without name)
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array", 10));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [10])toml");
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array", u8"abc"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [10, "abc"])toml");
|
||||
EXPECT_TRUE(root.InsertValue("inline_array[0]", "inline_array", 123.456));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [123.456, 10, "abc"])toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertTableInArray)
|
||||
{
|
||||
// Insert an array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertArray("", "inline_array"));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [])toml");
|
||||
|
||||
// Insert a standard table
|
||||
EXPECT_TRUE(root.InsertTable("", "inline_array", false));
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[0].a", 10));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [{a = 10}])toml");
|
||||
|
||||
// Insert an inline table before
|
||||
EXPECT_TRUE(root.InsertTable("inline_array[0]", "inline_array", true));
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[0].b", 20));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [{b = 20}, {a = 10}])toml");
|
||||
|
||||
// Insert an inline table behind
|
||||
EXPECT_TRUE(root.InsertTable("", "inline_array", true));
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array.c", 30));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [{b = 20}, {a = 10}, {c = 30}])toml");
|
||||
|
||||
// Insert a standard table in front
|
||||
EXPECT_TRUE(root.InsertTable("inline_array[0]", "inline_array", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[0].d", 40));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [{d = 40}, {b = 20}, {a = 10}, {c = 30}])toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertArrayInArray)
|
||||
{
|
||||
// Insert an array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertArray("", "inline_array"));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [])toml");
|
||||
|
||||
// Insert arrays
|
||||
EXPECT_TRUE(root.InsertArray("", "inline_array"));
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[0]", 10));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[10]])toml");
|
||||
EXPECT_TRUE(root.InsertArray("", "inline_array"));
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[1]", 20));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[10], [20]])toml");
|
||||
EXPECT_TRUE(root.InsertArray("inline_array[0]", "inline_array"));
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[0]", 30));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[30], [10], [20]])toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertTableArrayInArray)
|
||||
{
|
||||
// Insert an array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertArray("", "inline_array"));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [])toml");
|
||||
|
||||
// Insert standard table array
|
||||
EXPECT_TRUE(root.InsertTableArray("", "inline_array", false));
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[0].a", 10));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[{a = 10}]])toml");
|
||||
|
||||
// Insert an inline table array before
|
||||
EXPECT_TRUE(root.InsertTableArray("inline_array[0]", "inline_array", true));
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[0].b", 20));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[{b = 20}], [{a = 10}]])toml");
|
||||
|
||||
// Insert an inline table array behind -> this will have to be printed before the standard table array
|
||||
EXPECT_TRUE(root.InsertTableArray("", "inline_array", true));
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[999].c", 30));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[{b = 20}], [{a = 10}], [{c = 30}]])toml");
|
||||
|
||||
// Insert a standard table array in front -> this will have to be printed behind the inline table array
|
||||
EXPECT_TRUE(root.InsertTableArray("inline_array[0]", "inline_array", false));
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[0].d", 40));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[{d = 40}], [{b = 20}], [{a = 10}], [{c = 30}]])toml");
|
||||
|
||||
// Add an additional table array entry for table array #4
|
||||
EXPECT_TRUE(root.InsertValue("", "inline_array[0].e", 50));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[{d = 40, e = 50}], [{b = 20}], [{a = 10}], [{c = 30}]])toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertValueInTableArray)
|
||||
{
|
||||
// Insert a standard table array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTableArray("", "table_array", false));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]])toml");
|
||||
|
||||
// Insert the values into the table
|
||||
EXPECT_TRUE(root.InsertValue("", "table_array.value_int", 10));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_int = 10)toml");
|
||||
EXPECT_TRUE(root.InsertValue("", "table_array.value_str", u8"abc"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_int = 10
|
||||
value_str = "abc")toml");
|
||||
EXPECT_TRUE(root.InsertValue("table_array[0]", "table_array.value_float", 123.456));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_float = 123.456
|
||||
value_int = 10
|
||||
value_str = "abc")toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertTableInTableArray)
|
||||
{
|
||||
// Insert a standard table array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTableArray("", "table_array", false));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]])toml");
|
||||
|
||||
// Insert a standard table
|
||||
EXPECT_TRUE(root.InsertTable("", "table_array.table1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
[table_array.table1])toml");
|
||||
|
||||
// Insert an inline table before
|
||||
EXPECT_TRUE(root.InsertTable("table_array[0]", "table_array.table2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table2 = {}
|
||||
[table_array.table1])toml");
|
||||
|
||||
// Insert an inline table behind -> this will have to be printed before the standard table
|
||||
EXPECT_TRUE(root.InsertTable("", "table_array.table3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table2 = {}
|
||||
table3 = {}
|
||||
[table_array.table1])toml");
|
||||
|
||||
// Insert a standard table in front -> this will have to be printed behind the inline table
|
||||
EXPECT_TRUE(root.InsertTable("table_array[0]", "table_array.table4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table2 = {}
|
||||
table3 = {}
|
||||
[table_array.table4]
|
||||
[table_array.table1])toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertArrayInTableArray)
|
||||
{
|
||||
// Insert a standard table array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTableArray("", "table_array", false));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]])toml");
|
||||
|
||||
// Insert arrays
|
||||
EXPECT_TRUE(root.InsertArray("", "table_array.value_array1"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_array1 = [])toml");
|
||||
EXPECT_TRUE(root.InsertArray("", "table_array.value_array2"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_array1 = []
|
||||
value_array2 = [])toml");
|
||||
EXPECT_TRUE(root.InsertArray("table_array[0]", "table_array.value_array3"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_array3 = []
|
||||
value_array1 = []
|
||||
value_array2 = [])toml");
|
||||
}
|
||||
|
||||
TEST(CascadeInsertNode, InsertTableArrayInTableArray)
|
||||
{
|
||||
// Insert a standard table array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTableArray("", "table_array", false));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]])toml");
|
||||
|
||||
// Insert standard table array
|
||||
EXPECT_TRUE(root.InsertTableArray("", "table_array.table_array1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
[[table_array.table_array1]])toml");
|
||||
|
||||
// Insert an inline table array before
|
||||
EXPECT_TRUE(root.InsertTableArray("table_array[0]", "table_array.table_array2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table_array2 = [{}]
|
||||
[[table_array.table_array1]])toml");
|
||||
|
||||
// Insert an inline table array behind -> this will have to be printed before the standard table array
|
||||
EXPECT_TRUE(root.InsertTableArray("", "table_array.table_array3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[table_array.table_array1]])toml");
|
||||
|
||||
// Insert a standard table array in front -> this will have to be printed behind the inline table array
|
||||
EXPECT_TRUE(root.InsertTableArray("table_array[0]", "table_array.table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[table_array.table_array4]]
|
||||
[[table_array.table_array1]])toml");
|
||||
|
||||
// Add an additional table array entry for table array #4
|
||||
EXPECT_TRUE(root.InsertTableArray("", "table_array.table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[table_array.table_array4]]
|
||||
[[table_array.table_array1]]
|
||||
[[table_array.table_array4]])toml");
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/character_reader_utf_8.h"
|
||||
#include "../../../sdv_services/core/toml_parser/exception.h"
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
|
||||
TEST(GenerateTOML, CombineRoot)
|
||||
TEST(CombineReduse, CombineRoot)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(
|
||||
val1 = 10
|
||||
@@ -27,10 +27,10 @@ val1 = 10)toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Combine(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code(
|
||||
std::string ssCombinedTOML = R"toml(
|
||||
val1 = 10
|
||||
val2 = "20"
|
||||
val3 = 30.0)code";
|
||||
val3 = 30.0)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -38,7 +38,7 @@ val3 = 30.0)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineRootComments)
|
||||
TEST(CombineReduse, CombineRootComments)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(
|
||||
val1 = 10 # This is value 1
|
||||
@@ -49,10 +49,10 @@ val1 = 10 # This is again value 1)toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Combine(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code(
|
||||
std::string ssCombinedTOML = R"toml(
|
||||
val1 = 10 # This is value 1
|
||||
val2 = "20" # This is value 2
|
||||
val3 = 30.0 # This is value 3)code";
|
||||
val3 = 30.0 # This is value 3)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -60,7 +60,7 @@ val3 = 30.0 # This is value 3)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineRootwithTable)
|
||||
TEST(CombineReduse, CombineRootwithTableValues)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(
|
||||
val1 = 10
|
||||
@@ -73,10 +73,10 @@ val1 = 10)toml");
|
||||
ASSERT_TRUE(ptrTable);
|
||||
EXPECT_TRUE(parser1.Root().Combine(ptrTable->Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code(
|
||||
std::string ssCombinedTOML = R"toml(
|
||||
val1 = 10
|
||||
val2 = "20"
|
||||
val3 = 30.0)code";
|
||||
val3 = 30.0)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -84,7 +84,55 @@ val3 = 30.0)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineTablewithRoot)
|
||||
TEST(CombineReduse, CombineRootwithStandardTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(
|
||||
val1 = 10
|
||||
val2 = "20")toml");
|
||||
toml_parser::CParser parser2(R"toml([MyTable]
|
||||
val3 = 30.0
|
||||
val1 = 10)toml");
|
||||
|
||||
auto ptrTable = &parser2.Root();
|
||||
ASSERT_TRUE(ptrTable);
|
||||
EXPECT_TRUE(parser1.Root().Combine(ptrTable->Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"toml(
|
||||
val1 = 10
|
||||
val2 = "20"
|
||||
[MyTable]
|
||||
val3 = 30.0
|
||||
val1 = 10)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(CombineReduse, CombineRootwithInlineTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(
|
||||
val1 = 10
|
||||
val2 = "20")toml");
|
||||
toml_parser::CParser parser2(R"toml(MyTable = {val3 = 30.0, val1 = 10})toml");
|
||||
|
||||
auto ptrTable = &parser2.Root();
|
||||
ASSERT_TRUE(ptrTable);
|
||||
EXPECT_TRUE(parser1.Root().Combine(ptrTable->Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"toml(
|
||||
val1 = 10
|
||||
val2 = "20"
|
||||
MyTable = {val3 = 30.0, val1 = 10})toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(CombineReduse, CombineTablewithRoot)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml([MyTable]
|
||||
val1 = 10
|
||||
@@ -99,10 +147,10 @@ val1 = 10)toml");
|
||||
ASSERT_TRUE(ptrTable);
|
||||
EXPECT_TRUE(ptrTable->Combine(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code([MyTable]
|
||||
std::string ssCombinedTOML = R"toml([MyTable]
|
||||
val1 = 10
|
||||
val2 = "20"
|
||||
val3 = 30.0)code";
|
||||
val3 = 30.0)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -110,7 +158,7 @@ val3 = 30.0)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineTablewithDifferentTable)
|
||||
TEST(CombineReduse, CombineTablewithDifferentTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml([MyTable1]
|
||||
val1 = 10
|
||||
@@ -129,10 +177,10 @@ val1 = 10)toml");
|
||||
ASSERT_TRUE(ptrTable2);
|
||||
EXPECT_TRUE(ptrTable1->Combine(ptrTable2));
|
||||
|
||||
std::string ssCombinedTOML = R"code([MyTable1]
|
||||
std::string ssCombinedTOML = R"toml([MyTable1]
|
||||
val1 = 10
|
||||
val2 = "20"
|
||||
val3 = 30.0)code";
|
||||
val3 = 30.0)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -140,7 +188,7 @@ val3 = 30.0)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineTablewithIdenticalTable)
|
||||
TEST(CombineReduse, CombineTablewithIdenticalTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml([MyTable]
|
||||
val1 = 10
|
||||
@@ -151,10 +199,10 @@ val1 = 10)toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Combine(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code([MyTable]
|
||||
std::string ssCombinedTOML = R"toml([MyTable]
|
||||
val1 = 10
|
||||
val2 = "20"
|
||||
val3 = 30.0)code";
|
||||
val3 = 30.0)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -162,7 +210,7 @@ val3 = 30.0)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineInlineTablewithDifferentStandardTable)
|
||||
TEST(CombineReduse, CombineInlineTablewithDifferentStandardTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(MyTable1 = {val1 = 10, val2 = "20"})toml");
|
||||
toml_parser::CParser parser2(R"toml([MyTable2]
|
||||
@@ -179,7 +227,7 @@ val1 = 10)toml");
|
||||
ASSERT_TRUE(ptrTable2);
|
||||
EXPECT_TRUE(ptrTable1->Combine(ptrTable2));
|
||||
|
||||
std::string ssCombinedTOML = R"code(MyTable1 = {val1 = 10, val2 = "20", val3 = 30.0})code";
|
||||
std::string ssCombinedTOML = R"toml(MyTable1 = {val1 = 10, val2 = "20", val3 = 30.0})toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -187,7 +235,7 @@ val1 = 10)toml");
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineInlineTablewithIdenticalStandardTable)
|
||||
TEST(CombineReduse, CombineInlineTablewithIdenticalStandardTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(MyTable = {val1 = 10, val2 = "20"})toml");
|
||||
toml_parser::CParser parser2(R"toml([MyTable]
|
||||
@@ -196,7 +244,7 @@ val1 = 10)toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Combine(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code(MyTable = {val1 = 10, val2 = "20", val3 = 30.0})code";
|
||||
std::string ssCombinedTOML = R"toml(MyTable = {val1 = 10, val2 = "20", val3 = 30.0})toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -204,7 +252,7 @@ val1 = 10)toml");
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineStandardTablewithDifferentInlineTable)
|
||||
TEST(CombineReduse, CombineStandardTablewithDifferentInlineTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml([MyTable1]
|
||||
val1 = 10
|
||||
@@ -221,10 +269,10 @@ val2 = "20")toml");
|
||||
ASSERT_TRUE(ptrTable2);
|
||||
EXPECT_TRUE(ptrTable1->Combine(ptrTable2));
|
||||
|
||||
std::string ssCombinedTOML = R"code([MyTable1]
|
||||
std::string ssCombinedTOML = R"toml([MyTable1]
|
||||
val1 = 10
|
||||
val2 = "20"
|
||||
val3 = 30.0)code";
|
||||
val3 = 30.0)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -232,7 +280,7 @@ val3 = 30.0)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineStandardTablewithIdenticalInlineTable)
|
||||
TEST(CombineReduse, CombineStandardTablewithIdenticalInlineTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml([MyTable]
|
||||
val1 = 10
|
||||
@@ -241,10 +289,10 @@ val2 = "20")toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Combine(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code([MyTable]
|
||||
std::string ssCombinedTOML = R"toml([MyTable]
|
||||
val1 = 10
|
||||
val2 = "20"
|
||||
val3 = 30.0)code";
|
||||
val3 = 30.0)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -252,7 +300,7 @@ val3 = 30.0)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineInlineTablewithDifferentInlineTable)
|
||||
TEST(CombineReduse, CombineInlineTablewithDifferentInlineTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(MyTable1 = {val1 = 10, val2 = "20"})toml");
|
||||
toml_parser::CParser parser2(R"toml(MyTable2 = {val3 = 30.0, val1 = 10})toml");
|
||||
@@ -267,7 +315,7 @@ TEST(GenerateTOML, CombineInlineTablewithDifferentInlineTable)
|
||||
ASSERT_TRUE(ptrTable2);
|
||||
EXPECT_TRUE(ptrTable1->Combine(ptrTable2));
|
||||
|
||||
std::string ssCombinedTOML = R"code(MyTable1 = {val1 = 10, val2 = "20", val3 = 30.0})code";
|
||||
std::string ssCombinedTOML = R"toml(MyTable1 = {val1 = 10, val2 = "20", val3 = 30.0})toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -275,14 +323,14 @@ TEST(GenerateTOML, CombineInlineTablewithDifferentInlineTable)
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineInlineTablewithIdenticalInlineTable)
|
||||
TEST(CombineReduse, CombineInlineTablewithIdenticalInlineTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(MyTable = {val1 = 10, val2 = "20"})toml");
|
||||
toml_parser::CParser parser2(R"toml(MyTable = {val3 = 30.0, val1 = 10})toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Combine(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code(MyTable = {val1 = 10, val2 = "20", val3 = 30.0})code";
|
||||
std::string ssCombinedTOML = R"toml(MyTable = {val1 = 10, val2 = "20", val3 = 30.0})toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -290,7 +338,7 @@ TEST(GenerateTOML, CombineInlineTablewithIdenticalInlineTable)
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineDifferentArrays)
|
||||
TEST(CombineReduse, CombineDifferentArrays)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(
|
||||
val1 = [10, 20]
|
||||
@@ -301,10 +349,10 @@ val1 = [70, 80])toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Combine(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code(
|
||||
std::string ssCombinedTOML = R"toml(
|
||||
val1 = [70, 80]
|
||||
val2 = ["30", "40"]
|
||||
val3 = [50.0, 60.0])code";
|
||||
val3 = [50.0, 60.0])toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -312,12 +360,13 @@ val3 = [50.0, 60.0])code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, CombineDifferentTableArrays)
|
||||
TEST(CombineReduse, CombineDifferentTableArrays)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml([[table_array1]]
|
||||
val1 = [10, 20]
|
||||
[[table_array1]]
|
||||
val2 = ["30", "40"])toml");
|
||||
|
||||
toml_parser::CParser parser2(R"toml(
|
||||
[[table_array2]]
|
||||
val3 = [50.0, 60.0]
|
||||
@@ -326,14 +375,14 @@ val1 = [70, 80])toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Combine(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code([[table_array1]]
|
||||
std::string ssCombinedTOML = R"toml([[table_array1]]
|
||||
val1 = [10, 20]
|
||||
[[table_array1]]
|
||||
val2 = ["30", "40"]
|
||||
[[table_array2]]
|
||||
val3 = [50.0, 60.0]
|
||||
[[table_array2]]
|
||||
val1 = [70, 80])code";
|
||||
val1 = [70, 80])toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -341,7 +390,7 @@ val1 = [70, 80])code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, ReduceRoot)
|
||||
TEST(CombineReduse, ReduceRoot)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(
|
||||
val1 = 10
|
||||
@@ -353,9 +402,8 @@ val1 = 10)toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Reduce(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code(
|
||||
val2 = "20"
|
||||
val3 = 30.0)code";
|
||||
std::string ssCombinedTOML = R"toml(val2 = "20"
|
||||
val3 = 30.0)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -363,7 +411,7 @@ val3 = 30.0)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, ReduceRootComments)
|
||||
TEST(CombineReduse, ReduceRootComments)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(
|
||||
val1 = 10 # This is value 1
|
||||
@@ -375,9 +423,8 @@ val1 = 10 # This also is value 1)toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Reduce(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code(
|
||||
val2 = "20" # This is value 2
|
||||
val3 = 30.0 # This is value 3)code";
|
||||
std::string ssCombinedTOML = R"toml(val2 = "20" # This is value 2
|
||||
val3 = 30.0 # This is value 3)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -385,7 +432,7 @@ val3 = 30.0 # This is value 3)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, ReduceTable)
|
||||
TEST(CombineReduse, ReduceTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml([my_table]
|
||||
val1 = 10
|
||||
@@ -397,9 +444,9 @@ val1 = 10)toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Reduce(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code([my_table]
|
||||
std::string ssCombinedTOML = R"toml([my_table]
|
||||
val2 = "20"
|
||||
val3 = 30.0)code";
|
||||
val3 = 30.0)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -407,7 +454,7 @@ val3 = 30.0)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, ReduceStandardTableWithInlineTable)
|
||||
TEST(CombineReduse, ReduceStandardTableWithInlineTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml([my_table]
|
||||
val1 = 10
|
||||
@@ -417,9 +464,9 @@ val3 = 30.0)toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Reduce(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code([my_table]
|
||||
std::string ssCombinedTOML = R"toml([my_table]
|
||||
val2 = "20"
|
||||
val3 = 30.0)code";
|
||||
val3 = 30.0)toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -427,7 +474,7 @@ val3 = 30.0)code";
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, ReduceInlineTableWithStandardTable)
|
||||
TEST(CombineReduse, ReduceInlineTableWithStandardTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(my_table = {val1 = 10, val2 = "20", val3 = 30.0})toml");
|
||||
toml_parser::CParser parser2(R"toml([my_table]
|
||||
@@ -436,7 +483,7 @@ val1 = 10)toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Reduce(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code(my_table = { val2 = "20", val3 = 30.0})code";
|
||||
std::string ssCombinedTOML = R"toml(my_table = { val2 = "20", val3 = 30.0})toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -444,14 +491,14 @@ val1 = 10)toml");
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, ReduceInlineTable)
|
||||
TEST(CombineReduse, ReduceInlineTable)
|
||||
{
|
||||
toml_parser::CParser parser1(R"toml(my_table = {val1 = 10, val2 = "20", val3 = 30.0})toml");
|
||||
toml_parser::CParser parser2(R"toml(my_table = {val3 = 35.0, val1 = 10})toml");
|
||||
|
||||
EXPECT_TRUE(parser1.Root().Reduce(parser2.Root().Cast<toml_parser::CNodeCollection>()));
|
||||
|
||||
std::string ssCombinedTOML = R"code(my_table = { val2 = "20", val3 = 30.0})code";
|
||||
std::string ssCombinedTOML = R"toml(my_table = { val2 = "20", val3 = 30.0})toml";
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser1.GenerateTOML());
|
||||
@@ -459,12 +506,12 @@ TEST(GenerateTOML, ReduceInlineTable)
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, ReduceDifferentArrays)
|
||||
TEST(CombineReduse, ReduceDifferentArrays)
|
||||
{
|
||||
toml_parser::CParser parser1(R"code(
|
||||
toml_parser::CParser parser1(R"toml(
|
||||
val1 = [10, 20]
|
||||
val2 = ["30", "40"]
|
||||
val3 = [50.0, 60.0])code");
|
||||
val3 = [50.0, 60.0])toml");
|
||||
toml_parser::CParser parser2(R"toml(
|
||||
val3 = [50.0, 60.0]
|
||||
val1 = [70, 80])toml");
|
||||
@@ -482,16 +529,16 @@ val2 = ["30", "40"]
|
||||
EXPECT_EQ(ssGenerated, ssCombinedTOML);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, ReduceDifferentTableArrays)
|
||||
TEST(CombineReduse, ReduceDifferentTableArrays)
|
||||
{
|
||||
toml_parser::CParser parser1(R"code([[table_array1]]
|
||||
toml_parser::CParser parser1(R"toml([[table_array1]]
|
||||
val1 = [10, 20]
|
||||
[[table_array1]]
|
||||
val2 = ["30", "40"]
|
||||
[[table_array2]]
|
||||
val3 = [50.0, 60.0]
|
||||
[[table_array2]]
|
||||
val1 = [70, 80])code");
|
||||
val1 = [70, 80])toml");
|
||||
toml_parser::CParser parser2(R"toml(
|
||||
[[table_array1]]
|
||||
val2 = ["30", "40"]
|
||||
386
tests/unit_tests/toml_parser/comparison_tests.cpp
Normal file
386
tests/unit_tests/toml_parser/comparison_tests.cpp
Normal file
@@ -0,0 +1,386 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <functional>
|
||||
#include <gtest/gtest.h>
|
||||
#include <limits>
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include <support/toml.h>
|
||||
#include "../../../sdv_services/core/toml_parser/exception.h"
|
||||
#include "../../../sdv_services/core/toml_parser/miscellaneous.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
|
||||
bool CompareTest(const std::string& rssToml1, const std::string& rssToml2,
|
||||
uint32_t uiCompareFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_all))
|
||||
{
|
||||
try
|
||||
{
|
||||
toml_parser::CParser parser1(rssToml1);
|
||||
toml_parser::CParser parser2(rssToml2);
|
||||
sdv::toml::CNodeCollection collection1(&parser1.Root());
|
||||
sdv::toml::CNodeCollection collection2(&parser2.Root());
|
||||
return sdv::toml::internal::CompareNodes(collection1, collection2, uiCompareFlags) ==
|
||||
sdv::toml::ECompareResult::compare_identical;
|
||||
}
|
||||
catch (const toml_parser::XTOMLParseException&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Comparison, CompareInvalid)
|
||||
{
|
||||
EXPECT_FALSE(CompareTest("var = A", ""));
|
||||
EXPECT_FALSE(CompareTest("[[test]", ""));
|
||||
EXPECT_FALSE(CompareTest(R"toml([test]
|
||||
test1 = "this is invalid')toml", ""));
|
||||
}
|
||||
|
||||
TEST(Comparison, CompareEmpty)
|
||||
{
|
||||
// Identical
|
||||
uint32_t uiFlags = 0u;
|
||||
EXPECT_FALSE(CompareTest("var = 1", "", uiFlags));
|
||||
EXPECT_FALSE(CompareTest("", "var = 2", uiFlags));
|
||||
EXPECT_TRUE(CompareTest("", "", uiFlags));
|
||||
EXPECT_FALSE(CompareTest("", R"toml(
|
||||
)toml", uiFlags));
|
||||
EXPECT_FALSE(CompareTest("", R"toml(# This is a comment)toml", uiFlags));
|
||||
|
||||
// Ignore whitespace
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_whitespace);
|
||||
EXPECT_FALSE(CompareTest("var = 1", "", uiFlags));
|
||||
EXPECT_FALSE(CompareTest("", "var = 2", uiFlags));
|
||||
EXPECT_TRUE(CompareTest("", "", uiFlags));
|
||||
EXPECT_TRUE(CompareTest("", R"toml(
|
||||
)toml", uiFlags));
|
||||
EXPECT_FALSE(CompareTest("", R"toml(# This is a comment)toml", uiFlags));
|
||||
|
||||
// Ignore comments
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_comments);
|
||||
EXPECT_FALSE(CompareTest("var = 1", "", uiFlags));
|
||||
EXPECT_FALSE(CompareTest("", "var = 2", uiFlags));
|
||||
EXPECT_TRUE(CompareTest("", "", uiFlags));
|
||||
EXPECT_TRUE(CompareTest("", R"toml(
|
||||
)toml", uiFlags));
|
||||
EXPECT_TRUE(CompareTest("", R"toml(# This is a comment)toml", uiFlags));
|
||||
}
|
||||
|
||||
TEST(Comparison, CompareValues)
|
||||
{
|
||||
std::string ssVal = "val = 1";
|
||||
std::string ssVal2 = "val = 2";
|
||||
std::string ssValSpace = " val = 1";
|
||||
std::string ssValCommentsBefore = R"toml(# comment
|
||||
|
||||
# more comment
|
||||
val = 1)toml";
|
||||
std::string ssValCommentsBehind = R"toml( val = 1 # comment
|
||||
# more comment
|
||||
|
||||
# lots more comment)toml";
|
||||
|
||||
// Identical
|
||||
uint32_t uiFlags = 0u;
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssVal, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssVal, ssVal2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssVal, ssValSpace, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssVal, ssValCommentsBefore, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssVal, ssValCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore whitespace
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_whitespace);
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssVal, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssVal, ssVal2, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssValSpace, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssVal, ssValCommentsBefore, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssVal, ssValCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore comments
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_comments);
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssVal, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssVal, ssVal2, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssValSpace, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssValCommentsBefore, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssValCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore all
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_all);
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssVal, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssVal, ssVal2, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssValSpace, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssValCommentsBefore, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssVal, ssValCommentsBehind, uiFlags));
|
||||
}
|
||||
|
||||
TEST(Comparison, CompareTables)
|
||||
{
|
||||
std::string ssStandardTable = R"toml([table1]
|
||||
val = 1)toml";
|
||||
std::string ssStandardTable2 = R"toml([table2]
|
||||
val = 1)toml";
|
||||
std::string ssStandardTable1_3 = R"toml([table1]
|
||||
val = 3)toml";
|
||||
std::string ssInlineTable = R"toml(table1 = {val = 1})toml";
|
||||
std::string ssTableSpace = R"toml( [table1]
|
||||
|
||||
val = 1)toml";
|
||||
std::string ssTableCommentsBefore = R"toml(# comment
|
||||
|
||||
# more comment
|
||||
[table1]
|
||||
val = 1)toml";
|
||||
std::string ssTableCommentsBehind = R"toml( [table1] # comment
|
||||
val = 1 # comment
|
||||
# more comment
|
||||
|
||||
# lots more comment)toml";
|
||||
|
||||
// Identical
|
||||
uint32_t uiFlags = 0u;
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssStandardTable, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssStandardTable2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssStandardTable1_3, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssInlineTable, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssTableSpace, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssTableCommentsBefore, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssTableCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore whitespace
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_whitespace);
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssStandardTable, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssStandardTable2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssStandardTable1_3, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssInlineTable, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssTableSpace, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssTableCommentsBefore, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssTableCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore comments
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_comments);
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssStandardTable, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssStandardTable2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssStandardTable1_3, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssInlineTable, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssTableSpace, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssTableCommentsBefore, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssTableCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore inline
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_inline);
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssStandardTable, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssStandardTable2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssStandardTable1_3, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssInlineTable, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssTableSpace, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssTableCommentsBefore, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssTableCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore all
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_all);
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssStandardTable, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssStandardTable2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTable, ssStandardTable1_3, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssInlineTable, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssTableSpace, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssTableCommentsBefore, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTable, ssTableCommentsBehind, uiFlags));
|
||||
}
|
||||
|
||||
TEST(Comparison, CompareArrays)
|
||||
{
|
||||
std::string ssStandardArray = R"toml(array1 = [123, 456])toml";
|
||||
std::string ssStandardArray2 = R"toml(array2 = [789, 543])toml";
|
||||
std::string ssArraySpace = R"toml( array1 = [
|
||||
123,
|
||||
456 ])toml";
|
||||
std::string ssArrayCommentsBefore = R"toml(# comment
|
||||
array1 =
|
||||
# more comment
|
||||
[ 123, # xyz
|
||||
456])toml";
|
||||
std::string ssArrayCommentsBehind = R"toml( array1 = [123, 456] # comment
|
||||
# more comment
|
||||
|
||||
# lots more comment)toml";
|
||||
|
||||
// Identical
|
||||
uint32_t uiFlags = 0u;
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssStandardArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardArray, ssStandardArray2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardArray, ssArraySpace, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardArray, ssArrayCommentsBefore, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardArray, ssArrayCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore whitespace
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_whitespace);
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssStandardArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardArray, ssStandardArray2, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssArraySpace, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardArray, ssArrayCommentsBefore, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardArray, ssArrayCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore comments
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_comments);
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssStandardArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardArray, ssStandardArray2, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssArraySpace, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssArrayCommentsBefore, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssArrayCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore all
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_all);
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssStandardArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardArray, ssStandardArray2, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssArraySpace, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssArrayCommentsBefore, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardArray, ssArrayCommentsBehind, uiFlags));
|
||||
}
|
||||
|
||||
TEST(Comparison, CompareTableArrays)
|
||||
{
|
||||
std::string ssStandardTableArray = R"toml([[tableArray1]]
|
||||
val = 1)toml";
|
||||
std::string ssStandardTableArray2 = R"toml([[tableArray2]]
|
||||
val = 1)toml";
|
||||
std::string ssStandardTableArray1_3 = R"toml([[tableArray1]]
|
||||
val = 3)toml";
|
||||
std::string ssInlineTableArray = R"toml(tableArray1 = [{val = 1}])toml";
|
||||
std::string ssTableSpaceArray = R"toml( [[tableArray1]]
|
||||
|
||||
val = 1)toml";
|
||||
std::string ssTableArrayCommentsBefore = R"toml(# comment
|
||||
|
||||
# more comment
|
||||
[[tableArray1]]
|
||||
val = 1)toml";
|
||||
std::string ssTableArrayCommentsBehind = R"toml( [[tableArray1]] # comment
|
||||
val = 1 # comment
|
||||
# more comment
|
||||
|
||||
# lots more comment)toml";
|
||||
|
||||
// Identical
|
||||
uint32_t uiFlags = 0u;
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssStandardTableArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssStandardTableArray2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssStandardTableArray1_3, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssInlineTableArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssTableSpaceArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssTableArrayCommentsBefore, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssTableArrayCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore whitespace
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_whitespace);
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssStandardTableArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssStandardTableArray2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssStandardTableArray1_3, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssInlineTableArray, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssTableSpaceArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssTableArrayCommentsBefore, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssTableArrayCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore comments
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_comments);
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssStandardTableArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssStandardTableArray2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssStandardTableArray1_3, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssInlineTableArray, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssTableSpaceArray, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssTableArrayCommentsBefore, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssTableArrayCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore inline
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_inline);
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssStandardTableArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssStandardTableArray2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssStandardTableArray1_3, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssInlineTableArray, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssTableSpaceArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssTableArrayCommentsBefore, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssTableArrayCommentsBehind, uiFlags));
|
||||
|
||||
// Ignore all
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_all);
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssStandardTableArray, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssStandardTableArray2, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssStandardTableArray, ssStandardTableArray1_3, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssInlineTableArray, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssTableSpaceArray, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssTableArrayCommentsBefore, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssStandardTableArray, ssTableArrayCommentsBehind, uiFlags));
|
||||
}
|
||||
|
||||
TEST(Comparison, CompareComplex)
|
||||
{
|
||||
std::string ssToml1 = R"toml(# This is a complex TOML file
|
||||
|
||||
# Top value description
|
||||
[Top]
|
||||
value1 = 1 # Value 1
|
||||
valueA = "A" # Value A
|
||||
arrayBCD = [ "B", # Array element B
|
||||
"C", # Array element C
|
||||
"D" ] # Array element D
|
||||
|
||||
# Table 1
|
||||
[Top.table1]
|
||||
value2 = 2 # Value 2
|
||||
|
||||
# Table array in table 1
|
||||
[[Top.table1.table_array]] # Table array
|
||||
valueE = "E"
|
||||
|
||||
[[Top.table1.table_array]] # Table array
|
||||
valueF = "F"
|
||||
|
||||
[Top.table1.other_table]
|
||||
inline_table = { x = "X", y = "Y", z = "Z" } # Inline table
|
||||
|
||||
[[Top.table1.table_array]] # Table array
|
||||
valueG = "G"
|
||||
)toml";
|
||||
|
||||
std::string ssToml2 = R"toml(
|
||||
[Top]
|
||||
value1 = 1
|
||||
valueA = "A"
|
||||
arrayBCD = ["B", "C", "D" ]
|
||||
table1 = { value2 = 2, table_array = [{valueE = "E"}, {valueF = "F"}, {valueG = "G"}], other_table = { inline_table = {x = "X", y = "Y", z = "Z"}}} # Mega table
|
||||
)toml";
|
||||
|
||||
// Identical
|
||||
uint32_t uiFlags = 0u;
|
||||
EXPECT_TRUE(CompareTest(ssToml1, ssToml1, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssToml1, ssToml2, uiFlags));
|
||||
|
||||
// Ignore whitespace
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_whitespace);
|
||||
EXPECT_TRUE(CompareTest(ssToml1, ssToml1, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssToml1, ssToml2, uiFlags));
|
||||
|
||||
// Ignore comments
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_comments);
|
||||
EXPECT_TRUE(CompareTest(ssToml1, ssToml1, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssToml1, ssToml2, uiFlags));
|
||||
|
||||
// Ignore inline
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_inline);
|
||||
EXPECT_TRUE(CompareTest(ssToml1, ssToml1, uiFlags));
|
||||
EXPECT_FALSE(CompareTest(ssToml1, ssToml2, uiFlags));
|
||||
|
||||
// Ignore all
|
||||
uiFlags = static_cast<uint32_t>(sdv::toml::ECompareFlags::compare_ignore_all);
|
||||
EXPECT_TRUE(CompareTest(ssToml1, ssToml1, uiFlags));
|
||||
EXPECT_TRUE(CompareTest(ssToml1, ssToml2, uiFlags));
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
|
||||
@@ -45,321 +45,315 @@
|
||||
* @param[in] rssOuput Reference to the expected ouput.
|
||||
* @return Returns 'true' on success.
|
||||
*/
|
||||
bool TestDelete(const std::string& rssTOMLInput, const std::string& rssKey, const std::string& rssOutput)
|
||||
std::string DeleteNode(const std::string& rssTOMLInput, const std::string& rssKey)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
bool bRes = true;
|
||||
EXPECT_NO_THROW(bRes = parser.Process(rssTOMLInput));
|
||||
EXPECT_TRUE(bRes);
|
||||
if (!bRes) return bRes;
|
||||
if (!bRes) return {};
|
||||
auto ptrNode = parser.Root().Direct(rssKey);
|
||||
EXPECT_TRUE(ptrNode);
|
||||
if (!ptrNode) return false;
|
||||
if (!ptrNode) return {};
|
||||
EXPECT_TRUE(bRes = ptrNode->DeleteNode());
|
||||
if (!bRes) return bRes;
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, rssOutput);
|
||||
if (ssTOML != rssOutput) return false;
|
||||
return true;
|
||||
if (!bRes) return {};
|
||||
return parser.GenerateTOML();
|
||||
};
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteValues)
|
||||
TEST(DeleteNode, DeleteValues)
|
||||
{
|
||||
// Delete a key from the begin (whitespace reduced)
|
||||
EXPECT_TRUE(TestDelete(R"toml(key = 10 # value key
|
||||
EXPECT_EQ(DeleteNode(R"toml(key = 10 # value key
|
||||
bare_key = "value" # value bare_key
|
||||
bare-key = false # value bare-key)toml",
|
||||
"key",
|
||||
"key"),
|
||||
R"toml(bare_key = "value" # value bare_key
|
||||
bare-key = false # value bare-key)toml"));
|
||||
bare-key = false # value bare-key)toml");
|
||||
|
||||
// Delete a key from the begin
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = 10 # value key
|
||||
bare_key = "value" # value bare_key
|
||||
bare-key = false # value bare-key
|
||||
)toml",
|
||||
"key",
|
||||
R"toml(
|
||||
bare_key = "value" # value bare_key
|
||||
"key"),
|
||||
R"toml(bare_key = "value" # value bare_key
|
||||
bare-key = false # value bare-key
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
// Delete a key from the middle
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = 10 # value key
|
||||
bare_key = "value" # value bare_key
|
||||
bare-key = false # value bare-key
|
||||
)toml",
|
||||
"bare_key",
|
||||
"bare_key"),
|
||||
R"toml(
|
||||
key = 10 # value key
|
||||
bare-key = false # value bare-key
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
// Delete a key from the end
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = 10 # value key
|
||||
bare_key = "value" # value bare_key
|
||||
bare-key = false # value bare-key
|
||||
)toml",
|
||||
"bare-key",
|
||||
"bare-key"),
|
||||
R"toml(
|
||||
key = 10 # value key
|
||||
bare_key = "value" # value bare_key
|
||||
)toml"));
|
||||
)toml");
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteInlineTableValues)
|
||||
TEST(DeleteNode, DeleteInlineTableValues)
|
||||
{
|
||||
// Delete key from the inline table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"1234.y",
|
||||
"1234.y"),
|
||||
R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, z = 2, str = "abc"}
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"1234.x",
|
||||
"1234.x"),
|
||||
R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = { y = 1, z = 2, str = "abc"}
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"1234.str",
|
||||
"1234.str"),
|
||||
R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2}
|
||||
)toml"));
|
||||
|
||||
)toml");
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteInlineSubTableValues)
|
||||
TEST(DeleteNode, DeleteInlineSubTableValues)
|
||||
{
|
||||
// Delete key from the inline sub-table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc", tbl={a =1, b=2, c=3}}
|
||||
)toml",
|
||||
"1234.tbl.b",
|
||||
"1234.tbl.b"),
|
||||
R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc", tbl={a =1, c=3}}
|
||||
)toml"));
|
||||
|
||||
)toml");
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteInlineTables)
|
||||
TEST(DeleteNode, DeleteInlineTables)
|
||||
{
|
||||
// Delete table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc", tbl={a =1, b=2, c=3}}
|
||||
)toml",
|
||||
"1234.tbl",
|
||||
"1234.tbl"),
|
||||
R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc", tbl={a =1, b=2, c=3}}
|
||||
)toml",
|
||||
"1234",
|
||||
"1234"),
|
||||
R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml"));
|
||||
)toml");
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteTableValues)
|
||||
TEST(DeleteNode, DeleteTableValues)
|
||||
{
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml",
|
||||
"my_table.key",
|
||||
"my_table.key"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
// Delete a key from the middle
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml",
|
||||
"my_table.bare_key",
|
||||
"my_table.bare_key"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare-key = false
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
// Delete a key from the end
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml",
|
||||
"my_table.bare-key",
|
||||
"my_table.bare-key"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteInlineTableValueInTable)
|
||||
TEST(DeleteNode, DeleteInlineTableValueInTable)
|
||||
{
|
||||
// Delete key from the inline table in a table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"my_table.1234.y",
|
||||
"my_table.1234.y"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, z = 2, str = "abc"}
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"my_table.1234.x",
|
||||
"my_table.1234.x"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = { y = 1, z = 2, str = "abc"}
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"my_table.1234.str",
|
||||
"my_table.1234.str"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2}
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteInlineSubTableValueInTable)
|
||||
TEST(DeleteNode, DeleteInlineSubTableValueInTable)
|
||||
{
|
||||
// Delete key from the inline sub-table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc", tbl={a =1, b=2, c=3}}
|
||||
)toml",
|
||||
"my_table.1234.tbl.b",
|
||||
"my_table.1234.tbl.b"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc", tbl={a =1, c=3}}
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteInlineTableInTable)
|
||||
TEST(DeleteNode, DeleteInlineTableInTable)
|
||||
{
|
||||
// Delete table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc", tbl={a =1, b=2, c=3}}
|
||||
)toml",
|
||||
"my_table.1234.tbl",
|
||||
"my_table.1234.tbl"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc", tbl={a =1, b=2, c=3}}
|
||||
)toml",
|
||||
"my_table.1234",
|
||||
"my_table.1234"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteValuesInChildTable)
|
||||
TEST(DeleteNode, DeleteValuesInChildTable)
|
||||
{
|
||||
// Delete key from the child-table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
@@ -370,7 +364,7 @@ y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml",
|
||||
"my_table.1234.y",
|
||||
"my_table.1234.y"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
@@ -380,8 +374,8 @@ bare-key = false
|
||||
x = 0
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
@@ -392,7 +386,7 @@ y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml",
|
||||
"my_table.1234.x",
|
||||
"my_table.1234.x"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
@@ -402,8 +396,8 @@ bare-key = false
|
||||
y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
@@ -414,7 +408,7 @@ y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml",
|
||||
"my_table.1234.str",
|
||||
"my_table.1234.str"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
@@ -424,14 +418,14 @@ bare-key = false
|
||||
x = 0
|
||||
y = 1
|
||||
z = 2
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteChildTableInTable)
|
||||
TEST(DeleteNode, DeleteChildTableInTable)
|
||||
{
|
||||
// Delete table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
@@ -446,7 +440,7 @@ a =1
|
||||
b=2
|
||||
c=3
|
||||
)toml",
|
||||
"my_table.1234.tbl",
|
||||
"my_table.1234.tbl"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
@@ -457,8 +451,8 @@ x = 0
|
||||
y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
@@ -473,176 +467,176 @@ a =1
|
||||
b=2
|
||||
c=3
|
||||
)toml",
|
||||
"my_table.1234",
|
||||
"my_table.1234"),
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml"));
|
||||
)toml");
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteArrayValues)
|
||||
TEST(DeleteNode, DeleteArrayValues)
|
||||
{
|
||||
// Delete array values
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml",
|
||||
"key[0]",
|
||||
"key[0]"),
|
||||
R"toml(
|
||||
key = [ 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml",
|
||||
"key[1]",
|
||||
"key[1]"),
|
||||
R"toml(
|
||||
key = [10, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml",
|
||||
"key[2]",
|
||||
"key[2]"),
|
||||
R"toml(
|
||||
key = [10, 20]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteArrayValuesWithSucceedingComma)
|
||||
TEST(DeleteNode, DeleteArrayValuesWithSucceedingComma)
|
||||
{
|
||||
// Delete array values with succeeding comma
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml",
|
||||
"bare_key[0]",
|
||||
"bare_key[0]"),
|
||||
R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = [ "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml",
|
||||
"bare_key[1]",
|
||||
"bare_key[1]"),
|
||||
R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml",
|
||||
"bare_key[2]",
|
||||
"bare_key[2]"),
|
||||
R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml"));
|
||||
)toml");
|
||||
|
||||
}
|
||||
|
||||
TEST(TOMLDeleteNode, DeleteValuesWithComments)
|
||||
TEST(DeleteNode, DeleteValuesWithComments)
|
||||
{
|
||||
// Delete array values with comments
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml",
|
||||
"bare-key[0]",
|
||||
"bare-key[0]"),
|
||||
R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [ 2020, # value 1
|
||||
]
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml",
|
||||
"bare-key[0].a",
|
||||
"bare-key[0].a"),
|
||||
R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{ b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml",
|
||||
"bare-key[0].b",
|
||||
"bare-key[0].b"),
|
||||
R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
)toml");
|
||||
EXPECT_EQ(DeleteNode(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
2020, # value 1
|
||||
]
|
||||
)toml",
|
||||
"bare-key[1]",
|
||||
"bare-key[1]"),
|
||||
R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030, ]
|
||||
bare-key = [{a = false, b = true}, # value 0
|
||||
]
|
||||
)toml"));
|
||||
)toml");
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,21 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
|
||||
// Test TODO:
|
||||
// Shift nodes up and down within one container
|
||||
// Remove formatting from node
|
||||
@@ -1,50 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
|
||||
// Test TODO:
|
||||
// Switch to inline and vice versa
|
||||
|
||||
TEST(GenerateTOML, SwitchTableToInline)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code([table]
|
||||
key1 = "some string"
|
||||
key2 = 123)code";
|
||||
std::string ssTOMLOutput = R"code(table = {key1 = "some string", key2 = 123})code";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
std::string ssGenerated;
|
||||
EXPECT_NO_THROW(ssGenerated = parser.GenerateTOML());
|
||||
EXPECT_EQ(ssGenerated, ssTOMLInput);
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrTable = parser.Root().GetNodeDirect("table");
|
||||
EXPECT_TRUE(ptrTable);
|
||||
sdv::toml::INodeInfo* pInfo = ptrTable.GetInterface<sdv::toml::INodeInfo>();
|
||||
sdv::toml::INodeCollectionConvert* pConvert = ptrTable.GetInterface<sdv::toml::INodeCollectionConvert>();
|
||||
ASSERT_NE(pInfo, nullptr);
|
||||
ASSERT_NE(pConvert, nullptr);
|
||||
EXPECT_FALSE(pInfo->IsInline());
|
||||
EXPECT_TRUE(pConvert->CanMakeInline());
|
||||
EXPECT_TRUE(pConvert->MakeInline());
|
||||
EXPECT_TRUE(pInfo->IsInline());
|
||||
|
||||
EXPECT_NO_THROW(ssGenerated = parser.GenerateTOML());
|
||||
EXPECT_EQ(ssGenerated, ssTOMLOutput);
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
|
||||
@@ -19,7 +20,7 @@ TEST(GenerateTOML, Comment)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(# This is a full-line comment)code";
|
||||
std::string ssTOML = R"toml(# This is a full-line comment)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -33,9 +34,9 @@ TEST(GenerateTOML, NodeComment)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(# This is a full-line comment
|
||||
std::string ssTOML = R"toml(# This is a full-line comment
|
||||
key = "value" # This is a comment at the end of a line
|
||||
another = "# This is not a comment")code";
|
||||
another = "# This is not a comment")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -49,10 +50,10 @@ TEST(GenerateTOML, NodeCommentWithSpaces)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(
|
||||
std::string ssTOML = R"toml(
|
||||
# This is a full-line comment
|
||||
key = "value" # This is a comment at the end of a line
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -66,13 +67,13 @@ TEST(GenerateTOML, UnattachedComment)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(# Comment not belonging to node
|
||||
std::string ssTOML = R"toml(# Comment not belonging to node
|
||||
|
||||
# This is a full-line comment
|
||||
key = "value" # This is a comment at the end of a line
|
||||
another = "# This is not a comment"
|
||||
|
||||
# Comment not belonging to node)code";
|
||||
# Comment not belonging to node)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -86,10 +87,10 @@ TEST(GenerateTOML, ArrayWhitespace)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(
|
||||
std::string ssTOML = R"toml(
|
||||
array = [ 1, 2, 3,
|
||||
4, 5, 6 ]
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -103,7 +104,7 @@ TEST(GenerateTOML, ArrayComment)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(
|
||||
std::string ssTOML = R"toml(
|
||||
# Pre-array
|
||||
array = [ 1, # Value #1
|
||||
2, # Value #2
|
||||
@@ -112,7 +113,7 @@ array = [ 1, # Value #1
|
||||
5, # Value #5
|
||||
6, # Value #6
|
||||
] # Post-array
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -126,7 +127,7 @@ TEST(GenerateTOML, ArrayCommentWithSpace)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(
|
||||
std::string ssTOML = R"toml(
|
||||
|
||||
# unattached comment
|
||||
|
||||
@@ -159,7 +160,7 @@ array = [ 1, # Value #1
|
||||
|
||||
# unattached comment
|
||||
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -174,9 +175,9 @@ TEST(GenerateTOML, InlineTableWhitespace)
|
||||
toml_parser::CParser parser;
|
||||
|
||||
// Note: line-breaks within an inline table are not allowed.
|
||||
std::string ssTOML = R"code(
|
||||
std::string ssTOML = R"toml(
|
||||
table = { a = 1, b = 2, d = 3, e = 4, f = 5, g = 6 }
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -191,10 +192,10 @@ TEST(GenerateTOML, InlineTableComment)
|
||||
toml_parser::CParser parser;
|
||||
|
||||
// Note: line-breaks within an inline table are not allowed.
|
||||
std::string ssTOML = R"code(
|
||||
std::string ssTOML = R"toml(
|
||||
# Pre-table
|
||||
table = { a = 1, b = 2, d = 3, e = 4, f = 5, g = 6 } # Post-table
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -208,10 +209,10 @@ TEST(GenerateTOML, Keys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(key = "value"
|
||||
std::string ssTOML = R"toml(key = "value"
|
||||
bare_key = "value"
|
||||
bare-key = "value"
|
||||
1234 = "value")code";
|
||||
1234 = "value")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -225,11 +226,11 @@ TEST(GenerateTOML, QuotedKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = u8R"code("127.0.0.1" = "value"
|
||||
std::string ssTOML = u8R"toml("127.0.0.1" = "value"
|
||||
"character encoding" = "value"
|
||||
"ʎǝʞ" = "value"
|
||||
'key2' = "value"
|
||||
'quoted "value"' = "value")code";
|
||||
'quoted "value"' = "value")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -241,8 +242,8 @@ TEST(GenerateTOML, QuotedKeys)
|
||||
|
||||
TEST(GenerateTOML, BlankKeys)
|
||||
{
|
||||
std::string ssTOML1 = R"code("" = "blank" # VALID but discouraged)code";
|
||||
std::string ssTOML2 = R"code('' = 'blank' # VALID but discouraged)code";
|
||||
std::string ssTOML1 = R"toml("" = "blank" # VALID but discouraged)toml";
|
||||
std::string ssTOML2 = R"toml('' = 'blank' # VALID but discouraged)toml";
|
||||
|
||||
toml_parser::CParser parser1, parser2;
|
||||
EXPECT_NO_THROW(parser1.Process(ssTOML1));
|
||||
@@ -259,10 +260,10 @@ TEST(GenerateTOML, DottedKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(name = "Orange"
|
||||
std::string ssTOML = R"toml(name = "Orange"
|
||||
physical.color = "orange"
|
||||
physical.shape = "round"
|
||||
site."google.com" = true)code";
|
||||
site."google.com" = true)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -276,9 +277,9 @@ TEST(GenerateTOML, WhitespaceKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(fruit.name = "banana" # this is best practice
|
||||
std::string ssTOML = R"toml(fruit.name = "banana" # this is best practice
|
||||
fruit. color = "yellow" # same as fruit.color
|
||||
fruit . flavor = "banana" # same as fruit.flavor)code";
|
||||
fruit . flavor = "banana" # same as fruit.flavor)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -292,14 +293,14 @@ TEST(GenerateTOML, OutOfOrderKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(apple.type = "fruit"
|
||||
std::string ssTOML = R"toml(apple.type = "fruit"
|
||||
orange.type = "fruit"
|
||||
|
||||
apple.skin = "thin"
|
||||
orange.skin = "thick"
|
||||
|
||||
apple.color = "red"
|
||||
orange.color = "orange")code";
|
||||
orange.color = "orange")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -313,7 +314,7 @@ TEST(GenerateTOML, FloatLookingAlikeKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(3.14159 = "pi")code";
|
||||
std::string ssTOML = R"toml(3.14159 = "pi")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -327,7 +328,7 @@ TEST(GenerateTOML, BasicStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF.")code";
|
||||
std::string ssTOML = R"toml(str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF.")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -341,9 +342,9 @@ TEST(GenerateTOML, MultiLineStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(str1 = """
|
||||
std::string ssTOML = R"toml(str1 = """
|
||||
Roses are red
|
||||
Violets are blue""")code";
|
||||
Violets are blue""")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -357,7 +358,7 @@ TEST(GenerateTOML, LongMultiLineStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(str1 = "The quick brown fox jumps over the lazy dog."
|
||||
std::string ssTOML = R"toml(str1 = "The quick brown fox jumps over the lazy dog."
|
||||
|
||||
str2 = """
|
||||
The quick brown \
|
||||
@@ -370,7 +371,7 @@ str3 = """\
|
||||
The quick brown \
|
||||
fox jumps over \
|
||||
the lazy dog.\
|
||||
""")code";
|
||||
""")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -384,13 +385,13 @@ TEST(GenerateTOML, QuotingStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(str4 = """Here are two quotation marks: "". Simple enough."""
|
||||
std::string ssTOML = R"toml(str4 = """Here are two quotation marks: "". Simple enough."""
|
||||
# str5 = """Here are three quotation marks: """.""" # INVALID
|
||||
str5 = """Here are three quotation marks: ""\"."""
|
||||
str6 = """Here are fifteen quotation marks: ""\"""\"""\"""\"""\"."""
|
||||
|
||||
# "This," she said, "is just a pointless statement."
|
||||
str7 = """"This," she said, "is just a pointless statement."""")code";
|
||||
str7 = """"This," she said, "is just a pointless statement."""")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -404,10 +405,10 @@ TEST(GenerateTOML, LiteralStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(winpath = 'C:\Users\nodejs\templates'
|
||||
std::string ssTOML = R"toml(winpath = 'C:\Users\nodejs\templates'
|
||||
winpath2 = '\\ServerX\admin$\system32\'
|
||||
quoted = 'Tom "Dubs" Preston-Werner'
|
||||
regex = '<\i\c*\s*>')code";
|
||||
regex = '<\i\c*\s*>')toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -421,13 +422,13 @@ TEST(GenerateTOML, MultiLineLiteralStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(regex2 = '''I [dw]on't need \d{2} apples'''
|
||||
std::string ssTOML = R"toml(regex2 = '''I [dw]on't need \d{2} apples'''
|
||||
lines = '''
|
||||
The first newline is
|
||||
trimmed in raw strings.
|
||||
All other whitespace
|
||||
is preserved.
|
||||
''')code";
|
||||
''')toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -441,13 +442,13 @@ TEST(GenerateTOML, QuotedLiteralStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(quot15 = '''Here are fifteen quotation marks: """""""""""""""'''
|
||||
std::string ssTOML = R"toml(quot15 = '''Here are fifteen quotation marks: """""""""""""""'''
|
||||
|
||||
# apos15 = '''Here are fifteen apostrophes: '''''''''''''''''' # INVALID
|
||||
apos15 = "Here are fifteen apostrophes: '''''''''''''''"
|
||||
|
||||
# 'That,' she said, 'is still pointless.'
|
||||
str = ''''That,' she said, 'is still pointless.'''')code";
|
||||
str = ''''That,' she said, 'is still pointless.'''')toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -461,10 +462,10 @@ TEST(GenerateTOML, Integers)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(int1 = +99
|
||||
std::string ssTOML = R"toml(int1 = +99
|
||||
int2 = 42
|
||||
int3 = 0
|
||||
int4 = -17)code";
|
||||
int4 = -17)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -478,10 +479,10 @@ TEST(GenerateTOML, ReadibleIntegers)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(int5 = 1_000
|
||||
std::string ssTOML = R"toml(int5 = 1_000
|
||||
int6 = 5_349_221
|
||||
int7 = 53_49_221 # Indian number system grouping
|
||||
int8 = 1_2_3_4_5 # VALID but discouraged)code";
|
||||
int8 = 1_2_3_4_5 # VALID but discouraged)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -495,7 +496,7 @@ TEST(GenerateTOML, OtherBaseIntegers)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(# hexadecimal with prefix `0x`
|
||||
std::string ssTOML = R"toml(# hexadecimal with prefix `0x`
|
||||
hex1 = 0xDEADBEEF
|
||||
hex2 = 0xdeadbeef
|
||||
hex3 = 0xdead_beef
|
||||
@@ -505,7 +506,7 @@ oct1 = 0o01234567
|
||||
oct2 = 0o755 # useful for Unix file permissions
|
||||
|
||||
# binary with prefix `0b`
|
||||
bin1 = 0b11010110)code";
|
||||
bin1 = 0b11010110)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -519,7 +520,7 @@ TEST(GenerateTOML, FloatingPoints)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(# fractional
|
||||
std::string ssTOML = R"toml(# fractional
|
||||
flt1 = +1.0
|
||||
flt2 = 3.1415
|
||||
flt3 = -0.01
|
||||
@@ -530,7 +531,7 @@ flt5 = 1e06
|
||||
flt6 = -2E-2
|
||||
|
||||
# both
|
||||
flt7 = 6.626e-34)code";
|
||||
flt7 = 6.626e-34)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -544,7 +545,7 @@ TEST(GenerateTOML, ReadibleFloatingPoints)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(flt8 = 224_617.445_991_228)code";
|
||||
std::string ssTOML = R"toml(flt8 = 224_617.445_991_228)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -558,7 +559,7 @@ TEST(GenerateTOML, SpecialFloatingPoints)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(# infinity
|
||||
std::string ssTOML = R"toml(# infinity
|
||||
sf1 = inf # positive infinity
|
||||
sf2 = +inf # positive infinity
|
||||
sf3 = -inf # negative infinity
|
||||
@@ -566,7 +567,7 @@ sf3 = -inf # negative infinity
|
||||
# not a number
|
||||
sf4 = nan # actual sNaN/qNaN encoding is implementation-specific
|
||||
sf5 = +nan # same as `nan`
|
||||
sf6 = -nan # valid, actual encoding is implementation-specific)code";
|
||||
sf6 = -nan # valid, actual encoding is implementation-specific)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -580,8 +581,8 @@ TEST(GenerateTOML, Booleans)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(bool1 = true
|
||||
bool2 = false)code";
|
||||
std::string ssTOML = R"toml(bool1 = true
|
||||
bool2 = false)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -595,9 +596,9 @@ TEST(GenerateTOML, DISABLED_OffsetDateTimes)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(odt1 = 1979-05-27T07:32:00Z
|
||||
std::string ssTOML = R"toml(odt1 = 1979-05-27T07:32:00Z
|
||||
odt2 = 1979-05-27T00:32:00-07:00
|
||||
odt3 = 1979-05-27T00:32:00.999999-07:00)code";
|
||||
odt3 = 1979-05-27T00:32:00.999999-07:00)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -611,7 +612,7 @@ TEST(GenerateTOML, DISABLED_ReadibleOffsetDateTimes)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(odt4 = 1979-05-27 07:32:00Z)code";
|
||||
std::string ssTOML = R"toml(odt4 = 1979-05-27 07:32:00Z)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -625,8 +626,8 @@ TEST(GenerateTOML, DISABLED_LocalDateTimes)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(ldt1 = 1979-05-27T07:32:00
|
||||
ldt2 = 1979-05-27T00:32:00.999999)code";
|
||||
std::string ssTOML = R"toml(ldt1 = 1979-05-27T07:32:00
|
||||
ldt2 = 1979-05-27T00:32:00.999999)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -640,7 +641,7 @@ TEST(GenerateTOML, DISABLED_LocalDates)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(ld1 = 1979-05-27)code";
|
||||
std::string ssTOML = R"toml(ld1 = 1979-05-27)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -654,8 +655,8 @@ TEST(GenerateTOML, DISABLED_LocalTimes)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(lt1 = 07:32:00
|
||||
lt2 = 00:32:00.999999)code";
|
||||
std::string ssTOML = R"toml(lt1 = 07:32:00
|
||||
lt2 = 00:32:00.999999)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -669,7 +670,7 @@ TEST(GenerateTOML, Arrays)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(integers = [ 1, 2, 3 ]
|
||||
std::string ssTOML = R"toml(integers = [ 1, 2, 3 ]
|
||||
colors = [ "red", "yellow", "green" ]
|
||||
nested_arrays_of_ints = [ [ 1, 2 ], [3, 4, 5] ]
|
||||
nested_mixed_array = [ [ 1, 2 ], ["a", "b", "c"] ]
|
||||
@@ -681,7 +682,7 @@ contributors =
|
||||
[
|
||||
"Foo Bar <foo@example.com>",
|
||||
{ name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }
|
||||
])code";
|
||||
])toml";
|
||||
|
||||
parser.Process(ssTOML);
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
@@ -696,14 +697,14 @@ TEST(GenerateTOML, MultiLineArrays)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(integers2 = [
|
||||
std::string ssTOML = R"toml(integers2 = [
|
||||
1, 2, 3
|
||||
]
|
||||
|
||||
integers3 = [
|
||||
1,
|
||||
2, # this is ok
|
||||
])code";
|
||||
])toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -717,7 +718,7 @@ TEST(GenerateTOML, Tables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code([table]
|
||||
std::string ssTOML = R"toml([table]
|
||||
|
||||
[table-1]
|
||||
key1 = "some string"
|
||||
@@ -725,7 +726,7 @@ key2 = 123
|
||||
|
||||
[table-2]
|
||||
key1 = "another string"
|
||||
key2 = 456)code";
|
||||
key2 = 456)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -739,8 +740,8 @@ TEST(GenerateTOML, QuotedKeyTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code([dog."tater.man"]
|
||||
type.name = "pug")code";
|
||||
std::string ssTOML = R"toml([dog."tater.man"]
|
||||
type.name = "pug")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -754,14 +755,14 @@ TEST(GenerateTOML, WhitespaceKeyTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = u8R"code([a.b.c] # this is best practice
|
||||
std::string ssTOML = u8R"toml([a.b.c] # this is best practice
|
||||
x = 1
|
||||
[ d.e.f ] # same as [d.e.f]
|
||||
y = 1
|
||||
[ g . h . i ] # same as [g.h.i]
|
||||
z = 1
|
||||
[ j . "ʞ" . 'l' ] # same as [j."ʞ".'l']
|
||||
a = 1)code";
|
||||
a = 1)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -775,13 +776,13 @@ TEST(GenerateTOML, MixedOrderTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(# VALID BUT DISCOURAGED
|
||||
std::string ssTOML = R"toml(# VALID BUT DISCOURAGED
|
||||
[fruit.apple]
|
||||
a = 1
|
||||
[animal]
|
||||
b = 2
|
||||
[fruit.orange]
|
||||
aa = 11)code";
|
||||
aa = 11)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -795,14 +796,14 @@ TEST(GenerateTOML, MixedValueAndTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(# Top-level table begins.
|
||||
std::string ssTOML = R"toml(# Top-level table begins.
|
||||
name = "Fido"
|
||||
breed = "pug"
|
||||
|
||||
# Top-level table ends.
|
||||
[owner]
|
||||
name = "Regina Dogman"
|
||||
member_since = 1999)code";
|
||||
member_since = 1999)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -816,10 +817,10 @@ TEST(GenerateTOML, AutomaticTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(fruit.apple.color = "red"
|
||||
fruit.apple.taste.sweet = true)code";
|
||||
std::string ssTOMLOutput2 = R"code(apple.color = "red"
|
||||
apple.taste.sweet = true)code";
|
||||
std::string ssTOML = R"toml(fruit.apple.color = "red"
|
||||
fruit.apple.taste.sweet = true)toml";
|
||||
std::string ssTOMLOutput2 = R"toml(apple.color = "red"
|
||||
apple.taste.sweet = true)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -835,7 +836,7 @@ TEST(GenerateTOML, MixedAutomaticTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code([fruit]
|
||||
std::string ssTOML = R"toml([fruit]
|
||||
apple.color = "red"
|
||||
apple.taste.sweet = true
|
||||
|
||||
@@ -843,7 +844,7 @@ apple.taste.sweet = true
|
||||
# [fruit.apple.taste] # INVALID
|
||||
|
||||
[fruit.apple.texture] # you can add sub-tables
|
||||
smooth = true)code";
|
||||
smooth = true)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -857,9 +858,9 @@ TEST(GenerateTOML, InlineTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(name = { first = "Tom", last = "Preston-Werner" }
|
||||
std::string ssTOML = R"toml(name = { first = "Tom", last = "Preston-Werner" }
|
||||
point = { x = 1, y = 2 }
|
||||
animal = { type.name = "pug" })code";
|
||||
animal = { type.name = "pug" })toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -873,9 +874,9 @@ TEST(GenerateTOML, EmbeddedInlineTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(test=[{ first = "Tom", last = "Preston-Werner" },
|
||||
std::string ssTOML = R"toml(test=[{ first = "Tom", last = "Preston-Werner" },
|
||||
{ x = 1, y = 2 },
|
||||
{ type.name = "pug" }])code";
|
||||
{ type.name = "pug" }])toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -889,7 +890,7 @@ TEST(GenerateTOML, TableArrays)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code([[products]]
|
||||
std::string ssTOML = R"toml([[products]]
|
||||
name = "Hammer"
|
||||
sku = 738594937
|
||||
|
||||
@@ -899,7 +900,7 @@ sku = 738594937
|
||||
name = "Nail"
|
||||
sku = 284758393
|
||||
|
||||
color = "gray")code";
|
||||
color = "gray")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -913,7 +914,7 @@ TEST(GenerateTOML, MixedTableAndTableArrays)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code([[fruits]]
|
||||
std::string ssTOML = R"toml([[fruits]]
|
||||
name = "apple"
|
||||
|
||||
[fruits.physical] # subtable
|
||||
@@ -931,29 +932,29 @@ name = "granny smith"
|
||||
name = "banana"
|
||||
|
||||
[[fruits.varieties]]
|
||||
name = "plantain")code";
|
||||
std::string ssTOMLFruits1Physical = R"code([physical] # subtable
|
||||
name = "plantain")toml";
|
||||
std::string ssTOMLFruits1Physical = R"toml([physical] # subtable
|
||||
color = "red"
|
||||
shape = "round"
|
||||
|
||||
)code";
|
||||
std::string ssTOMLFruits1Varieties = R"code([[varieties]] # nested array of tables
|
||||
)toml";
|
||||
std::string ssTOMLFruits1Varieties = R"toml([[varieties]] # nested array of tables
|
||||
name = "red delicious"
|
||||
|
||||
[[varieties]]
|
||||
name = "granny smith"
|
||||
|
||||
)code";
|
||||
std::string ssTOMLFruits1Variety1 = R"code([variety] # nested array of tables
|
||||
)toml";
|
||||
std::string ssTOMLFruits1Variety1 = R"toml([variety] # nested array of tables
|
||||
name = "red delicious"
|
||||
|
||||
)code";
|
||||
std::string ssTOMLFruits1Variety2 = R"code([variety]
|
||||
)toml";
|
||||
std::string ssTOMLFruits1Variety2 = R"toml([variety]
|
||||
name = "granny smith"
|
||||
|
||||
)code";
|
||||
std::string ssTOMLFruits2Variety1 = R"code([variety]
|
||||
name = "plantain")code";
|
||||
)toml";
|
||||
std::string ssTOMLFruits2Variety1 = R"toml([variety]
|
||||
name = "plantain")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -998,9 +999,9 @@ TEST(GenerateTOML, InlineTableArrays)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(points = [ { x = 1, y = 2, z = 3 },
|
||||
std::string ssTOML = R"toml(points = [ { x = 1, y = 2, z = 3 },
|
||||
{ x = 7, y = 8, z = 9 },
|
||||
{ x = 2, y = 4, z = 8 } ])code";
|
||||
{ x = 2, y = 4, z = 8 } ])toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
|
||||
@@ -19,13 +20,13 @@ TEST(GenerateTOML, TransferNodeComment)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# This is a full-line comment
|
||||
std::string ssTOMLInput = R"toml(# This is a full-line comment
|
||||
key = "value" # This is a comment at the end of a line
|
||||
another = "# This is not a comment")code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
another = "# This is not a comment")toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
# This is a full-line comment
|
||||
key = "value" # This is a comment at the end of a line
|
||||
another = "# This is not a comment")code";
|
||||
another = "# This is not a comment")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -39,15 +40,15 @@ TEST(GenerateTOML, TransferNodeCommentWithSpaces)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(
|
||||
std::string ssTOMLInput = R"toml(
|
||||
# This is a full-line comment
|
||||
key = "value" # This is a comment at the end of a line
|
||||
)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
|
||||
# This is a full-line comment
|
||||
key = "value" # This is a comment at the end of a line
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -61,21 +62,21 @@ TEST(GenerateTOML, TransferUnattachedComment)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# Comment not belonging to node
|
||||
std::string ssTOMLInput = R"toml(# Comment not belonging to node
|
||||
|
||||
# This is a full-line comment
|
||||
key = "value" # This is a comment at the end of a line
|
||||
another = "# This is not a comment"
|
||||
|
||||
# Comment not belonging to node)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
# Comment not belonging to node)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
# Comment not belonging to node
|
||||
|
||||
# This is a full-line comment
|
||||
key = "value" # This is a comment at the end of a line
|
||||
another = "# This is not a comment"
|
||||
|
||||
# Comment not belonging to node)code";
|
||||
# Comment not belonging to node)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -89,15 +90,15 @@ TEST(GenerateTOML, TransferArrayWhitespace)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(
|
||||
std::string ssTOMLInput = R"toml(
|
||||
array = [ 1, 2, 3,
|
||||
4, 5, 6 ]
|
||||
)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
|
||||
array = [ 1, 2, 3,
|
||||
4, 5, 6 ]
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -111,7 +112,7 @@ TEST(GenerateTOML, TransferArrayComment)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(
|
||||
std::string ssTOMLInput = R"toml(
|
||||
# Pre-array
|
||||
array = [ 1, # Value #1
|
||||
2, # Value #2
|
||||
@@ -120,8 +121,8 @@ array = [ 1, # Value #1
|
||||
5, # Value #5
|
||||
6, # Value #6
|
||||
] # Post-array
|
||||
)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
|
||||
# Pre-array
|
||||
array = [ 1, # Value #1
|
||||
@@ -131,7 +132,7 @@ array = [ 1, # Value #1
|
||||
5, # Value #5
|
||||
6, # Value #6
|
||||
] # Post-array
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -145,7 +146,7 @@ TEST(GenerateTOML, TransferArrayCommentWithSpace)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(
|
||||
std::string ssTOMLInput = R"toml(
|
||||
|
||||
# unattached comment
|
||||
|
||||
@@ -178,8 +179,8 @@ array = [ 1, # Value #1
|
||||
|
||||
# unattached comment
|
||||
|
||||
)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
|
||||
|
||||
# unattached comment
|
||||
@@ -213,7 +214,7 @@ array = [ 1, # Value #1
|
||||
|
||||
# unattached comment
|
||||
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -228,13 +229,13 @@ TEST(GenerateTOML, TransferInlineTableWhitespace)
|
||||
toml_parser::CParser parser;
|
||||
|
||||
// NOTE: Line-breaks within inline tables are not allowed.
|
||||
std::string ssTOMLInput = R"code(
|
||||
std::string ssTOMLInput = R"toml(
|
||||
table = { a = 1, b = 2, d = 3, e = 4, f = 5, g = 6 }
|
||||
)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
|
||||
table = { a = 1, b = 2, d = 3, e = 4, f = 5, g = 6 }
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -249,15 +250,15 @@ TEST(GenerateTOML, TransferInlineTableComment)
|
||||
toml_parser::CParser parser;
|
||||
|
||||
// NOTE: Line-breaks within inline tables are not allowed.
|
||||
std::string ssTOMLInput = R"code(
|
||||
std::string ssTOMLInput = R"toml(
|
||||
# Pre-table
|
||||
table = { a = 1, b = 2, d = 3, e = 4, f = 5, g = 6 } # Post-table
|
||||
)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
|
||||
# Pre-table
|
||||
table = { a = 1, b = 2, d = 3, e = 4, f = 5, g = 6 } # Post-table
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -271,15 +272,15 @@ TEST(GenerateTOML, TransferKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(key = "value"
|
||||
std::string ssTOMLInput = R"toml(key = "value"
|
||||
bare_key = "value"
|
||||
bare-key = "value"
|
||||
1234 = "value")code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
1234 = "value")toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
key = "value"
|
||||
bare_key = "value"
|
||||
bare-key = "value"
|
||||
1234 = "value")code";
|
||||
1234 = "value")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -293,17 +294,17 @@ TEST(GenerateTOML, TransferQuotedKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = u8R"code("127.0.0.1" = "value"
|
||||
std::string ssTOMLInput = u8R"toml("127.0.0.1" = "value"
|
||||
"character encoding" = "value"
|
||||
"ʎǝʞ" = "value"
|
||||
'key2' = "value"
|
||||
'quoted "value"' = "value")code";
|
||||
std::string ssTOMLOutput = u8R"code([tree.branch]
|
||||
'quoted "value"' = "value")toml";
|
||||
std::string ssTOMLOutput = u8R"toml([tree.branch]
|
||||
"127.0.0.1" = "value"
|
||||
"character encoding" = "value"
|
||||
"ʎǝʞ" = "value"
|
||||
'key2' = "value"
|
||||
'quoted "value"' = "value")code";
|
||||
'quoted "value"' = "value")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -315,12 +316,12 @@ TEST(GenerateTOML, TransferQuotedKeys)
|
||||
|
||||
TEST(GenerateTOML, TransferBlankKeys)
|
||||
{
|
||||
std::string ssTOMLInput1 = R"code("" = "blank" # VALID but discouraged)code";
|
||||
std::string ssTOMLInput2 = R"code('' = 'blank' # VALID but discouraged)code";
|
||||
std::string ssTOMLOutput1 = R"code([tree.branch]
|
||||
"" = "blank" # VALID but discouraged)code";
|
||||
std::string ssTOMLOutput2 = R"code([tree.branch]
|
||||
'' = 'blank' # VALID but discouraged)code";
|
||||
std::string ssTOMLInput1 = R"toml("" = "blank" # VALID but discouraged)toml";
|
||||
std::string ssTOMLInput2 = R"toml('' = 'blank' # VALID but discouraged)toml";
|
||||
std::string ssTOMLOutput1 = R"toml([tree.branch]
|
||||
"" = "blank" # VALID but discouraged)toml";
|
||||
std::string ssTOMLOutput2 = R"toml([tree.branch]
|
||||
'' = 'blank' # VALID but discouraged)toml";
|
||||
|
||||
toml_parser::CParser parser1, parser2;
|
||||
EXPECT_NO_THROW(parser1.Process(ssTOMLInput1));
|
||||
@@ -338,15 +339,15 @@ TEST(GenerateTOML, TransferDottedKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(name = "Orange"
|
||||
std::string ssTOMLInput = R"toml(name = "Orange"
|
||||
physical.color = "orange"
|
||||
physical.shape = "round"
|
||||
site."google.com" = true)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
site."google.com" = true)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
name = "Orange"
|
||||
physical.color = "orange"
|
||||
physical.shape = "round"
|
||||
site."google.com" = true)code";
|
||||
site."google.com" = true)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -360,13 +361,13 @@ TEST(GenerateTOML, TransferWhitespaceKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(fruit.name = "banana" # this is best practice
|
||||
std::string ssTOMLInput = R"toml(fruit.name = "banana" # this is best practice
|
||||
fruit. color = "yellow" # same as fruit.color
|
||||
fruit . flavor = "banana" # same as fruit.flavor)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
fruit . flavor = "banana" # same as fruit.flavor)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
fruit.name = "banana" # this is best practice
|
||||
fruit. color = "yellow" # same as fruit.color
|
||||
fruit . flavor = "banana" # same as fruit.flavor)code";
|
||||
fruit . flavor = "banana" # same as fruit.flavor)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -380,15 +381,15 @@ TEST(GenerateTOML, TransferOutOfOrderKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(apple.type = "fruit"
|
||||
std::string ssTOMLInput = R"toml(apple.type = "fruit"
|
||||
orange.type = "fruit"
|
||||
|
||||
apple.skin = "thin"
|
||||
orange.skin = "thick"
|
||||
|
||||
apple.color = "red"
|
||||
orange.color = "orange")code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
orange.color = "orange")toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
apple.type = "fruit"
|
||||
orange.type = "fruit"
|
||||
|
||||
@@ -396,7 +397,7 @@ apple.skin = "thin"
|
||||
orange.skin = "thick"
|
||||
|
||||
apple.color = "red"
|
||||
orange.color = "orange")code";
|
||||
orange.color = "orange")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -410,9 +411,9 @@ TEST(GenerateTOML, TransferFloatLookingAlikeKeys)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(3.14159 = "pi")code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
3.14159 = "pi")code";
|
||||
std::string ssTOMLInput = R"toml(3.14159 = "pi")toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
3.14159 = "pi")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -426,9 +427,9 @@ TEST(GenerateTOML, TransferBasicStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF.")code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF.")code";
|
||||
std::string ssTOMLInput = R"toml(str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF.")toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF.")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -442,13 +443,13 @@ TEST(GenerateTOML, TransferMultiLineStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(str1 = """
|
||||
std::string ssTOMLInput = R"toml(str1 = """
|
||||
Roses are red
|
||||
Violets are blue""")code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
Violets are blue""")toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
str1 = """
|
||||
Roses are red
|
||||
Violets are blue""")code";
|
||||
Violets are blue""")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -462,7 +463,7 @@ TEST(GenerateTOML, TransferLongMultiLineStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(str1 = "The quick brown fox jumps over the lazy dog."
|
||||
std::string ssTOMLInput = R"toml(str1 = "The quick brown fox jumps over the lazy dog."
|
||||
|
||||
str2 = """
|
||||
The quick brown \
|
||||
@@ -475,8 +476,8 @@ str3 = """\
|
||||
The quick brown \
|
||||
fox jumps over \
|
||||
the lazy dog.\
|
||||
""")code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
""")toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
str1 = "The quick brown fox jumps over the lazy dog."
|
||||
|
||||
str2 = """
|
||||
@@ -490,7 +491,7 @@ str3 = """\
|
||||
The quick brown \
|
||||
fox jumps over \
|
||||
the lazy dog.\
|
||||
""")code";
|
||||
""")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -504,21 +505,21 @@ TEST(GenerateTOML, TransferQuotingStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(str4 = """Here are two quotation marks: "". Simple enough."""
|
||||
std::string ssTOMLInput = R"toml(str4 = """Here are two quotation marks: "". Simple enough."""
|
||||
# str5 = """Here are three quotation marks: """.""" # INVALID
|
||||
str5 = """Here are three quotation marks: ""\"."""
|
||||
str6 = """Here are fifteen quotation marks: ""\"""\"""\"""\"""\"."""
|
||||
|
||||
# "This," she said, "is just a pointless statement."
|
||||
str7 = """"This," she said, "is just a pointless statement."""")code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
str7 = """"This," she said, "is just a pointless statement."""")toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
str4 = """Here are two quotation marks: "". Simple enough."""
|
||||
# str5 = """Here are three quotation marks: """.""" # INVALID
|
||||
str5 = """Here are three quotation marks: ""\"."""
|
||||
str6 = """Here are fifteen quotation marks: ""\"""\"""\"""\"""\"."""
|
||||
|
||||
# "This," she said, "is just a pointless statement."
|
||||
str7 = """"This," she said, "is just a pointless statement."""")code";
|
||||
str7 = """"This," she said, "is just a pointless statement."""")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -532,15 +533,15 @@ TEST(GenerateTOML, TransferLiteralStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(winpath = 'C:\Users\nodejs\templates'
|
||||
std::string ssTOMLInput = R"toml(winpath = 'C:\Users\nodejs\templates'
|
||||
winpath2 = '\\ServerX\admin$\system32\'
|
||||
quoted = 'Tom "Dubs" Preston-Werner'
|
||||
regex = '<\i\c*\s*>')code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
regex = '<\i\c*\s*>')toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
winpath = 'C:\Users\nodejs\templates'
|
||||
winpath2 = '\\ServerX\admin$\system32\'
|
||||
quoted = 'Tom "Dubs" Preston-Werner'
|
||||
regex = '<\i\c*\s*>')code";
|
||||
regex = '<\i\c*\s*>')toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -554,21 +555,21 @@ TEST(GenerateTOML, TransferMultiLineLiteralStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(regex2 = '''I [dw]on't need \d{2} apples'''
|
||||
std::string ssTOMLInput = R"toml(regex2 = '''I [dw]on't need \d{2} apples'''
|
||||
lines = '''
|
||||
The first newline is
|
||||
trimmed in raw strings.
|
||||
All other whitespace
|
||||
is preserved.
|
||||
''')code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
''')toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
regex2 = '''I [dw]on't need \d{2} apples'''
|
||||
lines = '''
|
||||
The first newline is
|
||||
trimmed in raw strings.
|
||||
All other whitespace
|
||||
is preserved.
|
||||
''')code";
|
||||
''')toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -582,21 +583,21 @@ TEST(GenerateTOML, TransferQuotedLiteralStrings)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(quot15 = '''Here are fifteen quotation marks: """""""""""""""'''
|
||||
std::string ssTOMLInput = R"toml(quot15 = '''Here are fifteen quotation marks: """""""""""""""'''
|
||||
|
||||
# apos15 = '''Here are fifteen apostrophes: '''''''''''''''''' # INVALID
|
||||
apos15 = "Here are fifteen apostrophes: '''''''''''''''"
|
||||
|
||||
# 'That,' she said, 'is still pointless.'
|
||||
str = ''''That,' she said, 'is still pointless.'''')code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
str = ''''That,' she said, 'is still pointless.'''')toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
quot15 = '''Here are fifteen quotation marks: """""""""""""""'''
|
||||
|
||||
# apos15 = '''Here are fifteen apostrophes: '''''''''''''''''' # INVALID
|
||||
apos15 = "Here are fifteen apostrophes: '''''''''''''''"
|
||||
|
||||
# 'That,' she said, 'is still pointless.'
|
||||
str = ''''That,' she said, 'is still pointless.'''')code";
|
||||
str = ''''That,' she said, 'is still pointless.'''')toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -610,15 +611,15 @@ TEST(GenerateTOML, TransferIntegers)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(int1 = +99
|
||||
std::string ssTOMLInput = R"toml(int1 = +99
|
||||
int2 = 42
|
||||
int3 = 0
|
||||
int4 = -17)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
int4 = -17)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
int1 = +99
|
||||
int2 = 42
|
||||
int3 = 0
|
||||
int4 = -17)code";
|
||||
int4 = -17)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -632,15 +633,15 @@ TEST(GenerateTOML, TransferReadibleIntegers)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(int5 = 1_000
|
||||
std::string ssTOMLInput = R"toml(int5 = 1_000
|
||||
int6 = 5_349_221
|
||||
int7 = 53_49_221 # Indian number system grouping
|
||||
int8 = 1_2_3_4_5 # VALID but discouraged)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
int8 = 1_2_3_4_5 # VALID but discouraged)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
int5 = 1_000
|
||||
int6 = 5_349_221
|
||||
int7 = 53_49_221 # Indian number system grouping
|
||||
int8 = 1_2_3_4_5 # VALID but discouraged)code";
|
||||
int8 = 1_2_3_4_5 # VALID but discouraged)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -654,7 +655,7 @@ TEST(GenerateTOML, TransferOtherBaseIntegers)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# hexadecimal with prefix `0x`
|
||||
std::string ssTOMLInput = R"toml(# hexadecimal with prefix `0x`
|
||||
hex1 = 0xDEADBEEF
|
||||
hex2 = 0xdeadbeef
|
||||
hex3 = 0xdead_beef
|
||||
@@ -664,8 +665,8 @@ oct1 = 0o01234567
|
||||
oct2 = 0o755 # useful for Unix file permissions
|
||||
|
||||
# binary with prefix `0b`
|
||||
bin1 = 0b11010110)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
bin1 = 0b11010110)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
# hexadecimal with prefix `0x`
|
||||
hex1 = 0xDEADBEEF
|
||||
hex2 = 0xdeadbeef
|
||||
@@ -676,7 +677,7 @@ oct1 = 0o01234567
|
||||
oct2 = 0o755 # useful for Unix file permissions
|
||||
|
||||
# binary with prefix `0b`
|
||||
bin1 = 0b11010110)code";
|
||||
bin1 = 0b11010110)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -690,7 +691,7 @@ TEST(GenerateTOML, TransferFloatingPoints)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# fractional
|
||||
std::string ssTOMLInput = R"toml(# fractional
|
||||
flt1 = +1.0
|
||||
flt2 = 3.1415
|
||||
flt3 = -0.01
|
||||
@@ -701,8 +702,8 @@ flt5 = 1e06
|
||||
flt6 = -2E-2
|
||||
|
||||
# both
|
||||
flt7 = 6.626e-34)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
flt7 = 6.626e-34)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
# fractional
|
||||
flt1 = +1.0
|
||||
flt2 = 3.1415
|
||||
@@ -714,7 +715,7 @@ flt5 = 1e06
|
||||
flt6 = -2E-2
|
||||
|
||||
# both
|
||||
flt7 = 6.626e-34)code";
|
||||
flt7 = 6.626e-34)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -728,9 +729,9 @@ TEST(GenerateTOML, TransferReadibleFloatingPoints)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(flt8 = 224_617.445_991_228)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
flt8 = 224_617.445_991_228)code";
|
||||
std::string ssTOMLInput = R"toml(flt8 = 224_617.445_991_228)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
flt8 = 224_617.445_991_228)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -744,7 +745,7 @@ TEST(GenerateTOML, TransferSpecialFloatingPoints)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# infinity
|
||||
std::string ssTOMLInput = R"toml(# infinity
|
||||
sf1 = inf # positive infinity
|
||||
sf2 = +inf # positive infinity
|
||||
sf3 = -inf # negative infinity
|
||||
@@ -752,8 +753,8 @@ sf3 = -inf # negative infinity
|
||||
# not a number
|
||||
sf4 = nan # actual sNaN/qNaN encoding is implementation-specific
|
||||
sf5 = +nan # same as `nan`
|
||||
sf6 = -nan # valid, actual encoding is implementation-specific)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
sf6 = -nan # valid, actual encoding is implementation-specific)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
# infinity
|
||||
sf1 = inf # positive infinity
|
||||
sf2 = +inf # positive infinity
|
||||
@@ -762,7 +763,7 @@ sf3 = -inf # negative infinity
|
||||
# not a number
|
||||
sf4 = nan # actual sNaN/qNaN encoding is implementation-specific
|
||||
sf5 = +nan # same as `nan`
|
||||
sf6 = -nan # valid, actual encoding is implementation-specific)code";
|
||||
sf6 = -nan # valid, actual encoding is implementation-specific)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -776,11 +777,11 @@ TEST(GenerateTOML, TransferBooleans)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(bool1 = true
|
||||
bool2 = false)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
std::string ssTOMLInput = R"toml(bool1 = true
|
||||
bool2 = false)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
bool1 = true
|
||||
bool2 = false)code";
|
||||
bool2 = false)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -794,13 +795,13 @@ TEST(GenerateTOML, DISABLED_TransferOffsetDateTimes)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(odt1 = 1979-05-27T07:32:00Z
|
||||
std::string ssTOMLInput = R"toml(odt1 = 1979-05-27T07:32:00Z
|
||||
odt2 = 1979-05-27T00:32:00-07:00
|
||||
odt3 = 1979-05-27T00:32:00.999999-07:00)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
odt3 = 1979-05-27T00:32:00.999999-07:00)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
odt1 = 1979-05-27T07:32:00Z
|
||||
odt2 = 1979-05-27T00:32:00-07:00
|
||||
odt3 = 1979-05-27T00:32:00.999999-07:00)code";
|
||||
odt3 = 1979-05-27T00:32:00.999999-07:00)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -814,9 +815,9 @@ TEST(GenerateTOML, DISABLED_TransferReadibleOffsetDateTimes)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(odt4 = 1979-05-27 07:32:00Z)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
odt4 = 1979-05-27 07:32:00Z)code";
|
||||
std::string ssTOMLInput = R"toml(odt4 = 1979-05-27 07:32:00Z)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
odt4 = 1979-05-27 07:32:00Z)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -830,11 +831,11 @@ TEST(GenerateTOML, DISABLED_TransferLocalDateTimes)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(ldt1 = 1979-05-27T07:32:00
|
||||
ldt2 = 1979-05-27T00:32:00.999999)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
std::string ssTOMLInput = R"toml(ldt1 = 1979-05-27T07:32:00
|
||||
ldt2 = 1979-05-27T00:32:00.999999)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
ldt1 = 1979-05-27T07:32:00
|
||||
ldt2 = 1979-05-27T00:32:00.999999)code";
|
||||
ldt2 = 1979-05-27T00:32:00.999999)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -848,9 +849,9 @@ TEST(GenerateTOML, DISABLED_TransferLocalDates)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(ld1 = 1979-05-27)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
ld1 = 1979-05-27)code";
|
||||
std::string ssTOMLInput = R"toml(ld1 = 1979-05-27)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
ld1 = 1979-05-27)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -864,11 +865,11 @@ TEST(GenerateTOML, DISABLED_TransferLocalTimes)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(lt1 = 07:32:00
|
||||
lt2 = 00:32:00.999999)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
std::string ssTOMLInput = R"toml(lt1 = 07:32:00
|
||||
lt2 = 00:32:00.999999)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
lt1 = 07:32:00
|
||||
lt2 = 00:32:00.999999)code";
|
||||
lt2 = 00:32:00.999999)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -882,7 +883,7 @@ TEST(GenerateTOML, TransferArrays)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(integers = [ 1, 2, 3 ]
|
||||
std::string ssTOMLInput = R"toml(integers = [ 1, 2, 3 ]
|
||||
colors = [ "red", "yellow", "green" ]
|
||||
nested_arrays_of_ints = [ [ 1, 2 ], [3, 4, 5] ]
|
||||
nested_mixed_array = [ [ 1, 2 ], ["a", "b", "c"] ]
|
||||
@@ -893,8 +894,8 @@ numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]
|
||||
contributors = [
|
||||
"Foo Bar <foo@example.com>",
|
||||
{ name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }
|
||||
])code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
])toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
integers = [ 1, 2, 3 ]
|
||||
colors = [ "red", "yellow", "green" ]
|
||||
nested_arrays_of_ints = [ [ 1, 2 ], [3, 4, 5] ]
|
||||
@@ -906,7 +907,7 @@ numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]
|
||||
contributors = [
|
||||
"Foo Bar <foo@example.com>",
|
||||
{ name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }
|
||||
])code";
|
||||
])toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -920,15 +921,15 @@ TEST(GenerateTOML, TransferMultiLineArrays)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(integers2 = [
|
||||
std::string ssTOMLInput = R"toml(integers2 = [
|
||||
1, 2, 3
|
||||
]
|
||||
|
||||
integers3 = [
|
||||
1,
|
||||
2, # this is ok
|
||||
])code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
])toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
integers2 = [
|
||||
1, 2, 3
|
||||
]
|
||||
@@ -936,7 +937,7 @@ integers2 = [
|
||||
integers3 = [
|
||||
1,
|
||||
2, # this is ok
|
||||
])code";
|
||||
])toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -950,7 +951,7 @@ TEST(GenerateTOML, TransferTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code([table]
|
||||
std::string ssTOMLInput = R"toml([table]
|
||||
|
||||
[table-1]
|
||||
key1 = "some string"
|
||||
@@ -958,8 +959,8 @@ key2 = 123
|
||||
|
||||
[table-2]
|
||||
key1 = "another string"
|
||||
key2 = 456)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch.table]
|
||||
key2 = 456)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch.table]
|
||||
|
||||
[tree.branch.table-1]
|
||||
key1 = "some string"
|
||||
@@ -967,7 +968,7 @@ key2 = 123
|
||||
|
||||
[tree.branch.table-2]
|
||||
key1 = "another string"
|
||||
key2 = 456)code";
|
||||
key2 = 456)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -981,10 +982,10 @@ TEST(GenerateTOML, TransferQuotedKeyTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code([dog."tater.man"]
|
||||
type.name = "pug")code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch.dog."tater.man"]
|
||||
type.name = "pug")code";
|
||||
std::string ssTOMLInput = R"toml([dog."tater.man"]
|
||||
type.name = "pug")toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch.dog."tater.man"]
|
||||
type.name = "pug")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -998,22 +999,22 @@ TEST(GenerateTOML, TransferWhitespaceKeyTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = u8R"code([a.b.c] # this is best practice
|
||||
std::string ssTOMLInput = u8R"toml([a.b.c] # this is best practice
|
||||
x = 1
|
||||
[ d.e.f ] # same as [d.e.f]
|
||||
y = 1
|
||||
[ g . h . i ] # same as [g.h.i]
|
||||
z = 1
|
||||
[ j . "ʞ" . 'l' ] # same as [j."ʞ".'l']
|
||||
a = 1)code";
|
||||
std::string ssTOMLOutput = u8R"code([tree.branch.a.b.c] # this is best practice
|
||||
a = 1)toml";
|
||||
std::string ssTOMLOutput = u8R"toml([tree.branch.a.b.c] # this is best practice
|
||||
x = 1
|
||||
[tree.branch. d.e.f ] # same as [d.e.f]
|
||||
y = 1
|
||||
[tree.branch. g . h . i ] # same as [g.h.i]
|
||||
z = 1
|
||||
[tree.branch. j . "ʞ" . 'l' ] # same as [j."ʞ".'l']
|
||||
a = 1)code";
|
||||
a = 1)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -1027,20 +1028,20 @@ TEST(GenerateTOML, TransferMixedOrderTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# VALID BUT DISCOURAGED
|
||||
std::string ssTOMLInput = R"toml(# VALID BUT DISCOURAGED
|
||||
[fruit.apple]
|
||||
a = 1
|
||||
[animal]
|
||||
b = 2
|
||||
[fruit.orange]
|
||||
aa = 11)code";
|
||||
std::string ssTOMLOutput = R"code(# VALID BUT DISCOURAGED
|
||||
aa = 11)toml";
|
||||
std::string ssTOMLOutput = R"toml(# VALID BUT DISCOURAGED
|
||||
[tree.branch.fruit.apple]
|
||||
a = 1
|
||||
[tree.branch.animal]
|
||||
b = 2
|
||||
[tree.branch.fruit.orange]
|
||||
aa = 11)code";
|
||||
aa = 11)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -1054,15 +1055,15 @@ TEST(GenerateTOML, TransferMixedValueAndTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# Top-level table begins.
|
||||
std::string ssTOMLInput = R"toml(# Top-level table begins.
|
||||
name = "Fido"
|
||||
breed = "pug"
|
||||
|
||||
# Top-level table ends.
|
||||
[owner]
|
||||
name = "Regina Dogman"
|
||||
member_since = 1999)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
member_since = 1999)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
# Top-level table begins.
|
||||
name = "Fido"
|
||||
breed = "pug"
|
||||
@@ -1070,7 +1071,7 @@ breed = "pug"
|
||||
# Top-level table ends.
|
||||
[tree.branch.owner]
|
||||
name = "Regina Dogman"
|
||||
member_since = 1999)code";
|
||||
member_since = 1999)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -1084,14 +1085,14 @@ TEST(GenerateTOML, TransferAutomaticTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(fruit.apple.color = "red"
|
||||
fruit.apple.taste.sweet = true)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
std::string ssTOMLInput = R"toml(fruit.apple.color = "red"
|
||||
fruit.apple.taste.sweet = true)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
fruit.apple.color = "red"
|
||||
fruit.apple.taste.sweet = true)code";
|
||||
std::string ssTOMLOutput2 = R"code([tree.branch]
|
||||
fruit.apple.taste.sweet = true)toml";
|
||||
std::string ssTOMLOutput2 = R"toml([tree.branch]
|
||||
apple.color = "red"
|
||||
apple.taste.sweet = true)code";
|
||||
apple.taste.sweet = true)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -1107,7 +1108,7 @@ TEST(GenerateTOML, TransferMixedAutomaticTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code([fruit]
|
||||
std::string ssTOMLInput = R"toml([fruit]
|
||||
apple.color = "red"
|
||||
apple.taste.sweet = true
|
||||
|
||||
@@ -1115,8 +1116,8 @@ apple.taste.sweet = true
|
||||
# [fruit.apple.taste] # INVALID
|
||||
|
||||
[fruit.apple.texture] # you can add sub-tables
|
||||
smooth = true)code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch.fruit]
|
||||
smooth = true)toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch.fruit]
|
||||
apple.color = "red"
|
||||
apple.taste.sweet = true
|
||||
|
||||
@@ -1124,7 +1125,7 @@ apple.taste.sweet = true
|
||||
# [fruit.apple.taste] # INVALID
|
||||
|
||||
[tree.branch.fruit.apple.texture] # you can add sub-tables
|
||||
smooth = true)code";
|
||||
smooth = true)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -1138,13 +1139,13 @@ TEST(GenerateTOML, TransferInlineTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(name = { first = "Tom", last = "Preston-Werner" }
|
||||
std::string ssTOMLInput = R"toml(name = { first = "Tom", last = "Preston-Werner" }
|
||||
point = { x = 1, y = 2 }
|
||||
animal = { type.name = "pug" })code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
animal = { type.name = "pug" })toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
name = { first = "Tom", last = "Preston-Werner" }
|
||||
point = { x = 1, y = 2 }
|
||||
animal = { type.name = "pug" })code";
|
||||
animal = { type.name = "pug" })toml";
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
std::string ssGenerated;
|
||||
@@ -1157,13 +1158,13 @@ TEST(GenerateTOML, TransferEmbeddedInlineTables)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(test=[{ first = "Tom", last = "Preston-Werner" },
|
||||
std::string ssTOMLInput = R"toml(test=[{ first = "Tom", last = "Preston-Werner" },
|
||||
{ x = 1, y = 2 },
|
||||
{ type.name = "pug" }])code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
{ type.name = "pug" }])toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
test=[{ first = "Tom", last = "Preston-Werner" },
|
||||
{ x = 1, y = 2 },
|
||||
{ type.name = "pug" }])code";
|
||||
{ type.name = "pug" }])toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -1177,7 +1178,7 @@ TEST(GenerateTOML, TransferTableArrays)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code([[products]]
|
||||
std::string ssTOMLInput = R"toml([[products]]
|
||||
name = "Hammer"
|
||||
sku = 738594937
|
||||
|
||||
@@ -1187,8 +1188,8 @@ sku = 738594937
|
||||
name = "Nail"
|
||||
sku = 284758393
|
||||
|
||||
color = "gray")code";
|
||||
std::string ssTOMLOutput = R"code([[tree.branch.products]]
|
||||
color = "gray")toml";
|
||||
std::string ssTOMLOutput = R"toml([[tree.branch.products]]
|
||||
name = "Hammer"
|
||||
sku = 738594937
|
||||
|
||||
@@ -1198,7 +1199,7 @@ sku = 738594937
|
||||
name = "Nail"
|
||||
sku = 284758393
|
||||
|
||||
color = "gray")code";
|
||||
color = "gray")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -1212,7 +1213,7 @@ TEST(GenerateTOML, TransferMixedTableAndTableArrays)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code([[fruits]]
|
||||
std::string ssTOMLInput = R"toml([[fruits]]
|
||||
name = "apple"
|
||||
|
||||
[fruits.physical] # subtable
|
||||
@@ -1230,8 +1231,8 @@ name = "granny smith"
|
||||
name = "banana"
|
||||
|
||||
[[fruits.varieties]]
|
||||
name = "plantain")code";
|
||||
std::string ssTOMLOutput = R"code([[tree.branch.fruits]]
|
||||
name = "plantain")toml";
|
||||
std::string ssTOMLOutput = R"toml([[tree.branch.fruits]]
|
||||
name = "apple"
|
||||
|
||||
[tree.branch.fruits.physical] # subtable
|
||||
@@ -1249,7 +1250,7 @@ name = "granny smith"
|
||||
name = "banana"
|
||||
|
||||
[[tree.branch.fruits.varieties]]
|
||||
name = "plantain")code";
|
||||
name = "plantain")toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -1263,13 +1264,13 @@ TEST(GenerateTOML, TransferInlineTableArrays)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(points = [ { x = 1, y = 2, z = 3 },
|
||||
std::string ssTOMLInput = R"toml(points = [ { x = 1, y = 2, z = 3 },
|
||||
{ x = 7, y = 8, z = 9 },
|
||||
{ x = 2, y = 4, z = 8 } ])code";
|
||||
std::string ssTOMLOutput = R"code([tree.branch]
|
||||
{ x = 2, y = 4, z = 8 } ])toml";
|
||||
std::string ssTOMLOutput = R"toml([tree.branch]
|
||||
points = [ { x = 1, y = 2, z = 3 },
|
||||
{ x = 7, y = 8, z = 9 },
|
||||
{ x = 2, y = 4, z = 8 } ])code";
|
||||
{ x = 2, y = 4, z = 8 } ])toml";
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
std::string ssGenerated;
|
||||
|
||||
@@ -12,15 +12,15 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
|
||||
TEST(GenerateTOML, GetCommentRoot)
|
||||
TEST(GetSetComment, GetCommentRoot)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(# This is a comment)code";
|
||||
std::string ssTOML = R"toml(# This is a comment)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -34,17 +34,17 @@ TEST(GenerateTOML, GetCommentRoot)
|
||||
EXPECT_EQ(ssComment, "This is a comment");
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, GetMultiLineCommentRoot)
|
||||
TEST(GetSetComment, GetMultiLineCommentRoot)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(
|
||||
std::string ssTOML = R"toml(
|
||||
# This is a comment that stretches
|
||||
# more than one line.
|
||||
|
||||
# And here's another comment of more
|
||||
# than one line.
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
|
||||
@@ -55,23 +55,23 @@ TEST(GenerateTOML, GetMultiLineCommentRoot)
|
||||
ssComment = parser.Root().GetComment(sdv::toml::INodeInfo::ECommentType::out_of_scope_comment_before);
|
||||
EXPECT_TRUE(ssComment.empty());
|
||||
ssComment = parser.Root().GetComment(sdv::toml::INodeInfo::ECommentType::out_of_scope_comment_behind);
|
||||
EXPECT_EQ(ssComment, R"code(This is a comment that stretches more than one line.
|
||||
And here's another comment of more than one line.)code");
|
||||
EXPECT_EQ(ssComment, R"toml(This is a comment that stretches more than one line.
|
||||
And here's another comment of more than one line.)toml");
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, SetCommentRoot)
|
||||
TEST(GetSetComment, SetCommentRoot)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
// This will test the SetComment function and overwriting the existing comment.
|
||||
|
||||
std::string ssTOMLInput = R"code(# This is a double line comment
|
||||
# This is line two of the double line comment)code";
|
||||
std::string ssTOMLOutput = R"code(# This is comment way before
|
||||
std::string ssTOMLInput = R"toml(# This is a double line comment
|
||||
# This is line two of the double line comment)toml";
|
||||
std::string ssTOMLOutput = R"toml(# This is comment way before
|
||||
|
||||
# This is comment before
|
||||
# This is comment way behind
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -93,13 +93,13 @@ TEST(GenerateTOML, SetCommentRoot)
|
||||
EXPECT_EQ(ssGenerated, ssTOMLOutput);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, SetMultiLineCommentRoot)
|
||||
TEST(GetSetComment, SetMultiLineCommentRoot)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# This is a double line comment
|
||||
# This is line two of the double line comment)code";
|
||||
std::string ssTOMLOutput = R"code(# This is comment way before
|
||||
std::string ssTOMLInput = R"toml(# This is a double line comment
|
||||
# This is line two of the double line comment)toml";
|
||||
std::string ssTOMLOutput = R"toml(# This is comment way before
|
||||
|
||||
# And surprise, also a second line
|
||||
|
||||
@@ -109,7 +109,7 @@ TEST(GenerateTOML, SetMultiLineCommentRoot)
|
||||
# This is comment way behind
|
||||
|
||||
# And final, also a second line
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -139,13 +139,13 @@ And final, also a second line)");
|
||||
EXPECT_EQ(ssGenerated, ssTOMLOutput);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, RemoveCommentRoot)
|
||||
TEST(GetSetComment, RemoveCommentRoot)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# This is a double line comment
|
||||
# This is line two of the double line comment)code";
|
||||
std::string ssTOMLOutput = R"code()code";
|
||||
std::string ssTOMLInput = R"toml(# This is a double line comment
|
||||
# This is line two of the double line comment)toml";
|
||||
std::string ssTOMLOutput = R"toml()toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -155,16 +155,16 @@ TEST(GenerateTOML, RemoveCommentRoot)
|
||||
EXPECT_EQ(ssGenerated, ssTOMLOutput);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, GetCommentRootValue)
|
||||
TEST(GetSetComment, GetCommentRootValue)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(# This is a separate comment
|
||||
std::string ssTOML = R"toml(# This is a separate comment
|
||||
|
||||
# This is a comment before the value
|
||||
value = "this is the value text" # Comment following the value
|
||||
|
||||
# This is also a separate comment)code";
|
||||
# This is also a separate comment)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
sdv::TInterfaceAccessPtr ptrValue = parser.Root().GetNodeDirect("value");
|
||||
@@ -182,11 +182,11 @@ value = "this is the value text" # Comment following the value
|
||||
EXPECT_EQ(ssComment, "This is also a separate comment");
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, GetMultiLineCommentRootValue)
|
||||
TEST(GetSetComment, GetMultiLineCommentRootValue)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOML = R"code(
|
||||
std::string ssTOML = R"toml(
|
||||
|
||||
|
||||
# This is a separate comment with several line-breaks before.
|
||||
@@ -209,7 +209,7 @@ value = "this is the value text" # Comment following the value.
|
||||
# This is also a separate comment.
|
||||
# Followed by this text on the same line.
|
||||
|
||||
# And another text on a separate line.)code";
|
||||
# And another text on a separate line.)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOML));
|
||||
sdv::TInterfaceAccessPtr ptrValue = parser.Root().GetNodeDirect("value");
|
||||
@@ -218,32 +218,32 @@ value = "this is the value text" # Comment following the value.
|
||||
ASSERT_NE(pComment, nullptr);
|
||||
|
||||
std::string ssComment = pComment->GetComment(sdv::toml::INodeInfo::ECommentType::comment_before);
|
||||
EXPECT_EQ(ssComment, R"code(This is a comment before the value. And another comment before the value at the same line.
|
||||
Note: there was a space after the empty comment line. But that should not influence the comment lines.)code");
|
||||
EXPECT_EQ(ssComment, R"toml(This is a comment before the value. And another comment before the value at the same line.
|
||||
Note: there was a space after the empty comment line. But that should not influence the comment lines.)toml");
|
||||
ssComment = pComment->GetComment(sdv::toml::INodeInfo::ECommentType::comment_behind);
|
||||
EXPECT_EQ(ssComment, R"code(Comment following the value. More comment following the value. This becomes one line.
|
||||
But this is a separate line.)code");
|
||||
EXPECT_EQ(ssComment, R"toml(Comment following the value. More comment following the value. This becomes one line.
|
||||
But this is a separate line.)toml");
|
||||
ssComment = pComment->GetComment(sdv::toml::INodeInfo::ECommentType::out_of_scope_comment_before);
|
||||
EXPECT_EQ(ssComment, R"code(This is a separate comment with several line-breaks before. Followed by this text on the same line.
|
||||
Note: there was a space after the empty comment line. And another separate comment on a next line.)code");
|
||||
EXPECT_EQ(ssComment, R"toml(This is a separate comment with several line-breaks before. Followed by this text on the same line.
|
||||
Note: there was a space after the empty comment line. And another separate comment on a next line.)toml");
|
||||
ssComment = pComment->GetComment(sdv::toml::INodeInfo::ECommentType::out_of_scope_comment_behind);
|
||||
EXPECT_EQ(ssComment, R"code(This is also a separate comment. Followed by this text on the same line.
|
||||
And another text on a separate line.)code");
|
||||
EXPECT_EQ(ssComment, R"toml(This is also a separate comment. Followed by this text on the same line.
|
||||
And another text on a separate line.)toml");
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, SetCommentRootValue)
|
||||
TEST(GetSetComment, SetCommentRootValue)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
// This will test the SetComment function and overwriting the existing comment.
|
||||
|
||||
std::string ssTOMLInput = R"code(# This is a double line comment
|
||||
# This is line two of the double line comment)code";
|
||||
std::string ssTOMLOutput = R"code(# This is comment #3
|
||||
std::string ssTOMLInput = R"toml(# This is a double line comment
|
||||
# This is line two of the double line comment)toml";
|
||||
std::string ssTOMLOutput = R"toml(# This is comment #3
|
||||
|
||||
# This is comment #1
|
||||
# This is comment #4
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -265,13 +265,13 @@ TEST(GenerateTOML, SetCommentRootValue)
|
||||
EXPECT_EQ(ssGenerated, ssTOMLOutput);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, SetMultiLineCommentRootValue)
|
||||
TEST(GetSetComment, SetMultiLineCommentRootValue)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# This is a double line comment
|
||||
# This is line two of the double line comment)code";
|
||||
std::string ssTOMLOutput = R"code(# This is comment #3
|
||||
std::string ssTOMLInput = R"toml(# This is a double line comment
|
||||
# This is line two of the double line comment)toml";
|
||||
std::string ssTOMLOutput = R"toml(# This is comment #3
|
||||
|
||||
# And surprise, also a second line
|
||||
|
||||
@@ -281,7 +281,7 @@ TEST(GenerateTOML, SetMultiLineCommentRootValue)
|
||||
# This is comment #4
|
||||
|
||||
# And final, also a second line
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
@@ -311,13 +311,13 @@ And final, also a second line)");
|
||||
EXPECT_EQ(ssGenerated, ssTOMLOutput);
|
||||
}
|
||||
|
||||
TEST(GenerateTOML, RemoveCommentRootValue)
|
||||
TEST(GetSetComment, RemoveCommentRootValue)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
|
||||
std::string ssTOMLInput = R"code(# This is a double line comment
|
||||
# This is line two of the double line comment)code";
|
||||
std::string ssTOMLOutput = R"code()code";
|
||||
std::string ssTOMLInput = R"toml(# This is a double line comment
|
||||
# This is line two of the double line comment)toml";
|
||||
std::string ssTOMLOutput = R"toml()toml";
|
||||
|
||||
EXPECT_NO_THROW(parser.Process(ssTOMLInput));
|
||||
|
||||
119
tests/unit_tests/toml_parser/indexer_tests.cpp
Normal file
119
tests/unit_tests/toml_parser/indexer_tests.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Martin Stimpfl - initial API and implementation
|
||||
* Erik Verhoeven - writing TOML and whitespace preservation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_indexer.h"
|
||||
|
||||
TEST(IndexerTest, InitializeSingle)
|
||||
{
|
||||
toml_parser::CNodeIndexer indexer;
|
||||
|
||||
EXPECT_NO_THROW(toml_parser::CNodeIndex index = indexer.CreateIndex());
|
||||
}
|
||||
|
||||
TEST(IndexerTest, CompareOrder)
|
||||
{
|
||||
toml_parser::CNodeIndexer indexer;
|
||||
auto index1 = indexer.CreateIndex();
|
||||
auto index2 = indexer.CreateIndex();
|
||||
auto index3 = indexer.CreateIndex();
|
||||
EXPECT_GT(index2, index1);
|
||||
EXPECT_GT(index3, index1);
|
||||
EXPECT_GT(index3, index2);
|
||||
}
|
||||
|
||||
TEST(IndexerTest, SwitchOrder)
|
||||
{
|
||||
toml_parser::CNodeIndexer indexer;
|
||||
auto index1 = indexer.CreateIndex();
|
||||
auto index2 = indexer.CreateIndex();
|
||||
auto index3 = indexer.CreateIndex();
|
||||
index3.MoveBefore(index1);
|
||||
EXPECT_GT(index2, index1);
|
||||
EXPECT_LT(index3, index1);
|
||||
EXPECT_LT(index3, index2);
|
||||
}
|
||||
|
||||
TEST(IndexerTest, SwitchOrderMultipleIndexer)
|
||||
{
|
||||
toml_parser::CNodeIndexer indexer1;
|
||||
toml_parser::CNodeIndexer indexer2;
|
||||
toml_parser::CNodeIndexer indexer3;
|
||||
auto index1 = indexer1.CreateIndex();
|
||||
auto index2 = indexer2.CreateIndex();
|
||||
auto index3 = indexer3.CreateIndex();
|
||||
EXPECT_GT(index2, index1);
|
||||
EXPECT_GT(index3, index1);
|
||||
EXPECT_GT(index3, index2);
|
||||
index3.MoveBefore(index1);
|
||||
EXPECT_GT(index2, index1);
|
||||
EXPECT_LT(index3, index1);
|
||||
EXPECT_LT(index3, index2);
|
||||
index2.MoveBefore(index3);
|
||||
EXPECT_LT(index2, index1);
|
||||
EXPECT_LT(index3, index1);
|
||||
EXPECT_GT(index3, index2);
|
||||
}
|
||||
|
||||
TEST(IndexerTest, IndexLifetime)
|
||||
{
|
||||
toml_parser::CNodeIndexer indexer;
|
||||
|
||||
auto index1 = indexer.CreateIndex();
|
||||
size_t nCurrentCnt = indexer.Count();
|
||||
{
|
||||
auto index2 = indexer.CreateIndex();
|
||||
EXPECT_GT(index2, index1);
|
||||
EXPECT_EQ(indexer.Count(), nCurrentCnt + 1);
|
||||
}
|
||||
EXPECT_EQ(indexer.Count(), nCurrentCnt);
|
||||
auto index3 = indexer.CreateIndex();
|
||||
EXPECT_GT(index3, index1);
|
||||
}
|
||||
|
||||
TEST(IndexerTest, CopyIndex)
|
||||
{
|
||||
toml_parser::CNodeIndexer indexer;
|
||||
|
||||
auto index1 = indexer.CreateIndex();
|
||||
auto index2 = indexer.CreateIndex();
|
||||
auto index2b = index2;
|
||||
EXPECT_TRUE(index2b);
|
||||
EXPECT_TRUE(index2);
|
||||
EXPECT_GT(index2b, index1);
|
||||
EXPECT_GT(index2, index1);
|
||||
EXPECT_EQ(index2, index2b);
|
||||
auto index3 = indexer.CreateIndex();
|
||||
EXPECT_GT(index3, index2);
|
||||
EXPECT_GT(index3, index1);
|
||||
}
|
||||
|
||||
TEST(IndexerTest, MoveIndex)
|
||||
{
|
||||
toml_parser::CNodeIndexer indexer;
|
||||
|
||||
auto index1 = indexer.CreateIndex();
|
||||
auto index2 = indexer.CreateIndex();
|
||||
auto index2b = std::move(index2);
|
||||
EXPECT_TRUE(index2b);
|
||||
EXPECT_FALSE(index2);
|
||||
EXPECT_GT(index2b, index1);
|
||||
EXPECT_GT(index2, index1); // index 2 is not initialized any more.
|
||||
EXPECT_GT(index2, index2b);
|
||||
auto index3 = indexer.CreateIndex();
|
||||
EXPECT_GT(index3, index2b);
|
||||
EXPECT_GT(index3, index1);
|
||||
EXPECT_GT(index2, index3);
|
||||
}
|
||||
990
tests/unit_tests/toml_parser/insert_node.cpp
Normal file
990
tests/unit_tests/toml_parser/insert_node.cpp
Normal file
@@ -0,0 +1,990 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
#include <support/toml.h>
|
||||
|
||||
// Test TODO:
|
||||
// - Inserted and straight away deleted
|
||||
// - Inserted with false/deleted reference --error
|
||||
// - Inserted values before (okay) and behind (error) tables
|
||||
// - Inserted duplicate value -- error
|
||||
// - Smart insert (comments/whitespace around)
|
||||
// Insert as TOML, but only partly correct.
|
||||
|
||||
TEST(InsertNode, InsertValuesRoot)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertValue("", "value_int", 10));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(value_int = 10)toml");
|
||||
EXPECT_TRUE(root.InsertValue("", "value_str", u8"abc"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(value_int = 10
|
||||
value_str = "abc")toml");
|
||||
EXPECT_NE(parser.Root().InsertValue(root.GetNodeNameByIndex(0), "value_float", 123.456), nullptr);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(value_float = 123.456
|
||||
value_int = 10
|
||||
value_str = "abc")toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableRoot)
|
||||
{
|
||||
// Insert a standard table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTable("", "table1", false));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([table1])toml");
|
||||
|
||||
// Insert an inline table before
|
||||
EXPECT_TRUE(root.InsertTable(root.GetNodeNameByIndex(0), "table2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table2 = {}
|
||||
[table1])toml");
|
||||
|
||||
// Insert an inline table behind -> this will have to be printed before the standard table
|
||||
EXPECT_TRUE(root.InsertTable("", "table3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table2 = {}
|
||||
table3 = {}
|
||||
[table1])toml");
|
||||
|
||||
// Insert a standard table in front -> this will have to be printed behind the inline table
|
||||
EXPECT_TRUE(root.InsertTable(root.GetNodeNameByIndex(0), "table4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table2 = {}
|
||||
table3 = {}
|
||||
[table4]
|
||||
[table1])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertArrayRoot)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertArray("", "value_array1"));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(value_array1 = [])toml");
|
||||
EXPECT_TRUE(root.InsertArray("", "value_array2"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(value_array1 = []
|
||||
value_array2 = [])toml");
|
||||
EXPECT_TRUE(root.InsertArray(root.GetNodeNameByIndex(0), "value_array3"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(value_array3 = []
|
||||
value_array1 = []
|
||||
value_array2 = [])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableArrayRoot)
|
||||
{
|
||||
// Insert a standard table array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_TRUE(root.InsertTableArray("", "table_array1", false));
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array1]])toml");
|
||||
|
||||
// Insert an inline table array before
|
||||
EXPECT_TRUE(root.InsertTableArray(root.GetNodeNameByIndex(0), "table_array2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table_array2 = [{}]
|
||||
[[table_array1]])toml");
|
||||
|
||||
// Insert an inline table array behind -> this will have to be printed before the standard table array
|
||||
EXPECT_TRUE(root.InsertTableArray("", "table_array3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[table_array1]])toml");
|
||||
|
||||
// Insert a standard table array in front -> this will have to be printed behind the inline table array
|
||||
EXPECT_TRUE(root.InsertTableArray(root.GetNodeNameByIndex(0), "table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[table_array4]]
|
||||
[[table_array1]])toml");
|
||||
|
||||
// Add an additional table array entry for table array #4
|
||||
EXPECT_TRUE(root.InsertTableArray("", "table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[table_array4]]
|
||||
[[table_array1]]
|
||||
[[table_array4]])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertValueInStandardTable)
|
||||
{
|
||||
// Insert a standard table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection tableStandard = root.InsertTable("", "standard_table", false);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
|
||||
// Insert the values into the table
|
||||
EXPECT_TRUE(tableStandard.InsertValue("", "value_int", 10));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_int = 10)toml");
|
||||
EXPECT_TRUE(tableStandard.InsertValue("", "value_str", u8"abc"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_int = 10
|
||||
value_str = "abc")toml");
|
||||
EXPECT_TRUE(tableStandard.InsertValue(tableStandard.GetNodeNameByIndex(0), "value_float", 123.456));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_float = 123.456
|
||||
value_int = 10
|
||||
value_str = "abc")toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableInStandardTable)
|
||||
{
|
||||
// Insert a standard table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection tableStandard = root.InsertTable("", "standard_table", false);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
|
||||
// Insert a standard table
|
||||
EXPECT_TRUE(tableStandard.InsertTable("", "table1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table.table1])toml");
|
||||
|
||||
// Insert an inline table before
|
||||
EXPECT_TRUE(tableStandard.InsertTable(tableStandard.GetNodeNameByIndex(0), "table2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table2 = {}
|
||||
[standard_table.table1])toml");
|
||||
|
||||
// Insert an inline table behind -> this will have to be printed before the standard table
|
||||
EXPECT_TRUE(tableStandard.InsertTable("", "table3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table2 = {}
|
||||
table3 = {}
|
||||
[standard_table.table1])toml");
|
||||
|
||||
// Insert a standard table in front -> this will have to be printed behind the inline table relative to the elements of the
|
||||
// standard_table.
|
||||
EXPECT_TRUE(tableStandard.InsertTable(tableStandard.GetNodeNameByIndex(0), "table4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table2 = {}
|
||||
table3 = {}
|
||||
[standard_table.table4]
|
||||
[standard_table.table1])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertArrayInStandardTable)
|
||||
{
|
||||
// Insert a standard table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection tableStandard = root.InsertTable("", "standard_table", false);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
|
||||
// Insert arrays
|
||||
EXPECT_TRUE(tableStandard.InsertArray("", "value_array1"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_array1 = [])toml");
|
||||
EXPECT_TRUE(tableStandard.InsertArray("", "value_array2"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_array1 = []
|
||||
value_array2 = [])toml");
|
||||
EXPECT_TRUE(tableStandard.InsertArray(tableStandard.GetNodeNameByIndex(0), "value_array3"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
value_array3 = []
|
||||
value_array1 = []
|
||||
value_array2 = [])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableArrayInStandardTable)
|
||||
{
|
||||
// Insert a standard table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection tableStandard = root.InsertTable("", "standard_table", false);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
|
||||
// Insert standard table array
|
||||
EXPECT_TRUE(tableStandard.InsertTableArray("", "table_array1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[standard_table.table_array1]])toml");
|
||||
|
||||
// Insert an inline table array before
|
||||
EXPECT_TRUE(tableStandard.InsertTableArray(tableStandard.GetNodeNameByIndex(0), "table_array2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table_array2 = [{}]
|
||||
[[standard_table.table_array1]])toml");
|
||||
|
||||
// Insert an inline table array behind -> this will have to be printed before the standard table array
|
||||
EXPECT_TRUE(tableStandard.InsertTableArray("", "table_array3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[standard_table.table_array1]])toml");
|
||||
|
||||
// Insert a standard table array in front -> this will have to be printed behind the inline table array relative to the elements
|
||||
// of the standard_table.
|
||||
EXPECT_TRUE(tableStandard.InsertTableArray(tableStandard.GetNodeNameByIndex(0), "table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[standard_table.table_array4]]
|
||||
[[standard_table.table_array1]])toml");
|
||||
|
||||
// Add an additional table array entry for table array #4
|
||||
EXPECT_TRUE(tableStandard.InsertTableArray("", "table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([standard_table]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[standard_table.table_array4]]
|
||||
[[standard_table.table_array1]]
|
||||
[[standard_table.table_array4]])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertValueInInlineTable)
|
||||
{
|
||||
// Insert an inline table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection tableInline = root.InsertTable("", "inline_table", true);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {})toml");
|
||||
|
||||
// Insert the values into the table
|
||||
EXPECT_TRUE(tableInline.InsertValue("", "value_int", 10));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_int = 10})toml");
|
||||
EXPECT_TRUE(tableInline.InsertValue("", "value_str", u8"abc"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_int = 10, value_str = "abc"})toml");
|
||||
EXPECT_TRUE(tableInline.InsertValue(tableInline.GetNodeNameByIndex(0), "value_float", 123.456));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_float = 123.456, value_int = 10, value_str = "abc"})toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableInInlineTable)
|
||||
{
|
||||
// Insert an inline table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection tableInline = root.InsertTable("", "inline_table", true);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {})toml");
|
||||
|
||||
// Insert a standard table
|
||||
EXPECT_TRUE(tableInline.InsertTable("", "table1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table1 = {}})toml");
|
||||
|
||||
// Insert an inline table before
|
||||
EXPECT_TRUE(tableInline.InsertTable(tableInline.GetNodeNameByIndex(0), "table2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table2 = {}, table1 = {}})toml");
|
||||
|
||||
// Insert an inline table behind -> this will have to be printed before the standard table
|
||||
EXPECT_TRUE(tableInline.InsertTable("", "table3",
|
||||
true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table2 = {}, table1 = {}, table3 = {}})toml");
|
||||
|
||||
// Insert a standard table in front -> this will have to be printed behind the inline table
|
||||
EXPECT_TRUE(tableInline.InsertTable(tableInline.GetNodeNameByIndex(0), "table4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table4 = {}, table2 = {}, table1 = {}, table3 = {}})toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertArrayInInlineTable)
|
||||
{
|
||||
// Insert an inline table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection tableInline = root.InsertTable("", "inline_table", true);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {})toml");
|
||||
|
||||
// Insert arrays
|
||||
EXPECT_TRUE(tableInline.InsertArray("", "value_array1"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_array1 = []})toml");
|
||||
EXPECT_TRUE(tableInline.InsertArray("", "value_array2"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_array1 = [], value_array2 = []})toml");
|
||||
EXPECT_TRUE(tableInline.InsertArray(tableInline.GetNodeNameByIndex(0), "value_array3"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {value_array3 = [], value_array1 = [], value_array2 = []})toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableArrayInInlineTable)
|
||||
{
|
||||
// Insert an inline table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection tableInline = root.InsertTable("", "inline_table", true);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {})toml");
|
||||
|
||||
// Insert standard table array
|
||||
EXPECT_TRUE(tableInline.InsertTableArray("", "table_array1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table_array1 = [{}]})toml");
|
||||
|
||||
// Insert an inline table array before
|
||||
EXPECT_TRUE(tableInline.InsertTableArray(tableInline.GetNodeNameByIndex(0), "table_array2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table_array2 = [{}], table_array1 = [{}]})toml");
|
||||
|
||||
// Insert an inline table array behind -> this will have to be printed before the standard table array
|
||||
EXPECT_TRUE(tableInline.InsertTableArray("", "table_array3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_table = {table_array2 = [{}], table_array1 = [{}], table_array3 = [{}]})toml");
|
||||
|
||||
// Insert a standard table array in front -> this will have to be printed behind the inline table array
|
||||
EXPECT_TRUE(tableInline.InsertTableArray(tableInline.GetNodeNameByIndex(0), "table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML,
|
||||
R"toml(inline_table = {table_array4 = [{}], table_array2 = [{}], table_array1 = [{}], table_array3 = [{}]})toml");
|
||||
|
||||
// Add an additional table array entry for table array #4
|
||||
EXPECT_TRUE(tableInline.InsertTableArray("", "table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML,
|
||||
R"toml(inline_table = {table_array4 = [{}, {}], table_array2 = [{}], table_array1 = [{}], table_array3 = [{}]})toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertValueInArray)
|
||||
{
|
||||
// Insert an array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection arrayInline = root.InsertArray("", "inline_array");
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [])toml");
|
||||
|
||||
// Insert the values into the table (with or without name)
|
||||
EXPECT_TRUE(arrayInline.InsertValue("", "", 10));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [10])toml");
|
||||
EXPECT_TRUE(arrayInline.InsertValue("", "", u8"abc"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [10, "abc"])toml");
|
||||
EXPECT_TRUE(arrayInline.InsertValue(arrayInline.GetNodeNameByIndex(0), "", 123.456));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [123.456, 10, "abc"])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableInArray)
|
||||
{
|
||||
// Insert an array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection arrayInline = root.InsertArray("", "inline_array");
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [])toml");
|
||||
|
||||
// Insert a standard table
|
||||
sdv::toml::CNodeCollection table = arrayInline.InsertTable("", "", false);
|
||||
EXPECT_TRUE(table);
|
||||
table.InsertValue("", "a", 10);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [{a = 10}])toml");
|
||||
|
||||
// Insert an inline table before
|
||||
table = arrayInline.InsertTable(arrayInline.GetNodeNameByIndex(0), "", true);
|
||||
EXPECT_TRUE(table);
|
||||
table.InsertValue("", "b", 20);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [{b = 20}, {a = 10}])toml");
|
||||
|
||||
// Insert an inline table behind
|
||||
table = arrayInline.InsertTable("", "", true);
|
||||
EXPECT_TRUE(table);
|
||||
table.InsertValue("", "c", 30);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [{b = 20}, {a = 10}, {c = 30}])toml");
|
||||
|
||||
// Insert a standard table in front
|
||||
table = arrayInline.InsertTable(arrayInline.GetNodeNameByIndex(0), "", false);
|
||||
EXPECT_TRUE(table);
|
||||
table.InsertValue("", "d", 40);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [{d = 40}, {b = 20}, {a = 10}, {c = 30}])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertArrayInArray)
|
||||
{
|
||||
// Insert an array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection arrayInline = root.InsertArray("", "inline_array");
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [])toml");
|
||||
|
||||
// Insert arrays
|
||||
sdv::toml::CNodeCollection array = arrayInline.InsertArray("", "");
|
||||
EXPECT_TRUE(array);
|
||||
array.InsertValue("", "", 10);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[10]])toml");
|
||||
array = arrayInline.InsertArray("", "");
|
||||
EXPECT_TRUE(array);
|
||||
array.InsertValue("", "", 20);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[10], [20]])toml");
|
||||
array = arrayInline.InsertArray(arrayInline.GetNodeNameByIndex(0), "");
|
||||
EXPECT_TRUE(array);
|
||||
array.InsertValue("", "", 30);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[30], [10], [20]])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableArrayInArray)
|
||||
{
|
||||
// Insert an array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection arrayInline = root.InsertArray("", "inline_array");
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [])toml");
|
||||
|
||||
// Insert standard table array
|
||||
sdv::toml::CNodeCollection table = arrayInline.InsertTableArray("", "", false);
|
||||
EXPECT_TRUE(table);
|
||||
table.InsertValue("", "a", 10);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[{a = 10}]])toml");
|
||||
|
||||
// Insert an inline table array before
|
||||
table = arrayInline.InsertTableArray(arrayInline.GetNodeNameByIndex(0), "", true);
|
||||
EXPECT_TRUE(table);
|
||||
table.InsertValue("", "b", 20);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[{b = 20}], [{a = 10}]])toml");
|
||||
|
||||
// Insert an inline table array behind -> this will have to be printed before the standard table array
|
||||
table = arrayInline.InsertTableArray("", "", true);
|
||||
EXPECT_TRUE(table);
|
||||
table.InsertValue("", "c", 30);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[{b = 20}], [{a = 10}], [{c = 30}]])toml");
|
||||
|
||||
// Insert a standard table array in front -> this will have to be printed behind the inline table array
|
||||
table = arrayInline.InsertTableArray(arrayInline.GetNodeNameByIndex(0), "", false);
|
||||
EXPECT_TRUE(table);
|
||||
table.InsertValue("", "d", 40);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[{d = 40}], [{b = 20}], [{a = 10}], [{c = 30}]])toml");
|
||||
|
||||
// Add an additional table array entry for table array #4
|
||||
sdv::toml::CNodeCollection array = arrayInline.Get(0);
|
||||
EXPECT_TRUE(array);
|
||||
table = array.InsertTable("", "", false);
|
||||
EXPECT_TRUE(table);
|
||||
table.InsertValue("", "e", 50);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(inline_array = [[{d = 40}, {e = 50}], [{b = 20}], [{a = 10}], [{c = 30}]])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertValueInTableArray)
|
||||
{
|
||||
// Insert a standard table array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection table = root.InsertTableArray("", "table_array", false);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]])toml");
|
||||
|
||||
// Insert the values into the table
|
||||
EXPECT_TRUE(table.InsertValue("", "value_int", 10));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_int = 10)toml");
|
||||
EXPECT_TRUE(table.InsertValue("", "value_str", u8"abc"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_int = 10
|
||||
value_str = "abc")toml");
|
||||
EXPECT_TRUE(table.InsertValue(table.GetNodeNameByIndex(0), "value_float", 123.456));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_float = 123.456
|
||||
value_int = 10
|
||||
value_str = "abc")toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableInTableArray)
|
||||
{
|
||||
// Insert a standard table array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection table = root.InsertTableArray("", "table_array", false);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]])toml");
|
||||
|
||||
// Insert a standard table
|
||||
EXPECT_TRUE(table.InsertTable("", "table1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
[table_array.table1])toml");
|
||||
|
||||
// Insert an inline table before
|
||||
EXPECT_TRUE(table.InsertTable(table.GetNodeNameByIndex(0), "table2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table2 = {}
|
||||
[table_array.table1])toml");
|
||||
|
||||
// Insert an inline table behind -> this will have to be printed before the standard table
|
||||
EXPECT_TRUE(table.InsertTable("", "table3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table2 = {}
|
||||
table3 = {}
|
||||
[table_array.table1])toml");
|
||||
|
||||
// Insert a standard table in front -> this will have to be printed behind the inline table
|
||||
EXPECT_TRUE(table.InsertTable(table.GetNodeNameByIndex(0), "table4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table2 = {}
|
||||
table3 = {}
|
||||
[table_array.table4]
|
||||
[table_array.table1])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertArrayInTableArray)
|
||||
{
|
||||
// Insert a standard table array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection table = root.InsertTableArray("", "table_array", false);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]])toml");
|
||||
|
||||
// Insert arrays
|
||||
EXPECT_TRUE(table.InsertArray("", "value_array1"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_array1 = [])toml");
|
||||
EXPECT_TRUE(table.InsertArray("", "value_array2"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_array1 = []
|
||||
value_array2 = [])toml");
|
||||
EXPECT_TRUE(table.InsertArray(table.GetNodeNameByIndex(0), "value_array3"));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
value_array3 = []
|
||||
value_array1 = []
|
||||
value_array2 = [])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableArrayInTableArray)
|
||||
{
|
||||
// Insert a standard table array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
sdv::toml::CNodeCollection table = root.InsertTableArray("", "table_array", false);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]])toml");
|
||||
|
||||
// Insert standard table array
|
||||
EXPECT_TRUE(table.InsertTableArray("", "table_array1", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
[[table_array.table_array1]])toml");
|
||||
|
||||
// Insert an inline table array before
|
||||
EXPECT_TRUE(table.InsertTableArray(table.GetNodeNameByIndex(0), "table_array2", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table_array2 = [{}]
|
||||
[[table_array.table_array1]])toml");
|
||||
|
||||
// Insert an inline table array behind -> this will have to be printed before the standard table array
|
||||
EXPECT_TRUE(table.InsertTableArray("", "table_array3", true));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[table_array.table_array1]])toml");
|
||||
|
||||
// Insert a standard table array in front -> this will have to be printed behind the inline table array
|
||||
EXPECT_TRUE(table.InsertTableArray(table.GetNodeNameByIndex(0), "table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[table_array.table_array4]]
|
||||
[[table_array.table_array1]])toml");
|
||||
|
||||
// Add an additional table array entry for table array #4
|
||||
EXPECT_TRUE(table.InsertTableArray("", "table_array4", false));
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array]]
|
||||
table_array2 = [{}]
|
||||
table_array3 = [{}]
|
||||
[[table_array.table_array4]]
|
||||
[[table_array.table_array1]]
|
||||
[[table_array.table_array4]])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertValuesRootAsTOML)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_EQ(root.InsertTOML("", R"toml(# This is the first value
|
||||
value_int = 10)toml", true), 1);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(# This is the first value
|
||||
value_int = 10)toml");
|
||||
EXPECT_EQ(root.InsertTOML("", R"toml(value_str = "abc" # This is the second value
|
||||
|
||||
# Comment in between
|
||||
|
||||
# And the third value
|
||||
value_float = 123.456
|
||||
|
||||
# Some
|
||||
# Final
|
||||
# Words :-)
|
||||
)toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(# This is the first value
|
||||
value_int = 10
|
||||
value_str = "abc" # This is the second value
|
||||
|
||||
# Comment in between
|
||||
|
||||
# And the third value
|
||||
value_float = 123.456
|
||||
|
||||
# Some
|
||||
# Final
|
||||
# Words :-)
|
||||
)toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableRootAsTOML)
|
||||
{
|
||||
// Insert a standard table
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_EQ(root.InsertTOML("", R"toml([table1] # This is table 1
|
||||
a = 10
|
||||
b = 20.30)toml", true), 1);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([table1] # This is table 1
|
||||
a = 10
|
||||
b = 20.30)toml");
|
||||
|
||||
// Insert an inline table before
|
||||
EXPECT_EQ(root.InsertTOML(root.GetNodeNameByIndex(0), R"toml(# This is table 2
|
||||
table2 = {c = 40, d = "50"})toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(# This is table 2
|
||||
table2 = {c = 40, d = "50"}
|
||||
[table1] # This is table 1
|
||||
a = 10
|
||||
b = 20.30)toml");
|
||||
|
||||
// Insert an inline table behind -> this will have to be printed before the standard table
|
||||
EXPECT_EQ(root.InsertTOML("", R"toml(table3 = {e = '60'} # This is table 3
|
||||
)toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(# This is table 2
|
||||
table2 = {c = 40, d = "50"}
|
||||
table3 = {e = '60'} # This is table 3
|
||||
[table1] # This is table 1
|
||||
a = 10
|
||||
b = 20.30)toml");
|
||||
|
||||
// Insert a standard table in front -> this will have to be printed behind the inline table
|
||||
EXPECT_EQ(root.InsertTOML(root.GetNodeNameByIndex(0), R"toml(
|
||||
|
||||
# And this is table 4
|
||||
[table4]
|
||||
f = 70
|
||||
g = 80.90)toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(# This is table 2
|
||||
table2 = {c = 40, d = "50"}
|
||||
table3 = {e = '60'} # This is table 3
|
||||
|
||||
|
||||
# And this is table 4
|
||||
[table4]
|
||||
f = 70
|
||||
g = 80.90
|
||||
[table1] # This is table 1
|
||||
a = 10
|
||||
b = 20.30)toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertArrayRootAsTOML)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_EQ(root.InsertTOML("", R"toml(value_array1 = [10, 20, 30] # This is array 1)toml", true),
|
||||
1);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(value_array1 = [10, 20, 30] # This is array 1)toml");
|
||||
EXPECT_EQ(root.InsertTOML(root.GetNodeNameByIndex(0), R"toml(# This is array 2
|
||||
value_array2 = [
|
||||
40, # This is an integer value
|
||||
50.60, # This is a float value
|
||||
"70", # This is a string value
|
||||
])toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(# This is array 2
|
||||
value_array2 = [
|
||||
40, # This is an integer value
|
||||
50.60, # This is a float value
|
||||
"70", # This is a string value
|
||||
]
|
||||
value_array1 = [10, 20, 30] # This is array 1)toml");
|
||||
EXPECT_EQ(root.InsertTOML(root.GetNodeNameByIndex(1), R"toml(# And finally array 3
|
||||
value_array3 = [])toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(# This is array 2
|
||||
value_array2 = [
|
||||
40, # This is an integer value
|
||||
50.60, # This is a float value
|
||||
"70", # This is a string value
|
||||
]
|
||||
# And finally array 3
|
||||
value_array3 = []
|
||||
value_array1 = [10, 20, 30] # This is array 1)toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, InsertTableArrayRootAsTOML)
|
||||
{
|
||||
// Insert a standard table array
|
||||
toml_parser::CParser parser;
|
||||
sdv::toml::CNodeCollection root(&parser.Root());
|
||||
EXPECT_EQ(root.InsertTOML("", R"toml([[table_array1]]
|
||||
a = 10
|
||||
b = 20)toml", true), 1);
|
||||
std::string ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml([[table_array1]]
|
||||
a = 10
|
||||
b = 20)toml");
|
||||
|
||||
// Insert an inline table array before
|
||||
EXPECT_EQ(root.InsertTOML(root.GetNodeNameByIndex(0), R"toml(table_array2 = [{c = 30}, {d = 40}])toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table_array2 = [{c = 30}, {d = 40}]
|
||||
[[table_array1]]
|
||||
a = 10
|
||||
b = 20)toml");
|
||||
|
||||
// Insert an inline table array behind -> this will have to be printed before the standard table array
|
||||
EXPECT_EQ(root.InsertTOML("", R"toml(table_array3 =
|
||||
[
|
||||
{ e = 50 }
|
||||
])toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table_array2 = [{c = 30}, {d = 40}]
|
||||
table_array3 =
|
||||
[
|
||||
{ e = 50 }
|
||||
]
|
||||
[[table_array1]]
|
||||
a = 10
|
||||
b = 20)toml");
|
||||
|
||||
// Insert a standard table array in front -> this will have to be printed behind the inline table array
|
||||
EXPECT_EQ(root.InsertTOML(root.GetNodeNameByIndex(0), R"toml([[table_array4]]
|
||||
f = 60
|
||||
g = 70)toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table_array2 = [{c = 30}, {d = 40}]
|
||||
table_array3 =
|
||||
[
|
||||
{ e = 50 }
|
||||
]
|
||||
[[table_array4]]
|
||||
f = 60
|
||||
g = 70
|
||||
[[table_array1]]
|
||||
a = 10
|
||||
b = 20)toml");
|
||||
|
||||
// Add an additional table array entry for table array #4 (even provided as inline, must be added as standard).
|
||||
EXPECT_EQ(root.InsertTOML("", R"toml(table_array4 = [{h = 80}])toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table_array2 = [{c = 30}, {d = 40}]
|
||||
table_array3 =
|
||||
[
|
||||
{ e = 50 }
|
||||
]
|
||||
[[table_array4]]
|
||||
f = 60
|
||||
g = 70
|
||||
[[table_array1]]
|
||||
a = 10
|
||||
b = 20
|
||||
[[table_array4]]
|
||||
h = 80)toml");
|
||||
|
||||
// Add an additional table array entry for table array #4 (even provided as inline, must be added as standard).
|
||||
EXPECT_EQ(root.InsertTOML("", R"toml([[table_array3]]
|
||||
i = 90
|
||||
[[table_array3]]
|
||||
j = 100
|
||||
)toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(root.InsertTOML(root.GetNodeNameByIndex(0), R"toml([[table_array3]]
|
||||
k = 110)toml", true), 1);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table_array2 = [{c = 30}, {d = 40}]
|
||||
table_array3 =
|
||||
[{k = 110},
|
||||
{ e = 50 },
|
||||
{i = 90}, {j = 100}]
|
||||
[[table_array4]]
|
||||
f = 60
|
||||
g = 70
|
||||
[[table_array1]]
|
||||
a = 10
|
||||
b = 20
|
||||
[[table_array4]]
|
||||
h = 80)toml");
|
||||
|
||||
root.AutomaticFormat(true);
|
||||
ssTOML = parser.GenerateTOML();
|
||||
EXPECT_EQ(ssTOML, R"toml(table_array2 = [{c = 30}, {d = 40}]
|
||||
table_array3 = [{k = 110}, {e = 50}, {i = 90}, {j = 100}]
|
||||
[[table_array4]]
|
||||
f = 60
|
||||
g = 70
|
||||
[[table_array1]]
|
||||
a = 10
|
||||
b = 20
|
||||
[[table_array4]]
|
||||
h = 80)toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertValueInStandardTableAsTOML)
|
||||
{
|
||||
//// Insert a standard table
|
||||
//toml_parser::CParser parser;
|
||||
//sdv::toml::INodeCollectionInsert* pStandardTable = sdv::TInterfaceAccessPtr(root.InsertTable(
|
||||
// sdv::toml::npos, "standard_table", false)).
|
||||
// GetInterface<sdv::toml::INodeCollectionInsert>();
|
||||
//ASSERT_NE(pStandardTable, nullptr);
|
||||
//std::string ssTOML = parser.GenerateTOML();
|
||||
//EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertTableInStandardTableAsTOML)
|
||||
{
|
||||
//// Insert a standard table
|
||||
//toml_parser::CParser parser;
|
||||
//sdv::toml::INodeCollectionInsert* pStandardTable = sdv::TInterfaceAccessPtr(root.InsertTable(
|
||||
// sdv::toml::npos, "standard_table", false)).
|
||||
// GetInterface<sdv::toml::INodeCollectionInsert>();
|
||||
//ASSERT_NE(pStandardTable, nullptr);
|
||||
//std::string ssTOML = parser.GenerateTOML();
|
||||
//EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertArrayInStandardTableAsTOML)
|
||||
{
|
||||
//// Insert a standard table
|
||||
//toml_parser::CParser parser;
|
||||
//sdv::toml::INodeCollectionInsert* pStandardTable = sdv::TInterfaceAccessPtr(root.InsertTable(
|
||||
// sdv::toml::npos, "standard_table", false)).
|
||||
// GetInterface<sdv::toml::INodeCollectionInsert>();
|
||||
//ASSERT_NE(pStandardTable, nullptr);
|
||||
//std::string ssTOML = parser.GenerateTOML();
|
||||
//EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertTableArrayInStandardTableAsTOML)
|
||||
{
|
||||
//// Insert a standard table
|
||||
//toml_parser::CParser parser;
|
||||
//sdv::toml::INodeCollectionInsert* pStandardTable = sdv::TInterfaceAccessPtr(root.InsertTable(
|
||||
// sdv::toml::npos, "standard_table", false)).
|
||||
// GetInterface<sdv::toml::INodeCollectionInsert>();
|
||||
//ASSERT_NE(pStandardTable, nullptr);
|
||||
//std::string ssTOML = parser.GenerateTOML();
|
||||
//EXPECT_EQ(ssTOML, R"toml([standard_table])toml");
|
||||
}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertValueInInlineTableAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertTableInInlineTableAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertArrayInInlineTableAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertTableArrayInInlineTableAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertValueInArrayAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertTableInArrayAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertArrayInArrayAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertTableArrayInArrayAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertValueInTableArrayAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertTableInTableArrayAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertArrayInTableArrayAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertTableArrayInTableArrayAsTOML)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertMixed)
|
||||
{}
|
||||
|
||||
TEST(InsertNode, DISABLED_TestInsertMixedWithDelete)
|
||||
{}
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <limits>
|
||||
#include <functional>
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/lexer_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/exception.h"
|
||||
|
||||
@@ -114,7 +115,7 @@
|
||||
* + Exceptions thrown by the CharacterReaderare caught and result in a token_terminated-Token and no further lexing will be done
|
||||
*/
|
||||
|
||||
TEST(TOMLLexerTest, Keys)
|
||||
TEST(Lexer, Keys)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
// U+1F92B is the Finger-On-Lips Shushing emoji with UTF-8 byte representation 0xF09FA4AB
|
||||
@@ -169,7 +170,7 @@ TEST(TOMLLexerTest, Keys)
|
||||
EXPECT_EQ("1234", key8.StringValue());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, SyntaxToken_NewLine)
|
||||
TEST(Lexer, SyntaxToken_NewLine)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -187,7 +188,7 @@ TEST(TOMLLexerTest, SyntaxToken_NewLine)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_syntax_new_line, newLine2.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, SyntaxToken_Bracket)
|
||||
TEST(Lexer, SyntaxToken_Bracket)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -240,7 +241,7 @@ TEST(TOMLLexerTest, SyntaxToken_Bracket)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_syntax_table_array_close, tableArrayBracketClose.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, SyntaxToken_Assignment)
|
||||
TEST(Lexer, SyntaxToken_Assignment)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexerNormal(R"(
|
||||
@@ -279,7 +280,7 @@ TEST(TOMLLexerTest, SyntaxToken_Assignment)
|
||||
EXPECT_EQ(rValueNoSpace.StringValue(), "value");
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Comments)
|
||||
TEST(Lexer, Comments)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexerNormal(R"(
|
||||
@@ -414,7 +415,7 @@ TEST(TOMLLexerTest, Comments)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_comment, rNoSpaceTableClose.Next().Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, SyntaxToken_Dot)
|
||||
TEST(Lexer, SyntaxToken_Dot)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -451,7 +452,7 @@ TEST(TOMLLexerTest, SyntaxToken_Dot)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_syntax_dot, dot6.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, SyntaxToken_Braces)
|
||||
TEST(Lexer, SyntaxToken_Braces)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -511,7 +512,7 @@ TEST(TOMLLexerTest, SyntaxToken_Braces)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_key, emptyTable.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, SyntaxToken_ArrayTable)
|
||||
TEST(Lexer, SyntaxToken_ArrayTable)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -588,7 +589,7 @@ TEST(TOMLLexerTest, SyntaxToken_ArrayTable)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_syntax_table_array_close, tableArrayClose5.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Datatype_Integer)
|
||||
TEST(Lexer, Datatype_Integer)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -758,7 +759,7 @@ TEST(TOMLLexerTest, Datatype_Integer)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_error, intErr10.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Datatype_Float)
|
||||
TEST(Lexer, Datatype_Float)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -945,7 +946,7 @@ TEST(TOMLLexerTest, Datatype_Float)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_error, errFloat28.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Datatype_Boolean)
|
||||
TEST(Lexer, Datatype_Boolean)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -966,7 +967,7 @@ TEST(TOMLLexerTest, Datatype_Boolean)
|
||||
EXPECT_FALSE(falseToken.BooleanValue());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Datatype_String_BasicString)
|
||||
TEST(Lexer, Datatype_String_BasicString)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1045,7 +1046,7 @@ TEST(TOMLLexerTest, Datatype_String_BasicString)
|
||||
EXPECT_EQ("Musical eighth note: 𝅘𝅥𝅮", string_esc9.StringValue());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Datatype_String_BasicStringMultiline)
|
||||
TEST(Lexer, Datatype_String_BasicStringMultiline)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1170,7 +1171,7 @@ multiline string"""
|
||||
EXPECT_EQ("Musical eighth note: 𝅘𝅥𝅮 multiline", string_esc9.StringValue());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Datatype_String_LiteralString)
|
||||
TEST(Lexer, Datatype_String_LiteralString)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1208,7 +1209,7 @@ TEST(TOMLLexerTest, Datatype_String_LiteralString)
|
||||
EXPECT_EQ("<\\i\\c*\\s*>", regex.StringValue());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Datatype_String_LiteralStringMultiline)
|
||||
TEST(Lexer, Datatype_String_LiteralStringMultiline)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1257,27 +1258,27 @@ str = ''''That,' she said, 'is still pointless.''''
|
||||
EXPECT_EQ("'That,' she said, 'is still pointless.'", str.StringValue());
|
||||
}
|
||||
|
||||
// TEST(TOMLLexerTest, Datatype_OffsetDateTime)
|
||||
// TEST(Lexer, Datatype_OffsetDateTime)
|
||||
// {
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
|
||||
// TEST(TOMLLexerTest, Datatype_DateTime)
|
||||
// TEST(Lexer, Datatype_DateTime)
|
||||
// {
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
|
||||
// TEST(TOMLLexerTest, Datatype_LocalDate)
|
||||
// TEST(Lexer, Datatype_LocalDate)
|
||||
// {
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
|
||||
// TEST(TOMLLexerTest, Datatype_LocalTime)
|
||||
// TEST(Lexer, Datatype_LocalTime)
|
||||
// {
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
|
||||
TEST(TOMLLexerTest, Invalid_Key)
|
||||
TEST(Lexer, Invalid_Key)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1306,7 +1307,7 @@ TEST(TOMLLexerTest, Invalid_Key)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_error, invQuotedKey3.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Invalid_String)
|
||||
TEST(Lexer, Invalid_String)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer1(R"(key1 = "invalid escape sequence \h)"s);
|
||||
@@ -1332,7 +1333,7 @@ TEST(TOMLLexerTest, Invalid_String)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_error, invString4.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Invalid_Integer)
|
||||
TEST(Lexer, Invalid_Integer)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1406,7 +1407,7 @@ TEST(TOMLLexerTest, Invalid_Integer)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_error, invInteger15.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Invalid_Float)
|
||||
TEST(Lexer, Invalid_Float)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1440,7 +1441,7 @@ TEST(TOMLLexerTest, Invalid_Float)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_error, invFloat5.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Invalid_Boolean)
|
||||
TEST(Lexer, Invalid_Boolean)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1459,27 +1460,27 @@ TEST(TOMLLexerTest, Invalid_Boolean)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_error, invBool2.Category());
|
||||
}
|
||||
|
||||
// TEST(TOMLLexerTest, Invalid_OffsetDateTime)
|
||||
// TEST(Lexer, Invalid_OffsetDateTime)
|
||||
// {
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
|
||||
// TEST(TOMLLexerTest, Invalid_LocalDateTime)
|
||||
// TEST(Lexer, Invalid_LocalDateTime)
|
||||
// {
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
|
||||
// TEST(TOMLLexerTest, Invalid_LocalDate)
|
||||
// TEST(Lexer, Invalid_LocalDate)
|
||||
// {
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
|
||||
// TEST(TOMLLexerTest, Invalid_LocalTime)
|
||||
// TEST(Lexer, Invalid_LocalTime)
|
||||
// {
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
|
||||
TEST(TOMLLexerTest, Peek_NoAdvance)
|
||||
TEST(Lexer, Peek_NoAdvance)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1500,7 +1501,7 @@ TEST(TOMLLexerTest, Peek_NoAdvance)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_key, lexer.Peek(1).Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, Consume_Advance)
|
||||
TEST(Lexer, Consume_Advance)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1525,7 +1526,7 @@ TEST(TOMLLexerTest, Consume_Advance)
|
||||
EXPECT_EQ(toml_parser::ETokenCategory::token_syntax_assignment, ptr.Category());
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, PeekConsume_BoundsCheck)
|
||||
TEST(Lexer, PeekConsume_BoundsCheck)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"(
|
||||
@@ -1544,7 +1545,7 @@ TEST(TOMLLexerTest, PeekConsume_BoundsCheck)
|
||||
EXPECT_FALSE(lexer.Consume(0));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, PeekConsume_EmptyInput)
|
||||
TEST(Lexer, PeekConsume_EmptyInput)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer(R"()"s);
|
||||
@@ -1555,7 +1556,7 @@ TEST(TOMLLexerTest, PeekConsume_EmptyInput)
|
||||
EXPECT_FALSE(lexer.Consume(1));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, ExceptionHandling)
|
||||
TEST(Lexer, ExceptionHandling)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CLexer lexer;
|
||||
@@ -1577,7 +1578,7 @@ TEST(TOMLLexerTest, ExceptionHandling)
|
||||
EXPECT_FALSE(lexer.Consume(0));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerTest, DISABLED_RegenerateTOML)
|
||||
TEST(Lexer, DISABLED_RegenerateTOML)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
std::string ssOrginal = R"(
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../global/process_watchdog.h"
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/character_reader_utf_8.cpp"
|
||||
#include "../../../sdv_services/core/toml_parser/lexer_toml.cpp"
|
||||
#include "../../../sdv_services/core/toml_parser/lexer_toml_token.cpp"
|
||||
@@ -21,6 +22,8 @@
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.cpp"
|
||||
#include "../../../sdv_services/core/toml_parser/miscellaneous.cpp"
|
||||
#include "../../../sdv_services/core/toml_parser/code_snippet.cpp"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_indexer.cpp"
|
||||
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
extern "C" int wmain(int argc, wchar_t* argv[])
|
||||
@@ -30,6 +33,7 @@ extern "C" int main(int argc, char* argv[])
|
||||
{
|
||||
CProcessWatchdog watchdog;
|
||||
|
||||
CLocalMemMgr memmgr;
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
289
tests/unit_tests/toml_parser/make_inline_standard.cpp
Normal file
289
tests/unit_tests/toml_parser/make_inline_standard.cpp
Normal file
@@ -0,0 +1,289 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <functional>
|
||||
#include <gtest/gtest.h>
|
||||
#include <limits>
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/exception.h"
|
||||
#include "../../../sdv_services/core/toml_parser/miscellaneous.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
#include <support/toml.h>
|
||||
|
||||
TEST(MakeInline, Value)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(value1 = 1)toml";
|
||||
std::string ssTomlOut = R"toml(value1 = 1)toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeInline());
|
||||
EXPECT_TRUE(parser.Root().MakeInline());
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeStandard, Value)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(value1 = 1)toml";
|
||||
std::string ssTomlOut = R"toml(value1 = 1)toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_FALSE(parser.Root().CanMakeStandard());
|
||||
EXPECT_FALSE(parser.Root().MakeStandard(true));
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeInline, Array)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(value1 = ["abc", "def", "ghi"])toml";
|
||||
std::string ssTomlOut = R"toml(value1 = ["abc", "def", "ghi"])toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeInline());
|
||||
EXPECT_TRUE(parser.Root().MakeInline());
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeStandard, Array)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(value1 = ["abc", "def", "ghi"])toml";
|
||||
std::string ssTomlOut = R"toml(value1 = ["abc", "def", "ghi"])toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_FALSE(parser.Root().CanMakeStandard());
|
||||
EXPECT_FALSE(parser.Root().MakeStandard(true));
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeInline, StandardTable)
|
||||
{
|
||||
std::string ssTomlIn = R"toml([table1]
|
||||
value = 1)toml";
|
||||
std::string ssTomlOut = R"toml(table1 = {value = 1})toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeInline());
|
||||
EXPECT_TRUE(parser.Root().MakeInline());
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeStandard, StandardTable)
|
||||
{
|
||||
std::string ssTomlIn = R"toml([table1]
|
||||
value = 1)toml";
|
||||
std::string ssTomlOut = R"toml([table1]
|
||||
value = 1)toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeStandard());
|
||||
EXPECT_TRUE(parser.Root().MakeStandard(true));
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeInline, InlineTable)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(table1 = {value = 1})toml";
|
||||
std::string ssTomlOut = R"toml(table1 = {value = 1})toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeInline());
|
||||
EXPECT_TRUE(parser.Root().MakeInline());
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeStandard, InlineTable)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(table1 = {value = 1})toml";
|
||||
std::string ssTomlOut = R"toml([table1]
|
||||
value = 1)toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeStandard());
|
||||
EXPECT_TRUE(parser.Root().MakeStandard(true));
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeInline, StandardTableArray)
|
||||
{
|
||||
std::string ssTomlIn = R"toml([[table_array1]]
|
||||
value = 1)toml";
|
||||
std::string ssTomlOut = R"toml(table_array1 = [{value = 1}])toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeInline());
|
||||
EXPECT_TRUE(parser.Root().MakeInline());
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeStandard, StandardTableArray)
|
||||
{
|
||||
std::string ssTomlIn = R"toml([[table_array1]]
|
||||
value = 1)toml";
|
||||
std::string ssTomlOut = R"toml([[table_array1]]
|
||||
value = 1)toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeStandard());
|
||||
EXPECT_TRUE(parser.Root().MakeStandard(true));
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeInline, InlineTableArray)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(table_array1 = [{value = 1}])toml";
|
||||
std::string ssTomlOut = R"toml(table_array1 = [{value = 1}])toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeInline());
|
||||
EXPECT_TRUE(parser.Root().MakeInline());
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeStandard, InlineTableArray)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(table_array1 = [{value = 1}])toml";
|
||||
std::string ssTomlOut = R"toml([[table_array1]]
|
||||
value = 1)toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeStandard());
|
||||
EXPECT_TRUE(parser.Root().MakeStandard(true));
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeInline, StandardTableImplicit)
|
||||
{
|
||||
std::string ssTomlIn = R"toml([root_table.table1]
|
||||
value = 1)toml";
|
||||
std::string ssTomlOut = R"toml(root_table.table1 = {value = 1})toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeInline());
|
||||
EXPECT_TRUE(parser.Root().MakeInline());
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeStandard, StandardTableImplicit)
|
||||
{
|
||||
std::string ssTomlIn = R"toml([root_table.table1]
|
||||
value = 1)toml";
|
||||
std::string ssTomlOut = R"toml([root_table.table1]
|
||||
value = 1)toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeStandard());
|
||||
EXPECT_TRUE(parser.Root().MakeStandard(true));
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeInline, InlineTableImplicit)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(root_table.table1 = {value = 1})toml";
|
||||
std::string ssTomlOut = R"toml(root_table.table1 = {value = 1})toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeInline());
|
||||
EXPECT_TRUE(parser.Root().MakeInline());
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeStandard, InlineTableImplicit)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(root_table.table1 = {value = 1})toml";
|
||||
std::string ssTomlOut = R"toml([root_table.table1]
|
||||
value = 1)toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeStandard());
|
||||
EXPECT_TRUE(parser.Root().MakeStandard(true));
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeInline, StandardTableNested)
|
||||
{
|
||||
std::string ssTomlIn = R"toml([table1]
|
||||
value1 = 1
|
||||
[table1.table2]
|
||||
value2 = 2
|
||||
[table1.table3.table4]
|
||||
value3 = 3
|
||||
value4 = 4)toml";
|
||||
std::string ssTomlOut = R"toml(table1 = {value1 = 1, table2 = {value2 = 2}, table3.table4 = {value3 = 3, value4 = 4}})toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeInline());
|
||||
EXPECT_TRUE(parser.Root().MakeInline());
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeStandard, StandardTableNested)
|
||||
{
|
||||
std::string ssTomlIn = R"toml([table1]
|
||||
value = 1
|
||||
[table1.table2]
|
||||
value = 2)toml";
|
||||
std::string ssTomlOut = R"toml([table1]
|
||||
value = 1
|
||||
[table1.table2]
|
||||
value = 2)toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeStandard());
|
||||
EXPECT_TRUE(parser.Root().MakeStandard(true));
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeInline, InlineTableNested)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(table1 = {value = 1, table2 = {value = 2}})toml";
|
||||
std::string ssTomlOut = R"toml(table1 = {value = 1, table2 = {value = 2}})toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeInline());
|
||||
EXPECT_TRUE(parser.Root().MakeInline());
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
TEST(MakeStandard, InlineTableNested)
|
||||
{
|
||||
std::string ssTomlIn = R"toml(table1 = {value = 1, table2 = {value = 2}})toml";
|
||||
std::string ssTomlOut = R"toml([table1]
|
||||
value = 1
|
||||
[table1.table2]
|
||||
value = 2)toml";
|
||||
|
||||
toml_parser::CParser parser(ssTomlIn);
|
||||
EXPECT_TRUE(parser.Root().CanMakeStandard());
|
||||
EXPECT_TRUE(parser.Root().MakeStandard(true));
|
||||
std::string ssOut = parser.Root().GetTOML();
|
||||
EXPECT_EQ(ssTomlOut, ssOut);
|
||||
}
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
#include <functional>
|
||||
#include <gtest/gtest.h>
|
||||
#include <limits>
|
||||
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/exception.h"
|
||||
#include "../../../sdv_services/core/toml_parser/miscellaneous.h"
|
||||
|
||||
TEST(TOMLMiscellaneousTests, Hex2Dec)
|
||||
// Test TODO:
|
||||
// Shift nodes up and down within one container
|
||||
// Remove formatting from node
|
||||
// Compare TOMLs
|
||||
|
||||
TEST(Miscellaneous, Hex2Dec)
|
||||
{
|
||||
// No string
|
||||
std::string ssEmpty;
|
||||
@@ -47,7 +52,7 @@ TEST(TOMLMiscellaneousTests, Hex2Dec)
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("10xyz"), 16u);
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, Dec2Dec)
|
||||
TEST(Miscellaneous, Dec2Dec)
|
||||
{
|
||||
// No string
|
||||
std::string ssEmpty;
|
||||
@@ -75,7 +80,7 @@ TEST(TOMLMiscellaneousTests, Dec2Dec)
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("10xyz"), 10u);
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, Oct2Dec)
|
||||
TEST(Miscellaneous, Oct2Dec)
|
||||
{
|
||||
// No string
|
||||
std::string ssEmpty;
|
||||
@@ -103,7 +108,7 @@ TEST(TOMLMiscellaneousTests, Oct2Dec)
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("12xyz"), 10u);
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, Bin2Dec)
|
||||
TEST(Miscellaneous, Bin2Dec)
|
||||
{
|
||||
// No string
|
||||
std::string ssEmpty;
|
||||
@@ -131,7 +136,7 @@ TEST(TOMLMiscellaneousTests, Bin2Dec)
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("1010yz"), 10u);
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, UnicodeCharacter)
|
||||
TEST(Miscellaneous, UnicodeCharacter)
|
||||
{
|
||||
// No string
|
||||
std::string ssEmpty;
|
||||
@@ -147,7 +152,7 @@ TEST(TOMLMiscellaneousTests, UnicodeCharacter)
|
||||
EXPECT_EQ(toml_parser::EscapedUnicodeCharacterToUTF8("0001F600"), u8"\U0001F600");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitKeyStringEmpty)
|
||||
TEST(Miscellaneous, SplitKeyStringEmpty)
|
||||
{
|
||||
std::string ssKeyEmpty;
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKeyEmpty);
|
||||
@@ -155,7 +160,7 @@ TEST(TOMLMiscellaneousTests, SplitKeyStringEmpty)
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitKeyFirstPartOnly)
|
||||
TEST(Miscellaneous, SplitKeyFirstPartOnly)
|
||||
{
|
||||
std::string ssKey = "abc";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
@@ -196,7 +201,7 @@ TEST(TOMLMiscellaneousTests, SplitKeyFirstPartOnly)
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitStandardBareKey)
|
||||
TEST(Miscellaneous, SplitStandardBareKey)
|
||||
{
|
||||
std::string ssKey = "abc.def";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
@@ -236,7 +241,7 @@ TEST(TOMLMiscellaneousTests, SplitStandardBareKey)
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitBareKeyWithSpace)
|
||||
TEST(Miscellaneous, SplitBareKeyWithSpace)
|
||||
{
|
||||
std::string ssKey = " abc.def";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
@@ -265,7 +270,7 @@ TEST(TOMLMiscellaneousTests, SplitBareKeyWithSpace)
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitLiteralKey)
|
||||
TEST(Miscellaneous, SplitLiteralKey)
|
||||
{
|
||||
std::string ssKey = "'abc'";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
@@ -309,7 +314,7 @@ TEST(TOMLMiscellaneousTests, SplitLiteralKey)
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitQuotedKey)
|
||||
TEST(Miscellaneous, SplitQuotedKey)
|
||||
{
|
||||
std::string ssKey = "\"abc\"";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
@@ -348,7 +353,7 @@ TEST(TOMLMiscellaneousTests, SplitQuotedKey)
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitEscapedQuotedKey)
|
||||
TEST(Miscellaneous, SplitEscapedQuotedKey)
|
||||
{
|
||||
std::string ssKey = "\"abc\\bdef\"";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
@@ -413,7 +418,7 @@ TEST(TOMLMiscellaneousTests, SplitEscapedQuotedKey)
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitTableKey)
|
||||
TEST(Miscellaneous, SplitTableKey)
|
||||
{
|
||||
std::string ssKey = "abc.def";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
@@ -431,7 +436,7 @@ TEST(TOMLMiscellaneousTests, SplitTableKey)
|
||||
EXPECT_EQ(prSplittedKey.second, "def.ghi");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitArrayKey)
|
||||
TEST(Miscellaneous, SplitArrayKey)
|
||||
{
|
||||
std::string ssKey = "abc[1]";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
@@ -493,7 +498,7 @@ TEST(TOMLMiscellaneousTests, SplitArrayKey)
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SmartQuoteBareKeys)
|
||||
TEST(Miscellaneous, SmartQuoteBareKeys)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc", toml_parser::EQuoteRequest::smart_key), "abc");
|
||||
EXPECT_EQ(toml_parser::QuoteText("123", toml_parser::EQuoteRequest::smart_key), "123");
|
||||
@@ -502,7 +507,7 @@ TEST(TOMLMiscellaneousTests, SmartQuoteBareKeys)
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::smart_key), "ABC-DEF");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SmartQuoteSpecialCharsKeys)
|
||||
TEST(Miscellaneous, SmartQuoteSpecialCharsKeys)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("", toml_parser::EQuoteRequest::smart_key), "\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc def", toml_parser::EQuoteRequest::smart_key), "\"abc def\"");
|
||||
@@ -515,7 +520,7 @@ TEST(TOMLMiscellaneousTests, SmartQuoteSpecialCharsKeys)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::smart_key), "\"abc/\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SmartQuoteEscapeCharsKeys)
|
||||
TEST(Miscellaneous, SmartQuoteEscapeCharsKeys)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\tdef", toml_parser::EQuoteRequest::smart_key), "\"abc\\tdef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\\def", toml_parser::EQuoteRequest::smart_key), "\"abc\\\\def\"");
|
||||
@@ -527,7 +532,7 @@ TEST(TOMLMiscellaneousTests, SmartQuoteEscapeCharsKeys)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::smart_key), "\"abc\\rdef\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SmartQuoteControlCharsKeys)
|
||||
TEST(Miscellaneous, SmartQuoteControlCharsKeys)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText(std::string(1, '\0'), toml_parser::EQuoteRequest::smart_key), "\"\\u0000\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0001", toml_parser::EQuoteRequest::smart_key), "\"\\u0001\"");
|
||||
@@ -567,7 +572,7 @@ TEST(TOMLMiscellaneousTests, SmartQuoteControlCharsKeys)
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SmartQuoteText)
|
||||
TEST(Miscellaneous, SmartQuoteText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc", toml_parser::EQuoteRequest::smart_text), "\"abc\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("123", toml_parser::EQuoteRequest::smart_text), "\"123\"");
|
||||
@@ -576,7 +581,7 @@ TEST(TOMLMiscellaneousTests, SmartQuoteText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::smart_text), "\"ABC-DEF\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SmartQuoteSpecialCharsText)
|
||||
TEST(Miscellaneous, SmartQuoteSpecialCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("", toml_parser::EQuoteRequest::smart_text), "\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc def", toml_parser::EQuoteRequest::smart_text), "\"abc def\"");
|
||||
@@ -589,7 +594,7 @@ TEST(TOMLMiscellaneousTests, SmartQuoteSpecialCharsText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::smart_text), "\"abc/\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SmartQuoteEscapeCharsText)
|
||||
TEST(Miscellaneous, SmartQuoteEscapeCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\tdef", toml_parser::EQuoteRequest::smart_text), "\"abc\\tdef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\\def", toml_parser::EQuoteRequest::smart_text), "'abc\\def'");
|
||||
@@ -601,7 +606,7 @@ TEST(TOMLMiscellaneousTests, SmartQuoteEscapeCharsText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::smart_text), "\"abc\\rdef\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SmartQuoteControlCharsText)
|
||||
TEST(Miscellaneous, SmartQuoteControlCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText(std::string(1, '\0'), toml_parser::EQuoteRequest::smart_text), "\"\\u0000\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0001", toml_parser::EQuoteRequest::smart_text), "\"\\u0001\"");
|
||||
@@ -641,7 +646,7 @@ TEST(TOMLMiscellaneousTests, SmartQuoteControlCharsText)
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, QuotedText)
|
||||
TEST(Miscellaneous, QuotedText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc", toml_parser::EQuoteRequest::quoted_text), "\"abc\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("123", toml_parser::EQuoteRequest::quoted_text), "\"123\"");
|
||||
@@ -650,7 +655,7 @@ TEST(TOMLMiscellaneousTests, QuotedText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::quoted_text), "\"ABC-DEF\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, QuotedSpecialCharsText)
|
||||
TEST(Miscellaneous, QuotedSpecialCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("", toml_parser::EQuoteRequest::quoted_text), "\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc def", toml_parser::EQuoteRequest::quoted_text), "\"abc def\"");
|
||||
@@ -663,7 +668,7 @@ TEST(TOMLMiscellaneousTests, QuotedSpecialCharsText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::quoted_text), "\"abc/\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, QuotedEscapeCharsText)
|
||||
TEST(Miscellaneous, QuotedEscapeCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\tdef", toml_parser::EQuoteRequest::quoted_text), "\"abc\\tdef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\\def", toml_parser::EQuoteRequest::quoted_text), "\"abc\\\\def\"");
|
||||
@@ -675,7 +680,7 @@ TEST(TOMLMiscellaneousTests, QuotedEscapeCharsText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::quoted_text), "\"abc\\rdef\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, QuotedControlCharsText)
|
||||
TEST(Miscellaneous, QuotedControlCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText(std::string(1, '\0'), toml_parser::EQuoteRequest::quoted_text), "\"\\u0000\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0001", toml_parser::EQuoteRequest::quoted_text), "\"\\u0001\"");
|
||||
@@ -715,7 +720,7 @@ TEST(TOMLMiscellaneousTests, QuotedControlCharsText)
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, LiteralText)
|
||||
TEST(Miscellaneous, LiteralText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc", toml_parser::EQuoteRequest::literal_text), "'abc'");
|
||||
EXPECT_EQ(toml_parser::QuoteText("123", toml_parser::EQuoteRequest::literal_text), "'123'");
|
||||
@@ -724,7 +729,7 @@ TEST(TOMLMiscellaneousTests, LiteralText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::literal_text), "'ABC-DEF'");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, LiteralSpecialCharsText)
|
||||
TEST(Miscellaneous, LiteralSpecialCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("", toml_parser::EQuoteRequest::literal_text), "''");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc def", toml_parser::EQuoteRequest::literal_text), "'abc def'");
|
||||
@@ -737,7 +742,7 @@ TEST(TOMLMiscellaneousTests, LiteralSpecialCharsText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::literal_text), "'abc/'");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, LiteralEscapeCharsText)
|
||||
TEST(Miscellaneous, LiteralEscapeCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\tdef", toml_parser::EQuoteRequest::literal_text), "\"abc\\tdef\""); // Becomes quoted
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\\def", toml_parser::EQuoteRequest::literal_text), "'abc\\def'");
|
||||
@@ -749,7 +754,7 @@ TEST(TOMLMiscellaneousTests, LiteralEscapeCharsText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::literal_text), "\"abc\\rdef\""); // Becomes quoted
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, LiteralControlCharsText)
|
||||
TEST(Miscellaneous, LiteralControlCharsText)
|
||||
{
|
||||
// All become quoted insteda of literal (due to control character).
|
||||
EXPECT_EQ(toml_parser::QuoteText(std::string(1, '\0'), toml_parser::EQuoteRequest::literal_text), "\"\\u0000\"");
|
||||
@@ -790,7 +795,7 @@ TEST(TOMLMiscellaneousTests, LiteralControlCharsText)
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, MultiLineQuotedText)
|
||||
TEST(Miscellaneous, MultiLineQuotedText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("123", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"123\"\"\"");
|
||||
@@ -799,7 +804,7 @@ TEST(TOMLMiscellaneousTests, MultiLineQuotedText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"ABC-DEF\"\"\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, MultiLineQuotedSpecialCharsText)
|
||||
TEST(Miscellaneous, MultiLineQuotedSpecialCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc def", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc def\"\"\"");
|
||||
@@ -812,7 +817,7 @@ TEST(TOMLMiscellaneousTests, MultiLineQuotedSpecialCharsText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc/\"\"\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, MultiLineQuotedEscapeCharsText)
|
||||
TEST(Miscellaneous, MultiLineQuotedEscapeCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\tdef", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc\\tdef\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\\def", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc\\\\def\"\"\"");
|
||||
@@ -826,7 +831,7 @@ TEST(TOMLMiscellaneousTests, MultiLineQuotedEscapeCharsText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc\rdef\"\"\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, MultiLineQuotedControlCharsText)
|
||||
TEST(Miscellaneous, MultiLineQuotedControlCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText(std::string(1, '\0'), toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0000\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0001", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0001\"\"\"");
|
||||
@@ -866,7 +871,7 @@ TEST(TOMLMiscellaneousTests, MultiLineQuotedControlCharsText)
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, MultiLineLiteralText)
|
||||
TEST(Miscellaneous, MultiLineLiteralText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc", toml_parser::EQuoteRequest::multi_line_literal_text), "'''abc'''");
|
||||
EXPECT_EQ(toml_parser::QuoteText("123", toml_parser::EQuoteRequest::multi_line_literal_text), "'''123'''");
|
||||
@@ -875,7 +880,7 @@ TEST(TOMLMiscellaneousTests, MultiLineLiteralText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::multi_line_literal_text), "'''ABC-DEF'''");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, MultiLineLiteralSpecialCharsText)
|
||||
TEST(Miscellaneous, MultiLineLiteralSpecialCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("", toml_parser::EQuoteRequest::multi_line_literal_text), "''''''");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc def", toml_parser::EQuoteRequest::multi_line_literal_text), "'''abc def'''");
|
||||
@@ -888,7 +893,7 @@ TEST(TOMLMiscellaneousTests, MultiLineLiteralSpecialCharsText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::multi_line_literal_text), "'''abc/'''");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, MultiLineLiteralEscapeCharsText)
|
||||
TEST(Miscellaneous, MultiLineLiteralEscapeCharsText)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\tdef", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"abc\\tdef\"\"\""); // Becomes quoted
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\\def", toml_parser::EQuoteRequest::multi_line_literal_text), "'''abc\\def'''");
|
||||
@@ -901,7 +906,7 @@ TEST(TOMLMiscellaneousTests, MultiLineLiteralEscapeCharsText)
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::multi_line_literal_text), "'''abc\rdef'''");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, MultiLineLiteralControlCharsText)
|
||||
TEST(Miscellaneous, MultiLineLiteralControlCharsText)
|
||||
{
|
||||
// All become quoted insteda of literal (due to control character).
|
||||
EXPECT_EQ(toml_parser::QuoteText(std::string(1, '\0'), toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0000\"\"\"");
|
||||
@@ -942,7 +947,7 @@ TEST(TOMLMiscellaneousTests, MultiLineLiteralControlCharsText)
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, ExtractBareKeyName)
|
||||
TEST(Miscellaneous, ExtractBareKeyName)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName(""), "");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc.def"), "def");
|
||||
@@ -955,7 +960,7 @@ TEST(TOMLMiscellaneousTests, ExtractBareKeyName)
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("1234"), "1234");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, ExtractQuotedKeyName)
|
||||
TEST(Miscellaneous, ExtractQuotedKeyName)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("\"\""), "");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("\"abc\""), "abc");
|
||||
@@ -968,7 +973,7 @@ TEST(TOMLMiscellaneousTests, ExtractQuotedKeyName)
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc\"def\""), ""); // Failure
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, ExtractLiteralKeyName)
|
||||
TEST(Miscellaneous, ExtractLiteralKeyName)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("''"), "");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("'abc'"), "abc");
|
||||
@@ -982,7 +987,7 @@ TEST(TOMLMiscellaneousTests, ExtractLiteralKeyName)
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc'def"), ""); // Failure
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, ExtractIndexKeyName)
|
||||
TEST(Miscellaneous, ExtractIndexKeyName)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("[0]"), "0");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("[0][1]"), "1");
|
||||
@@ -13,6 +13,7 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
|
||||
@@ -444,32 +445,32 @@ TEST(NestedContent, InlineTable)
|
||||
TEST(NestedContent, InlineTableBreakLine)
|
||||
{
|
||||
// The following are not allowed
|
||||
EXPECT_THROW(toml_parser::CParser(R"code(
|
||||
EXPECT_THROW(toml_parser::CParser(R"toml(
|
||||
table = { a = 1, b = 2,
|
||||
c = 3, d = 4 }
|
||||
)code"), sdv::toml::XTOMLParseException);
|
||||
EXPECT_THROW(toml_parser::CParser(R"code(
|
||||
)toml"), sdv::toml::XTOMLParseException);
|
||||
EXPECT_THROW(toml_parser::CParser(R"toml(
|
||||
table = { a = 1, b = 2
|
||||
,c = 3, d = 4 }
|
||||
)code"), sdv::toml::XTOMLParseException);
|
||||
)toml"), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Line breaks are allowed when part of an array or have multi-line strings
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"code(
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"toml(
|
||||
array = [{ a = 1, b = 2},
|
||||
{c = 3, d = 4}]
|
||||
)code"));
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"code(
|
||||
)toml"));
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"toml(
|
||||
table = { a = 1, b = [2, 3,
|
||||
4, 5], c = 6, d = 7}
|
||||
)code"));
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"code(
|
||||
)toml"));
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"toml(
|
||||
table = { x = "abc", y = """def-
|
||||
ghi""", z = "jkl" }
|
||||
)code"));
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"code(
|
||||
)toml"));
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"toml(
|
||||
table = { x = 'abc', y = '''def-
|
||||
ghi''', z = 'jkl' }
|
||||
)code"));
|
||||
)toml"));
|
||||
}
|
||||
|
||||
TEST(SpecialCases, Keys)
|
||||
@@ -865,6 +866,60 @@ TEST(Ordering, TableAray)
|
||||
EXPECT_EQ(ptrArray->Get(uiIndex)->Cast<toml_parser::CTable>()->Direct("a")->GetValue(), (int64_t) uiIndex);
|
||||
}
|
||||
|
||||
TEST(Ordering, TableArayWithTables)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CParser parser(R"(
|
||||
[topTable]
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 0
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 1
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 2
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 3
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 4
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 5
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 6
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 7
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 8
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 9
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 10
|
||||
[[topTable.tableArray]]
|
||||
[topTable.tableArray.MyTable]
|
||||
a = 11
|
||||
)"s);
|
||||
|
||||
auto tableArray = parser.Root().Direct("topTable.tableArray");
|
||||
|
||||
ASSERT_NE(tableArray, nullptr);
|
||||
auto ptrArray = tableArray->Cast<toml_parser::CArray>();
|
||||
EXPECT_EQ(ptrArray->GetCount(), 12u);
|
||||
for (uint32_t uiIndex = 0; uiIndex < ptrArray->GetCount(); uiIndex++)
|
||||
{
|
||||
EXPECT_EQ(ptrArray->Get(uiIndex)->Cast<toml_parser::CTable>()->Direct("MyTable.a")->GetValue(), (int64_t)uiIndex);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Ordering, NodeGetDirect)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <limits>
|
||||
#include <functional>
|
||||
#include "../../../global/localmemmgr.h"
|
||||
#include "../../../sdv_services/core/toml_parser/lexer_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/exception.h"
|
||||
#include "../../../sdv_services/core/toml_parser/miscellaneous.h"
|
||||
@@ -445,7 +446,7 @@ bool FindAndExtendToken(toml_parser::CLexer& rlexer, const std::string& rssKey,
|
||||
return false; // When coming here, the key was not found
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, CheckEmptyRange)
|
||||
TEST(StatementBoundary, CheckEmptyRange)
|
||||
{
|
||||
std::string ssEmpty;
|
||||
|
||||
@@ -459,11 +460,11 @@ TEST(TOMLLexerStatementBoundaryTests, CheckEmptyRange)
|
||||
EXPECT_THROW(lexerEmpty.SmartExtendNodeRange(rangeEmpty), sdv::toml::XTOMLParseException);
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, CheckInvalidRange)
|
||||
TEST(StatementBoundary, CheckInvalidRange)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_a = 10
|
||||
)code";
|
||||
)toml";
|
||||
std::string ssOther = ssCode;
|
||||
|
||||
// Process the code
|
||||
@@ -477,11 +478,11 @@ token_a = 10
|
||||
EXPECT_THROW(lexerCode.SmartExtendNodeRange(rangeOther), sdv::toml::XTOMLParseException);
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, StandardIntegerAssignment)
|
||||
TEST(StatementBoundary, StandardIntegerAssignment)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_a = 10
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -497,11 +498,11 @@ token_a = 10
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, StandardStringAssignment)
|
||||
TEST(StatementBoundary, StandardStringAssignment)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_b = "abc"
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -516,16 +517,16 @@ token_b = "abc"
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, AssignmentWithIndependentComment)
|
||||
TEST(StatementBoundary, AssignmentWithIndependentComment)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_c = 30.1
|
||||
|
||||
# middle followed by double lines
|
||||
|
||||
|
||||
token_d = "def"
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -541,9 +542,9 @@ token_d = "def"
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, AssignmentCommentsNotPartOfIt)
|
||||
TEST(StatementBoundary, AssignmentCommentsNotPartOfIt)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_c = 30.1
|
||||
|
||||
# middle followed by double lines
|
||||
@@ -554,7 +555,7 @@ token_d = "def"
|
||||
# before
|
||||
# more before
|
||||
token_e = [10, 20, 30]
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -570,9 +571,9 @@ token_e = [10, 20, 30]
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, ArrayAssignmentWithPreceedingComment)
|
||||
TEST(StatementBoundary, ArrayAssignmentWithPreceedingComment)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_d = "def"
|
||||
|
||||
# before
|
||||
@@ -581,7 +582,7 @@ token_e = [10, 20, 30]
|
||||
|
||||
token_f = "ghi" # after
|
||||
# more after
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -609,14 +610,14 @@ token_f = "ghi" # after
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, AssignmentWithFollowingComment)
|
||||
TEST(StatementBoundary, AssignmentWithFollowingComment)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_f = "ghi" # after
|
||||
# more after
|
||||
# belonging to next
|
||||
[token_g]
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -636,9 +637,9 @@ token_f = "ghi" # after
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, AssignmentWithFollowingComment2)
|
||||
TEST(StatementBoundary, AssignmentWithFollowingComment2)
|
||||
{
|
||||
std::string ssTOML = R"code(
|
||||
std::string ssTOML = R"toml(
|
||||
|
||||
|
||||
# This is a separate comment with several line-breaks before.
|
||||
@@ -661,7 +662,7 @@ value = "this is the value text" # Comment following the value.
|
||||
# This is also a separate comment.
|
||||
# Followed by this text on the same line.
|
||||
|
||||
# And another text on a separate line.)code";
|
||||
# And another text on a separate line.)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssTOML);
|
||||
@@ -701,15 +702,15 @@ value = "this is the value text" # Comment following the value.
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, TableAssignmentWithDedicatedComment)
|
||||
TEST(StatementBoundary, TableAssignmentWithDedicatedComment)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_f = "ghi" # after
|
||||
# more after
|
||||
# belonging to next
|
||||
[token_g]
|
||||
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -725,14 +726,14 @@ token_f = "ghi" # after
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, AssignmentWithFollowingCommentWithoutIndentation)
|
||||
TEST(StatementBoundary, AssignmentWithFollowingCommentWithoutIndentation)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_h = "jkl"#after without whitespace
|
||||
# more after due to following empty line
|
||||
|
||||
[token_i]
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -751,16 +752,16 @@ token_h = "jkl"#after without whitespace
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, AssignmentCommentsExcluded)
|
||||
TEST(StatementBoundary, AssignmentCommentsExcluded)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_h = "jkl"#after without whitespace
|
||||
# more after due to following empty line
|
||||
|
||||
[token_i]
|
||||
# not after
|
||||
token_j = 20
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -773,13 +774,13 @@ token_j = 20
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, SmartExtendTokenRange)
|
||||
TEST(StatementBoundary, SmartExtendTokenRange)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
[token_i]
|
||||
# not after
|
||||
token_j = 20
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -796,12 +797,12 @@ token_j = 20
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, StandardAssignmentWithIndentation)
|
||||
TEST(StatementBoundary, StandardAssignmentWithIndentation)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_k = 30
|
||||
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -818,11 +819,11 @@ TEST(TOMLLexerStatementBoundaryTests, StandardAssignmentWithIndentation)
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, ArrayOfStringsAssignment)
|
||||
TEST(StatementBoundary, ArrayOfStringsAssignment)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_l = ["abc", "def", "ghi"]
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -846,16 +847,16 @@ TEST(TOMLLexerStatementBoundaryTests, ArrayOfStringsAssignment)
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, InlineTableAssignmentWithIndependentComment)
|
||||
TEST(StatementBoundary, InlineTableAssignmentWithIndependentComment)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_m = {x = 10, str = "gfh"}
|
||||
|
||||
# middle followed by double newlines
|
||||
|
||||
|
||||
token_n = 100
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -885,9 +886,9 @@ TEST(TOMLLexerStatementBoundaryTests, InlineTableAssignmentWithIndependentCommen
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, IndentedAssignmentNoComments)
|
||||
TEST(StatementBoundary, IndentedAssignmentNoComments)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
# begin followed by double newlines
|
||||
|
||||
|
||||
@@ -896,7 +897,7 @@ TEST(TOMLLexerStatementBoundaryTests, IndentedAssignmentNoComments)
|
||||
# before
|
||||
# more before
|
||||
token_o = 123.456
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -913,15 +914,15 @@ TEST(TOMLLexerStatementBoundaryTests, IndentedAssignmentNoComments)
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, IndentedAssignmentWithCommentsBefore)
|
||||
TEST(StatementBoundary, IndentedAssignmentWithCommentsBefore)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
|
||||
# before
|
||||
# more before
|
||||
token_o = 123.456
|
||||
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -944,15 +945,15 @@ TEST(TOMLLexerStatementBoundaryTests, IndentedAssignmentWithCommentsBefore)
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, IndentedBooleanArrayAssignmentWithDedicatedComments)
|
||||
TEST(StatementBoundary, IndentedBooleanArrayAssignmentWithDedicatedComments)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
|
||||
token_p = [true, false] # after
|
||||
# more after
|
||||
# belonging to next
|
||||
token_q = "next"
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -978,15 +979,15 @@ TEST(TOMLLexerStatementBoundaryTests, IndentedBooleanArrayAssignmentWithDedicate
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, IndentedAssignmentWithDedicatedCommentsBefore)
|
||||
TEST(StatementBoundary, IndentedAssignmentWithDedicatedCommentsBefore)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_p = [true, false] # after
|
||||
# more after
|
||||
# belonging to next
|
||||
token_q = "next"
|
||||
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -1006,14 +1007,14 @@ TEST(TOMLLexerStatementBoundaryTests, IndentedAssignmentWithDedicatedCommentsBef
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, IndentedAssignmentFollowedByCommentWithoutSpace)
|
||||
TEST(StatementBoundary, IndentedAssignmentFollowedByCommentWithoutSpace)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
token_r =987#after without whitespace
|
||||
# more after due to following empty line
|
||||
|
||||
[token_s]
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -1033,13 +1034,13 @@ TEST(TOMLLexerStatementBoundaryTests, IndentedAssignmentFollowedByCommentWithout
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, IndentedTableWithoutComments)
|
||||
TEST(StatementBoundary, IndentedTableWithoutComments)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
[token_s]
|
||||
# not after
|
||||
[token_t]
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -1053,16 +1054,16 @@ TEST(TOMLLexerStatementBoundaryTests, IndentedTableWithoutComments)
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, IndentedTableWithAndWithoutComments)
|
||||
TEST(StatementBoundary, IndentedTableWithAndWithoutComments)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
[token_s]
|
||||
# not after
|
||||
[token_t]
|
||||
|
||||
# comment before a table member (belongs to token_bb)
|
||||
token_u.token_aa.token_bb = 10 # table token_u has a table token_aa which has a value token_bb
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -1080,12 +1081,12 @@ token_u.token_aa.token_bb = 10 # table token_u has a table token_aa which ha
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, InlineTableWithParentChildAssignment)
|
||||
TEST(StatementBoundary, InlineTableWithParentChildAssignment)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
# comment before a table member (belongs to token_bb)
|
||||
token_u.token_aa.token_bb = 10 # table token_u has a table token_aa which has a value token_bb
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -1116,9 +1117,9 @@ token_u.token_aa.token_bb = 10 # table token_u has a table token_aa which ha
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, ComplexInlineTableWithParentChildAssignmentOfTablesAndMultiDimensionalArrays)
|
||||
TEST(StatementBoundary, ComplexInlineTableWithParentChildAssignmentOfTablesAndMultiDimensionalArrays)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
# Super inline table with sub-tables and arrays
|
||||
token_u.token_aa.token_cc = { dd = { ee = 10, ff = 11 }, # this is the comment for dd
|
||||
gg = [{hh = 1, ii = 2},
|
||||
@@ -1128,7 +1129,7 @@ token_u.token_aa.token_cc = { dd = { ee = 10, ff = 11 }, # this is the commen
|
||||
# and this as well
|
||||
jj = [["abc", "def"], [1, 2, 3], []]}
|
||||
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// NOTE EVE 22.10.2025: the value token_u.token_aa.token_cc.jj is the last value in the table. This means that the scope of
|
||||
// the value included the comma before the value jj (following value gg). This has the consequence, that the comments, which
|
||||
@@ -1292,9 +1293,9 @@ token_u.token_aa.token_cc = { dd = { ee = 10, ff = 11 }, # this is the commen
|
||||
toml_parser::ETokenCategory::token_syntax_array_close}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, ArrayOfTables)
|
||||
TEST(StatementBoundary, ArrayOfTables)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
[[token_v]]
|
||||
token_kk = 10
|
||||
token_ll = 20
|
||||
@@ -1303,7 +1304,7 @@ token_mm = 30
|
||||
[[token_v]]
|
||||
token_kk = 110
|
||||
token_ll = 120
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
@@ -1316,15 +1317,15 @@ token_ll = 120
|
||||
toml_parser::ETokenCategory::token_syntax_new_line}));
|
||||
}
|
||||
|
||||
TEST(TOMLLexerStatementBoundaryTests, ParentChildTable)
|
||||
TEST(StatementBoundary, ParentChildTable)
|
||||
{
|
||||
std::string ssCode = R"code(
|
||||
std::string ssCode = R"toml(
|
||||
[[token_v]]
|
||||
token_kk = 110
|
||||
token_ll = 120
|
||||
# Comments before (belongs ot child only)
|
||||
[token_x.token_nn] # Comments following (belongs to child only)
|
||||
)code";
|
||||
)toml";
|
||||
|
||||
// Process the code
|
||||
toml_parser::CLexer lexerCode(ssCode);
|
||||
|
||||
Reference in New Issue
Block a user