mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-07-02 05:35:11 +00:00
update parser (#5)
This commit is contained in:
@@ -4,7 +4,10 @@ add_executable(UnitTest_TOMLParser
|
||||
"lexer_tests.cpp"
|
||||
"parser_tests.cpp"
|
||||
"main.cpp"
|
||||
"generate_toml_tests.cpp")
|
||||
"generate_toml_tests.cpp"
|
||||
"content_modifications.cpp"
|
||||
"statement_boundary_detection.cpp"
|
||||
"miscellaneous_tests.cpp")
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
target_link_libraries(UnitTest_TOMLParser GTest::GTest ${CMAKE_THREAD_LIBS_INIT})
|
||||
if (WIN32)
|
||||
|
||||
@@ -183,46 +183,108 @@ TEST(UTF8_CharacterReader, InputValidation)
|
||||
for (const auto& inv : GetInvalidUTF8Bytes())
|
||||
{
|
||||
std::string ssUTF8InputInvalid = "Invalid input: " + inv + " test";
|
||||
EXPECT_THROW(CCharacterReaderUTF8 reader(ssUTF8InputInvalid), sdv::toml::XTOMLParseException);
|
||||
EXPECT_THROW(toml_parser::CCharacterReaderUTF8 reader(ssUTF8InputInvalid), sdv::toml::XTOMLParseException);
|
||||
}
|
||||
// Test for a variety of invalid sequences
|
||||
for (const auto& inv : GetInvalidUTF8Sequences())
|
||||
{
|
||||
std::string UTF8InputInvalid = "Invalid input: " + inv + "test";
|
||||
EXPECT_THROW(CCharacterReaderUTF8 reader(UTF8InputInvalid), sdv::toml::XTOMLParseException);
|
||||
EXPECT_THROW(toml_parser::CCharacterReaderUTF8 reader(UTF8InputInvalid), sdv::toml::XTOMLParseException);
|
||||
}
|
||||
// Test for a sample of ASCII, 2-Byte-, 3-Byte- and 4-Byte-Sequences that they will be accepted as valid input
|
||||
EXPECT_NO_THROW(CCharacterReaderUTF8 reader(UTF8InputValid));
|
||||
EXPECT_NO_THROW(toml_parser::CCharacterReaderUTF8 reader(UTF8InputValid));
|
||||
|
||||
EXPECT_NO_THROW(CCharacterReaderUTF8 reader(TestInputUTF8));
|
||||
EXPECT_NO_THROW(toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8));
|
||||
}
|
||||
|
||||
TEST(UTF8_CharacterReader, PeekAndConsume_ReadCharacters)
|
||||
{
|
||||
// Peek() and Consume() read the next character
|
||||
// Peek() and Consume() read the next character
|
||||
{
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i], reader.Peek());
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i], reader.Consume());
|
||||
}
|
||||
}
|
||||
|
||||
// Read all characters and the an empty string must be read
|
||||
{
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
std::size_t nSize = TestInputUTF8.size();
|
||||
size_t nCnt = 0;
|
||||
while (nCnt < nSize)
|
||||
{
|
||||
EXPECT_FALSE(reader.Peek().empty());
|
||||
std::string ssCharacters = reader.Consume();
|
||||
size_t nCharCnt = ssCharacters.size();
|
||||
EXPECT_NE(nCharCnt, 0);
|
||||
if (!nCharCnt) break;
|
||||
nCnt += nCharCnt;
|
||||
}
|
||||
EXPECT_EQ(nCnt, nSize);
|
||||
EXPECT_TRUE(reader.Peek().empty());
|
||||
EXPECT_TRUE(reader.Consume().empty());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UTF8_CharacterReader, PeekAndConsume_ReadCharactersSkip)
|
||||
{
|
||||
// Peek(n) and Consume(n) read with skip of every two characters
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
for (int i = 0; i < 12; ++i)
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
for (int i = 1; i < 12; i += 2)
|
||||
{
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i], reader.Peek());
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i], reader.Consume());
|
||||
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i], reader.Peek(1));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i], reader.Consume(1));
|
||||
}
|
||||
}
|
||||
// Peek(n) and Consume(n) read the next n-th character
|
||||
{
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i], reader.Peek(i + 1));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i], reader.Consume(i + 1));
|
||||
}
|
||||
}
|
||||
// PeekUntil(a) and ConsumeUntil(a) read until a given character
|
||||
|
||||
// Peek(0)/Consume(0) will return the first character in the string and Peek(n)/Consume(n) return empty string if they read out
|
||||
// of bounds
|
||||
{
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0], reader.Peek(0));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0], reader.Consume(0));
|
||||
std::size_t biggerIndex = TestInputUTF8.size(); // Assure this is bigger than the number of characters in TestInputUTF8
|
||||
EXPECT_EQ("", reader.Peek(biggerIndex));
|
||||
EXPECT_EQ("", reader.Consume(biggerIndex));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UTF8_CharacterReader, PeekAndConsume_ReadCharactersMulti)
|
||||
{
|
||||
// Peek() and Consume() read the next character
|
||||
{
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
for (int i = 0; i < 12; i += 2)
|
||||
{
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i] + TestInputUTF8_CharacterIndexMap[i + 1], reader.Peek(0, 2));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i] + TestInputUTF8_CharacterIndexMap[i + 1], reader.Consume(0, 2));
|
||||
}
|
||||
}
|
||||
|
||||
// Peek() and Consume() skip one and then read two read the next character
|
||||
{
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
for (int i = 0; i < 12; i += 3)
|
||||
{
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i + 1] + TestInputUTF8_CharacterIndexMap[i + 2], reader.Peek(1, 2));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[i + 1] + TestInputUTF8_CharacterIndexMap[i + 2], reader.Consume(1, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UTF8_CharacterReader, PeekAndConsume_ReadCharactersUntil)
|
||||
{
|
||||
// PeekUntil(a) and ConsumeUntil(a) read until a given character
|
||||
{
|
||||
std::size_t byteIndex = 0;
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
std::vector<std::string> Codepoints;
|
||||
Codepoints.push_back(TestInputUTF8_CharacterIndexMap[i]);
|
||||
std::string wantedSubstring = TestInputUTF8.substr(0, byteIndex);
|
||||
@@ -233,28 +295,19 @@ TEST(UTF8_CharacterReader, PeekAndConsume_ReadCharacters)
|
||||
}
|
||||
// PeekUntil(a) and ConsumeUntil(a) read only until EOF if they don't find a matching character
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
std::string notInTestString = "g";
|
||||
EXPECT_EQ(std::string::npos, TestInputUTF8.find(notInTestString));
|
||||
EXPECT_EQ(TestInputUTF8, reader.PeekUntil({notInTestString}));
|
||||
EXPECT_EQ(TestInputUTF8, reader.ConsumeUntil({notInTestString}));
|
||||
}
|
||||
// Peek(0)/Peek(n) and Consume(0)/Consume(n) return empty string if they would read out of bounds
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_EQ("", reader.Peek(0));
|
||||
EXPECT_EQ("", reader.Consume(0));
|
||||
std::size_t biggerIndex = TestInputUTF8.size(); // Assure this is bigger than the number of characters in TestInputUTF8
|
||||
EXPECT_EQ("", reader.Peek(biggerIndex));
|
||||
EXPECT_EQ("", reader.Consume(biggerIndex));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(UTF8_CharacterReader, Peek_NoAdvance)
|
||||
{
|
||||
ASSERT_NE(TestInputUTF8_CharacterIndexMap[0], TestInputUTF8_CharacterIndexMap[1]);
|
||||
ASSERT_NE(TestInputUTF8_CharacterIndexMap[1], TestInputUTF8_CharacterIndexMap[2]);
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
// Peek() does not advance the read location
|
||||
{
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0], reader.Peek());
|
||||
@@ -263,10 +316,10 @@ TEST(UTF8_CharacterReader, Peek_NoAdvance)
|
||||
}
|
||||
// Peek(n) does not advance the read location
|
||||
{
|
||||
EXPECT_EQ("", reader.Peek(0));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0], reader.Peek(1));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[1], reader.Peek(2));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[2], reader.Peek(3));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0], reader.Peek(0)); // Read pos 0
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[1], reader.Peek(1)); // Read pos 1
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[2], reader.Peek(2)); // Read pos 2
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[3], reader.Peek(3)); // Read pos 3
|
||||
}
|
||||
// PeekUntil(a) does not advance the read location
|
||||
{
|
||||
@@ -286,22 +339,22 @@ TEST(UTF8_CharacterReader, Consume_Advance)
|
||||
ASSERT_NE(TestInputUTF8_CharacterIndexMap[3], TestInputUTF8_CharacterIndexMap[4]);
|
||||
// Consume() does advance the read location to the next character
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0], reader.Consume());
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[1], reader.Consume());
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[2], reader.Consume());
|
||||
}
|
||||
// Consume(n) does advance the read location to the next n-th character
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_EQ("", reader.Consume(0));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0], reader.Consume(1));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[2], reader.Consume(2));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[5], reader.Consume(3));
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0], reader.Consume(0)); // Read pos 0; advance to pos 1
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[2], reader.Consume(1)); // Read pos 2; advance to pos 3
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[5], reader.Consume(2)); // Read pos 5; advance to pos 6
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[9], reader.Consume(3)); // Read pos 9; advance to pos 10
|
||||
}
|
||||
// ConsumeUntil(a) does advance the read location
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0], reader.ConsumeUntil({TestInputUTF8_CharacterIndexMap[1]}));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[1], reader.ConsumeUntil({TestInputUTF8_CharacterIndexMap[2]}));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[2], reader.ConsumeUntil({TestInputUTF8_CharacterIndexMap[3]}));
|
||||
@@ -312,7 +365,7 @@ TEST(UTF8_CharacterReader, PeekUntilConsumeUntil_FindAny)
|
||||
{
|
||||
// PeekUntil(a) works for a collection of characters
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0],
|
||||
reader.PeekUntil({TestInputUTF8_CharacterIndexMap[2], TestInputUTF8_CharacterIndexMap[1]}));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0] + TestInputUTF8_CharacterIndexMap[1] + TestInputUTF8_CharacterIndexMap[2],
|
||||
@@ -320,7 +373,7 @@ TEST(UTF8_CharacterReader, PeekUntilConsumeUntil_FindAny)
|
||||
}
|
||||
// ConsumeUntil(a) works for a collection of characters
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[0],
|
||||
reader.ConsumeUntil({TestInputUTF8_CharacterIndexMap[2], TestInputUTF8_CharacterIndexMap[1]}));
|
||||
EXPECT_EQ(TestInputUTF8_CharacterIndexMap[1] + TestInputUTF8_CharacterIndexMap[2],
|
||||
@@ -331,7 +384,7 @@ TEST(UTF8_CharacterReader, PeekUntilConsumeUntil_FindAny)
|
||||
TEST(UTF8_CharacterReader, PeekAndConsume_SameOutput)
|
||||
{
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
for (int i = 0; i < 12; ++i)
|
||||
{
|
||||
std::string p = reader.Peek();
|
||||
@@ -342,7 +395,7 @@ TEST(UTF8_CharacterReader, PeekAndConsume_SameOutput)
|
||||
{
|
||||
for (int i = 1; i < 13; ++i)
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
std::string p = reader.Peek(i);
|
||||
std::string c = reader.Consume(i);
|
||||
EXPECT_EQ(p, c);
|
||||
@@ -351,7 +404,7 @@ TEST(UTF8_CharacterReader, PeekAndConsume_SameOutput)
|
||||
{
|
||||
for (int i = 1; i < 13; ++i)
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
std::vector<std::string> CodePoints;
|
||||
CodePoints.push_back(reader.Peek(i));
|
||||
std::string p = reader.PeekUntil(CodePoints);
|
||||
@@ -365,7 +418,7 @@ TEST(UTF8_CharacterReader, EOFTests)
|
||||
{
|
||||
// Check all calls that are not to trigger EOF
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_FALSE(reader.IsEOF());
|
||||
reader.Peek();
|
||||
reader.Peek(1);
|
||||
@@ -379,20 +432,20 @@ TEST(UTF8_CharacterReader, EOFTests)
|
||||
}
|
||||
// Check that reading the last character with Consume(n) triggers EOF
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_FALSE(reader.IsEOF());
|
||||
reader.Consume(TestInputUTF8_CharacterIndexMap.size()); // Last Character
|
||||
EXPECT_TRUE(reader.IsEOF());
|
||||
}
|
||||
// Check that reading out of bounds with Consume(n) triggers EOF
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_FALSE(reader.IsEOF());
|
||||
reader.Consume(TestInputUTF8_CharacterIndexMap.size() + 1); // Out of bounds
|
||||
EXPECT_TRUE(reader.IsEOF());
|
||||
}
|
||||
{
|
||||
CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
toml_parser::CCharacterReaderUTF8 reader(TestInputUTF8);
|
||||
EXPECT_FALSE(reader.IsEOF());
|
||||
reader.ConsumeUntil({TestInputUTF8_CharacterIndexMap[11]}); // Second last character
|
||||
EXPECT_FALSE(reader.IsEOF());
|
||||
@@ -400,7 +453,7 @@ TEST(UTF8_CharacterReader, EOFTests)
|
||||
EXPECT_TRUE(reader.IsEOF());
|
||||
}
|
||||
{
|
||||
CCharacterReaderUTF8 reader("");
|
||||
toml_parser::CCharacterReaderUTF8 reader("");
|
||||
EXPECT_TRUE(reader.IsEOF());
|
||||
}
|
||||
}
|
||||
|
||||
449
tests/unit_tests/toml_parser/content_modifications.cpp
Normal file
449
tests/unit_tests/toml_parser/content_modifications.cpp
Normal file
@@ -0,0 +1,449 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
|
||||
// Delete nodes (for all types of nodes, between all types of nodes)
|
||||
// - beginning
|
||||
// - middle
|
||||
// - end
|
||||
// - Using deleted node info -- error
|
||||
// - Last node (empty after that)
|
||||
// - Smart delete (comments/whitespace around)
|
||||
|
||||
// Insert nodes (for all types of nodes, between all types of nodes)
|
||||
// Before and after:
|
||||
// - beginning
|
||||
// - middle
|
||||
// - end
|
||||
// - Being the first item in a TOML file
|
||||
// - 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)
|
||||
|
||||
// Shift nodes (for all types of nodes, between root, tables and arrays)
|
||||
|
||||
/*
|
||||
* @brief Delete a key from the TOML string.
|
||||
* @param[in] rssTOMLInput Reference to the TOML string.
|
||||
* @param[in] rssKey Reference to the key to delete.
|
||||
* @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)
|
||||
{
|
||||
toml_parser::CParser parser;
|
||||
bool bRes = true;
|
||||
EXPECT_NO_THROW(bRes = parser.Process(rssTOMLInput));
|
||||
EXPECT_TRUE(bRes);
|
||||
if (!bRes) return bRes;
|
||||
auto ptrNode = parser.Root().Direct(rssKey);
|
||||
EXPECT_TRUE(ptrNode);
|
||||
if (!ptrNode) return false;
|
||||
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;
|
||||
};
|
||||
|
||||
TEST(TOMLContentModifications, DISABLED_DeleteValues)
|
||||
{
|
||||
// Delete a key from the begin
|
||||
EXPECT_TRUE(TestDelete(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
|
||||
bare-key = false # value bare-key
|
||||
)toml"));
|
||||
|
||||
// Delete a key from the middle
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
key = 10 # value key
|
||||
bare_key = "value" # value bare_key
|
||||
bare-key = false # value bare-key
|
||||
)toml",
|
||||
"bare_key",
|
||||
R"toml(
|
||||
key = 10 # value key
|
||||
bare-key = false # value bare-key
|
||||
)toml"));
|
||||
|
||||
// Delete a key from the end
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
key = 10 # value key
|
||||
bare_key = "value" # value bare_key
|
||||
bare-key = false # value bare-key
|
||||
)toml",
|
||||
"bare-key",
|
||||
R"toml(
|
||||
key = 10 # value key
|
||||
bare_key = "value" # value bare_key
|
||||
)toml"));
|
||||
}
|
||||
|
||||
TEST(TOMLContentModifications, DISABLED_DeleteInlineTableValues)
|
||||
{
|
||||
// Delete key from the inline table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"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(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"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(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"1234.str",
|
||||
R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2}
|
||||
)toml"));
|
||||
|
||||
// Delete key from the inline sub-table
|
||||
EXPECT_TRUE(TestDelete(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",
|
||||
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"));
|
||||
|
||||
// Delete table
|
||||
EXPECT_TRUE(TestDelete(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",
|
||||
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(
|
||||
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",
|
||||
R"toml(
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml"));
|
||||
}
|
||||
|
||||
TEST(TOMLContentModifications, DISABLED_DeleteTableValues)
|
||||
{
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml",
|
||||
"my_table.key",
|
||||
R"toml(
|
||||
[my_table]
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml"));
|
||||
|
||||
// Delete a key from the middle
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml",
|
||||
"my_table.bare_key",
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare-key = false
|
||||
)toml"));
|
||||
|
||||
// Delete a key from the end
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml",
|
||||
"my_table.bare-key",
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
)toml"));
|
||||
|
||||
// Delete key from the inline table in a table
|
||||
EXPECT_TRUE(TestDelete(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",
|
||||
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(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"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(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2, str = "abc"}
|
||||
)toml",
|
||||
"my_table.1234.str",
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
1234 = {x = 0, y = 1, z = 2}
|
||||
)toml"));
|
||||
|
||||
// Delete key from the inline sub-table
|
||||
EXPECT_TRUE(TestDelete(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",
|
||||
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"));
|
||||
|
||||
// Delete table
|
||||
EXPECT_TRUE(TestDelete(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",
|
||||
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(
|
||||
[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",
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml"));
|
||||
|
||||
// Delete key from the child-table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
[my_table.1234]
|
||||
x = 0
|
||||
y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml",
|
||||
"my_table.1234.y",
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
[my_table.1234]
|
||||
x = 0
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
[my_table.1234]
|
||||
x = 0
|
||||
y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml",
|
||||
"my_table.1234.x",
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
[my_table.1234]
|
||||
y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
[my_table.1234]
|
||||
x = 0
|
||||
y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml",
|
||||
"my_table.1234.str",
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
[my_table.1234]
|
||||
x = 0
|
||||
y = 1
|
||||
z = 2
|
||||
)toml"));
|
||||
|
||||
// Delete table
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
[my_table.1234]
|
||||
x = 0
|
||||
y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
[my_table.1234.tbl]
|
||||
a =1
|
||||
b=2
|
||||
c=3
|
||||
)toml",
|
||||
"my_table.1234.tbl",
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
[my_table.1234]
|
||||
x = 0
|
||||
y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
)toml"));
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
[my_table.1234]
|
||||
x = 0
|
||||
y = 1
|
||||
z = 2
|
||||
str = "abc"
|
||||
[my_table.1234.tbl]
|
||||
a =1
|
||||
b=2
|
||||
c=3
|
||||
)toml",
|
||||
"my_table.1234",
|
||||
R"toml(
|
||||
[my_table]
|
||||
key = 10
|
||||
bare_key = "value"
|
||||
bare-key = false
|
||||
)toml"));
|
||||
}
|
||||
|
||||
TEST(TOMLContentModifications, DISABLED_DeleteArrayValues)
|
||||
{
|
||||
EXPECT_TRUE(TestDelete(R"toml(
|
||||
key = [10, 20, 30]
|
||||
bare_key = ["value1", "value2", 3030]
|
||||
bare-key = [{a = false, b = true}, 2020]
|
||||
)toml",
|
||||
"key[1]",
|
||||
R"toml(
|
||||
key = [10, 30]
|
||||
bare_key = ["value1", "value2", 3030]
|
||||
bare-key = [{a = false, b = true}, 2020]
|
||||
)toml"));
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,10 @@
|
||||
#include "../../../global/process_watchdog.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"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.cpp"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.cpp"
|
||||
#include "../../../sdv_services/core/toml_parser/miscellaneous.cpp"
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
extern "C" int wmain(int argc, wchar_t* argv[])
|
||||
|
||||
981
tests/unit_tests/toml_parser/miscellaneous_tests.cpp
Normal file
981
tests/unit_tests/toml_parser/miscellaneous_tests.cpp
Normal file
@@ -0,0 +1,981 @@
|
||||
#include <functional>
|
||||
#include <gtest/gtest.h>
|
||||
#include <limits>
|
||||
|
||||
#include "../../../sdv_services/core/toml_parser/exception.h"
|
||||
#include "../../../sdv_services/core/toml_parser/miscellaneous.h"
|
||||
|
||||
TEST(TOMLMiscellaneousTests, Hex2Dec)
|
||||
{
|
||||
// No string
|
||||
std::string ssEmpty;
|
||||
EXPECT_THROW(toml_parser::HexadecimalToDecimal(ssEmpty), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Invalid string
|
||||
std::string ssNoNumber = "xyz";
|
||||
EXPECT_THROW(toml_parser::HexadecimalToDecimal(ssNoNumber), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Parse value
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("10"), 16u);
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("a"), 10u);
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("AbCd1234"), 2882343476u);
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("0"), 0u);
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("7fffffff"), 2147483647u);
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("80000000"), 2147483648u);
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("FFFFFFFF"), 4294967295u);
|
||||
|
||||
// Parse up to max value
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("0FFFFFFFF"), 4294967295u);
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("FFFFFFFFA"), 4294967295u);
|
||||
|
||||
// Parse until unknown character
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("0xyz"), 0u);
|
||||
EXPECT_EQ(toml_parser::HexadecimalToDecimal("10xyz"), 16u);
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, Dec2Dec)
|
||||
{
|
||||
// No string
|
||||
std::string ssEmpty;
|
||||
EXPECT_THROW(toml_parser::DecimalToDecimal(ssEmpty), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Invalid string
|
||||
std::string ssNoNumber = "f123";
|
||||
EXPECT_THROW(toml_parser::DecimalToDecimal(ssNoNumber), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Parse value
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("16"), 16u);
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("10"), 10u);
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("2882343476"), 2882343476u);
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("0"), 0u);
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("2147483647"), 2147483647u);
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("2147483648"), 2147483648u);
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("4294967295"), 4294967295u);
|
||||
|
||||
// Parse up to max value
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("04294967295"), 4294967295u);
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("42949672950"), 4294967295u);
|
||||
|
||||
// Parse until unknown character
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("0xyz"), 0u);
|
||||
EXPECT_EQ(toml_parser::DecimalToDecimal("10xyz"), 10u);
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, Oct2Dec)
|
||||
{
|
||||
// No string
|
||||
std::string ssEmpty;
|
||||
EXPECT_THROW(toml_parser::OctalToDecimal(ssEmpty), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Invalid string
|
||||
std::string ssNoNumber = "890";
|
||||
EXPECT_THROW(toml_parser::OctalToDecimal(ssNoNumber), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Parse value
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("20"), 16u);
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("12"), 10u);
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("25363211064"), 2882343476u);
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("0"), 0u);
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("17777777777"), 2147483647u);
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("20000000000"), 2147483648u);
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("37777777777"), 4294967295u);
|
||||
|
||||
// Parse up to max value
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("037777777777"), 4294967295u);
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("377777777770"), 4294967295u);
|
||||
|
||||
// Parse until unknown character
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("0xyz"), 0u);
|
||||
EXPECT_EQ(toml_parser::OctalToDecimal("12xyz"), 10u);
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, Bin2Dec)
|
||||
{
|
||||
// No string
|
||||
std::string ssEmpty;
|
||||
EXPECT_THROW(toml_parser::BinaryToDecimal(ssEmpty), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Invalid string
|
||||
std::string ssNoNumber = "234";
|
||||
EXPECT_THROW(toml_parser::BinaryToDecimal(ssNoNumber), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Parse value
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("10000"), 16u);
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("1010"), 10u);
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("10101011110011010001001000110100"), 2882343476u);
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("0"), 0u);
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("1111111111111111111111111111111"), 2147483647u);
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("10000000000000000000000000000000"), 2147483648u);
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("11111111111111111111111111111111"), 4294967295u);
|
||||
|
||||
// Parse up to max value
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("011111111111111111111111111111111"), 4294967295u);
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("111111111111111111111111111111110"), 4294967295u);
|
||||
|
||||
// Parse until unknown character
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("0xyz"), 0u);
|
||||
EXPECT_EQ(toml_parser::BinaryToDecimal("1010yz"), 10u);
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, UnicodeCharacter)
|
||||
{
|
||||
// No string
|
||||
std::string ssEmpty;
|
||||
EXPECT_THROW(toml_parser::EscapedUnicodeCharacterToUTF8(ssEmpty), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Invalid string
|
||||
std::string ssNoNumber = "xyz";
|
||||
EXPECT_THROW(toml_parser::EscapedUnicodeCharacterToUTF8(ssNoNumber), sdv::toml::XTOMLParseException);
|
||||
|
||||
// Conversion
|
||||
EXPECT_EQ(toml_parser::EscapedUnicodeCharacterToUTF8("042f"), u8"\u042f");
|
||||
EXPECT_EQ(toml_parser::EscapedUnicodeCharacterToUTF8("0000042f"), u8"\U0000042f");
|
||||
EXPECT_EQ(toml_parser::EscapedUnicodeCharacterToUTF8("0001F600"), u8"\U0001F600");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitKeyStringEmpty)
|
||||
{
|
||||
std::string ssKeyEmpty;
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKeyEmpty);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitKeyFirstPartOnly)
|
||||
{
|
||||
std::string ssKey = "abc";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "_abc";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "_abc");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "-abc";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "-abc");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "1234";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "1234");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Although invalid bare key
|
||||
ssKey = "abc/";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Invalid bare key
|
||||
ssKey = "abc\\";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Invalid bare key
|
||||
ssKey = "abc def";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitStandardBareKey)
|
||||
{
|
||||
std::string ssKey = "abc.def";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "def");
|
||||
|
||||
ssKey = "_abc._def";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "_abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "_def");
|
||||
|
||||
ssKey = "-abc.-def";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "-abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "-def");
|
||||
|
||||
ssKey = "1234.5678";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "1234");
|
||||
EXPECT_EQ(prSplittedKey.second, "5678");
|
||||
|
||||
ssKey = "1234.5678.90";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "1234");
|
||||
EXPECT_EQ(prSplittedKey.second, "5678.90");
|
||||
|
||||
// Invalid bare key
|
||||
ssKey = "/abc./def";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Invalid bare key
|
||||
ssKey = "\\abc.\\def";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitBareKeyWithSpace)
|
||||
{
|
||||
std::string ssKey = " abc.def";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "def");
|
||||
|
||||
ssKey = "abc . def";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, " def");
|
||||
|
||||
ssKey = "\tabc.\tdef";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "\tdef");
|
||||
|
||||
ssKey = "abc\n.\ndef";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "\ndef");
|
||||
|
||||
// Invalid key
|
||||
ssKey = "abc def . ghi jkl";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitLiteralKey)
|
||||
{
|
||||
std::string ssKey = "'abc'";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "'abc.def'";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc.def");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "'abc'.'def'";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "'def'");
|
||||
|
||||
ssKey = "'\"cool\" key'.'very \"cool\" key'";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "\"cool\" key");
|
||||
EXPECT_EQ(prSplittedKey.second, "'very \"cool\" key'");
|
||||
|
||||
ssKey = "'abc/def'";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc/def");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "'abc\\ndef'";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc\\ndef");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Invalid key
|
||||
ssKey = "'abc.def";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "cool' 'key";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitQuotedKey)
|
||||
{
|
||||
std::string ssKey = "\"abc\"";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc.def\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc.def");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc\".\"def\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "\"def\"");
|
||||
|
||||
ssKey = "\"'cool' key\".\"very 'cool' key\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "'cool' key");
|
||||
EXPECT_EQ(prSplittedKey.second, "\"very 'cool' key\"");
|
||||
|
||||
ssKey = "\"abc/def\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc/def");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Invalid key
|
||||
ssKey = "\"abc.def";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "cool\" \"key";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitEscapedQuotedKey)
|
||||
{
|
||||
std::string ssKey = "\"abc\\bdef\"";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc\bdef");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc\\tdef\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc\tdef");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc\\ndef\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc\ndef");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc\\fdef\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc\fdef");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc\\rdef\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc\rdef");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc\\\"def\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc\"def");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc\\\\def\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc\\def");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc\\u042fdef\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, u8"abc\u042fdef");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc\\U0000042fdef\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, u8"abc\U0000042fdef");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "\"abc\\U0001F600def\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, u8"abc\U0001F600def");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Invalid key
|
||||
ssKey = "\"abc\\uxyz\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Invalid key
|
||||
ssKey = "\"abc\\Uxyz\"";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitTableKey)
|
||||
{
|
||||
std::string ssKey = "abc.def";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "def");
|
||||
|
||||
ssKey = "abc.def.ghi";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "def.ghi");
|
||||
|
||||
ssKey = ".abc.def.ghi";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "def.ghi");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, SplitArrayKey)
|
||||
{
|
||||
std::string ssKey = "abc[1]";
|
||||
auto prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "[1]");
|
||||
|
||||
ssKey = "abc[1][2]";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "[1][2]");
|
||||
|
||||
ssKey = "[1]";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "1");
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
ssKey = "[1][2]";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "1");
|
||||
EXPECT_EQ(prSplittedKey.second, "[2]");
|
||||
|
||||
ssKey = "[1].abc";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "1");
|
||||
EXPECT_EQ(prSplittedKey.second, "abc");
|
||||
|
||||
ssKey = ".[1].abc";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "1");
|
||||
EXPECT_EQ(prSplittedKey.second, "abc");
|
||||
|
||||
ssKey = "abc [ 1 ] [ 2 ] [ 3 ] . def";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_EQ(prSplittedKey.first, "abc");
|
||||
EXPECT_EQ(prSplittedKey.second, "[ 1 ] [ 2 ] [ 3 ] . def");
|
||||
|
||||
// Invalid key
|
||||
ssKey = "[1]abc";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Invalid key
|
||||
ssKey = "[1.2][2]";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Invalid key
|
||||
ssKey = "[1";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
|
||||
// Invalid key
|
||||
ssKey = "[1[2]]";
|
||||
prSplittedKey = toml_parser::SplitNodeKey(ssKey);
|
||||
EXPECT_TRUE(prSplittedKey.first.empty());
|
||||
EXPECT_TRUE(prSplittedKey.second.empty());
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC", toml_parser::EQuoteRequest::smart_key), "ABC");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc_def", toml_parser::EQuoteRequest::smart_key), "abc_def");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::smart_key), "ABC-DEF");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText(".abc", toml_parser::EQuoteRequest::smart_key), "\".abc\"");
|
||||
#ifndef __GNUC__
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"<EFBFBD>", toml_parser::EQuoteRequest::smart_key),
|
||||
"\"\\u00B5\""); // Only supported on Windows with MS compiler
|
||||
#endif
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"\u00a1", toml_parser::EQuoteRequest::smart_key), "\"\\u00A1\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::smart_key), "\"abc/\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\"abc\"", toml_parser::EQuoteRequest::smart_key), "\"\\\"abc\\\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("'abc'", toml_parser::EQuoteRequest::smart_key), "\"'abc'\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\bdef", toml_parser::EQuoteRequest::smart_key), "\"abc\\bdef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\ndef", toml_parser::EQuoteRequest::smart_key), "\"abc\\ndef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\fdef", toml_parser::EQuoteRequest::smart_key), "\"abc\\fdef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::smart_key), "\"abc\\rdef\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0002", toml_parser::EQuoteRequest::smart_key), "\"\\u0002\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0003", toml_parser::EQuoteRequest::smart_key), "\"\\u0003\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0004", toml_parser::EQuoteRequest::smart_key), "\"\\u0004\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0005", toml_parser::EQuoteRequest::smart_key), "\"\\u0005\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0006", toml_parser::EQuoteRequest::smart_key), "\"\\u0006\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0007", toml_parser::EQuoteRequest::smart_key), "\"\\u0007\"");
|
||||
// 0008 = backspace (\b), 0009 = tab (\t), 000a = linefeed (\n)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000b", toml_parser::EQuoteRequest::smart_key), "\"\\u000B\"");
|
||||
// 000c = form feed (\f), 000d = carriage return (\r)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000e", toml_parser::EQuoteRequest::smart_key), "\"\\u000E\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000f", toml_parser::EQuoteRequest::smart_key), "\"\\u000F\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0010", toml_parser::EQuoteRequest::smart_key), "\"\\u0010\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0011", toml_parser::EQuoteRequest::smart_key), "\"\\u0011\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0012", toml_parser::EQuoteRequest::smart_key), "\"\\u0012\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0013", toml_parser::EQuoteRequest::smart_key), "\"\\u0013\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0014", toml_parser::EQuoteRequest::smart_key), "\"\\u0014\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0015", toml_parser::EQuoteRequest::smart_key), "\"\\u0015\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0016", toml_parser::EQuoteRequest::smart_key), "\"\\u0016\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0017", toml_parser::EQuoteRequest::smart_key), "\"\\u0017\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0018", toml_parser::EQuoteRequest::smart_key), "\"\\u0018\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0019", toml_parser::EQuoteRequest::smart_key), "\"\\u0019\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001a", toml_parser::EQuoteRequest::smart_key), "\"\\u001A\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001b", toml_parser::EQuoteRequest::smart_key), "\"\\u001B\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001c", toml_parser::EQuoteRequest::smart_key), "\"\\u001C\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001d", toml_parser::EQuoteRequest::smart_key), "\"\\u001D\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001e", toml_parser::EQuoteRequest::smart_key), "\"\\u001E\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001f", toml_parser::EQuoteRequest::smart_key), "\"\\u001F\"");
|
||||
// 0020..0021 are treated as characters (partly quotation needed)
|
||||
// 0022 = quote (\")
|
||||
// 0023..005b are treated as characters (partly quotation needed)
|
||||
// 005c = backslash (\\)
|
||||
// 005d..007e are treated as characters (partly quotation needed)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u007f", toml_parser::EQuoteRequest::smart_key), "\"\\u007F\"");
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC", toml_parser::EQuoteRequest::smart_text), "\"ABC\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc_def", toml_parser::EQuoteRequest::smart_text), "\"abc_def\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::smart_text), "\"ABC-DEF\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText(".abc", toml_parser::EQuoteRequest::smart_text), "\".abc\"");
|
||||
#ifndef __GNUC__
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"<EFBFBD>", toml_parser::EQuoteRequest::smart_text),
|
||||
"\"\\u00B5\""); // Only supported on Windows with MS compiler
|
||||
#endif
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"\u00a1", toml_parser::EQuoteRequest::smart_text), "\"\\u00A1\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::smart_text), "\"abc/\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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'");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\"abc\"", toml_parser::EQuoteRequest::smart_text), "'\"abc\"'"); // becomes literal text
|
||||
EXPECT_EQ(toml_parser::QuoteText("'abc'", toml_parser::EQuoteRequest::smart_text), "\"'abc'\""); // becomes literal text
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\bdef", toml_parser::EQuoteRequest::smart_text), "\"abc\\bdef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\ndef", toml_parser::EQuoteRequest::smart_text), "\"abc\\ndef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\fdef", toml_parser::EQuoteRequest::smart_text), "\"abc\\fdef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::smart_text), "\"abc\\rdef\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0002", toml_parser::EQuoteRequest::smart_text), "\"\\u0002\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0003", toml_parser::EQuoteRequest::smart_text), "\"\\u0003\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0004", toml_parser::EQuoteRequest::smart_text), "\"\\u0004\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0005", toml_parser::EQuoteRequest::smart_text), "\"\\u0005\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0006", toml_parser::EQuoteRequest::smart_text), "\"\\u0006\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0007", toml_parser::EQuoteRequest::smart_text), "\"\\u0007\"");
|
||||
// 0008 = backspace (\b), 0009 = tab (\t), 000a = linefeed (\n)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000b", toml_parser::EQuoteRequest::smart_text), "\"\\u000B\"");
|
||||
// 000c = form feed (\f), 000d = carriage return (\r)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000e", toml_parser::EQuoteRequest::smart_text), "\"\\u000E\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000f", toml_parser::EQuoteRequest::smart_text), "\"\\u000F\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0010", toml_parser::EQuoteRequest::smart_text), "\"\\u0010\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0011", toml_parser::EQuoteRequest::smart_text), "\"\\u0011\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0012", toml_parser::EQuoteRequest::smart_text), "\"\\u0012\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0013", toml_parser::EQuoteRequest::smart_text), "\"\\u0013\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0014", toml_parser::EQuoteRequest::smart_text), "\"\\u0014\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0015", toml_parser::EQuoteRequest::smart_text), "\"\\u0015\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0016", toml_parser::EQuoteRequest::smart_text), "\"\\u0016\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0017", toml_parser::EQuoteRequest::smart_text), "\"\\u0017\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0018", toml_parser::EQuoteRequest::smart_text), "\"\\u0018\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0019", toml_parser::EQuoteRequest::smart_text), "\"\\u0019\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001a", toml_parser::EQuoteRequest::smart_text), "\"\\u001A\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001b", toml_parser::EQuoteRequest::smart_text), "\"\\u001B\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001c", toml_parser::EQuoteRequest::smart_text), "\"\\u001C\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001d", toml_parser::EQuoteRequest::smart_text), "\"\\u001D\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001e", toml_parser::EQuoteRequest::smart_text), "\"\\u001E\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001f", toml_parser::EQuoteRequest::smart_text), "\"\\u001F\"");
|
||||
// 0020..0021 are treated as characters (partly quotation needed)
|
||||
// 0022 = quote (\")
|
||||
// 0023..005b are treated as characters (partly quotation needed)
|
||||
// 005c = backslash (\\)
|
||||
// 005d..007e are treated as characters (partly quotation needed)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u007f", toml_parser::EQuoteRequest::smart_text), "\"\\u007F\"");
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC", toml_parser::EQuoteRequest::quoted_text), "\"ABC\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc_def", toml_parser::EQuoteRequest::quoted_text), "\"abc_def\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::quoted_text), "\"ABC-DEF\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText(".abc", toml_parser::EQuoteRequest::quoted_text), "\".abc\"");
|
||||
#ifndef __GNUC__
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"<EFBFBD>", toml_parser::EQuoteRequest::quoted_text),
|
||||
"\"\\u00B5\""); // Only supported on Windows with MS compiler
|
||||
#endif
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"\u00a1", toml_parser::EQuoteRequest::quoted_text), "\"\\u00A1\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::quoted_text), "\"abc/\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\"abc\"", toml_parser::EQuoteRequest::quoted_text), "\"\\\"abc\\\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("'abc'", toml_parser::EQuoteRequest::quoted_text), "\"'abc'\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\bdef", toml_parser::EQuoteRequest::quoted_text), "\"abc\\bdef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\ndef", toml_parser::EQuoteRequest::quoted_text), "\"abc\\ndef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\fdef", toml_parser::EQuoteRequest::quoted_text), "\"abc\\fdef\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::quoted_text), "\"abc\\rdef\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0002", toml_parser::EQuoteRequest::quoted_text), "\"\\u0002\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0003", toml_parser::EQuoteRequest::quoted_text), "\"\\u0003\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0004", toml_parser::EQuoteRequest::quoted_text), "\"\\u0004\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0005", toml_parser::EQuoteRequest::quoted_text), "\"\\u0005\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0006", toml_parser::EQuoteRequest::quoted_text), "\"\\u0006\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0007", toml_parser::EQuoteRequest::quoted_text), "\"\\u0007\"");
|
||||
// 0008 = backspace (\b), 0009 = tab (\t), 000a = linefeed (\n)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000b", toml_parser::EQuoteRequest::quoted_text), "\"\\u000B\"");
|
||||
// 000c = form feed (\f), 000d = carriage return (\r)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000e", toml_parser::EQuoteRequest::quoted_text), "\"\\u000E\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000f", toml_parser::EQuoteRequest::quoted_text), "\"\\u000F\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0010", toml_parser::EQuoteRequest::quoted_text), "\"\\u0010\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0011", toml_parser::EQuoteRequest::quoted_text), "\"\\u0011\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0012", toml_parser::EQuoteRequest::quoted_text), "\"\\u0012\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0013", toml_parser::EQuoteRequest::quoted_text), "\"\\u0013\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0014", toml_parser::EQuoteRequest::quoted_text), "\"\\u0014\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0015", toml_parser::EQuoteRequest::quoted_text), "\"\\u0015\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0016", toml_parser::EQuoteRequest::quoted_text), "\"\\u0016\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0017", toml_parser::EQuoteRequest::quoted_text), "\"\\u0017\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0018", toml_parser::EQuoteRequest::quoted_text), "\"\\u0018\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0019", toml_parser::EQuoteRequest::quoted_text), "\"\\u0019\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001a", toml_parser::EQuoteRequest::quoted_text), "\"\\u001A\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001b", toml_parser::EQuoteRequest::quoted_text), "\"\\u001B\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001c", toml_parser::EQuoteRequest::quoted_text), "\"\\u001C\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001d", toml_parser::EQuoteRequest::quoted_text), "\"\\u001D\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001e", toml_parser::EQuoteRequest::quoted_text), "\"\\u001E\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001f", toml_parser::EQuoteRequest::quoted_text), "\"\\u001F\"");
|
||||
// 0020..0021 are treated as characters (partly quotation needed)
|
||||
// 0022 = quote (\")
|
||||
// 0023..005b are treated as characters (partly quotation needed)
|
||||
// 005c = backslash (\\)
|
||||
// 005d..007e are treated as characters (partly quotation needed)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u007f", toml_parser::EQuoteRequest::quoted_text), "\"\\u007F\"");
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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'");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC", toml_parser::EQuoteRequest::literal_text), "'ABC'");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc_def", toml_parser::EQuoteRequest::literal_text), "'abc_def'");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::literal_text), "'ABC-DEF'");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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'");
|
||||
EXPECT_EQ(toml_parser::QuoteText(".abc", toml_parser::EQuoteRequest::literal_text), "'.abc'");
|
||||
#ifndef __GNUC__
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"<EFBFBD>", toml_parser::EQuoteRequest::literal_text),
|
||||
u8"'\u00B5'"); // Only supported on Windows with MS compiler
|
||||
#endif
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"\u00a1", toml_parser::EQuoteRequest::literal_text), u8"'\u00A1'");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::literal_text), "'abc/'");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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'");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\"abc\"", toml_parser::EQuoteRequest::literal_text), "'\"abc\"'");
|
||||
EXPECT_EQ(toml_parser::QuoteText("'abc'", toml_parser::EQuoteRequest::literal_text), "\"'abc'\""); // Becomes quoted
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\bdef", toml_parser::EQuoteRequest::literal_text), "\"abc\\bdef\""); // Becomes quoted
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\ndef", toml_parser::EQuoteRequest::literal_text), "\"abc\\ndef\""); // Becomes quoted
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\fdef", toml_parser::EQuoteRequest::literal_text), "\"abc\\fdef\""); // Becomes quoted
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::literal_text), "\"abc\\rdef\""); // Becomes quoted
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0001", toml_parser::EQuoteRequest::literal_text), "\"\\u0001\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0002", toml_parser::EQuoteRequest::literal_text), "\"\\u0002\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0003", toml_parser::EQuoteRequest::literal_text), "\"\\u0003\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0004", toml_parser::EQuoteRequest::literal_text), "\"\\u0004\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0005", toml_parser::EQuoteRequest::literal_text), "\"\\u0005\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0006", toml_parser::EQuoteRequest::literal_text), "\"\\u0006\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0007", toml_parser::EQuoteRequest::literal_text), "\"\\u0007\"");
|
||||
// 0008 = backspace (\b), 0009 = tab (\t), 000a = linefeed (\n)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000b", toml_parser::EQuoteRequest::literal_text), "\"\\u000B\"");
|
||||
// 000c = form feed (\f), 000d = carriage return (\r)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000e", toml_parser::EQuoteRequest::literal_text), "\"\\u000E\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000f", toml_parser::EQuoteRequest::literal_text), "\"\\u000F\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0010", toml_parser::EQuoteRequest::literal_text), "\"\\u0010\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0011", toml_parser::EQuoteRequest::literal_text), "\"\\u0011\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0012", toml_parser::EQuoteRequest::literal_text), "\"\\u0012\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0013", toml_parser::EQuoteRequest::literal_text), "\"\\u0013\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0014", toml_parser::EQuoteRequest::literal_text), "\"\\u0014\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0015", toml_parser::EQuoteRequest::literal_text), "\"\\u0015\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0016", toml_parser::EQuoteRequest::literal_text), "\"\\u0016\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0017", toml_parser::EQuoteRequest::literal_text), "\"\\u0017\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0018", toml_parser::EQuoteRequest::literal_text), "\"\\u0018\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0019", toml_parser::EQuoteRequest::literal_text), "\"\\u0019\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001a", toml_parser::EQuoteRequest::literal_text), "\"\\u001A\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001b", toml_parser::EQuoteRequest::literal_text), "\"\\u001B\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001c", toml_parser::EQuoteRequest::literal_text), "\"\\u001C\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001d", toml_parser::EQuoteRequest::literal_text), "\"\\u001D\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001e", toml_parser::EQuoteRequest::literal_text), "\"\\u001E\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001f", toml_parser::EQuoteRequest::literal_text), "\"\\u001F\"");
|
||||
// 0020..0021 are treated as characters (partly quotation needed)
|
||||
// 0022 = quote (\")
|
||||
// 0023..005b are treated as characters (partly quotation needed)
|
||||
// 005c = backslash (\\)
|
||||
// 005d..007e are treated as characters (partly quotation needed)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u007f", toml_parser::EQuoteRequest::literal_text), "\"\\u007F\"");
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"ABC\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc_def", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc_def\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"ABC-DEF\"\"\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText(".abc", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\".abc\"\"\"");
|
||||
#ifndef __GNUC__
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"<EFBFBD>", toml_parser::EQuoteRequest::multi_line_quoted_text),
|
||||
"\"\"\"\\u00B5\"\"\""); // Only supported on Windows with MS compiler
|
||||
#endif
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"\u00a1", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u00A1\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc/\"\"\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\"abc\"", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\\"abc\\\"\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("'abc'", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"'abc'\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\bdef", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc\\bdef\"\"\"");
|
||||
// Multi line
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\ndef", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc\ndef\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\fdef", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc\\fdef\"\"\"");
|
||||
// Multi line
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"abc\rdef\"\"\"");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0002", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0002\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0003", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0003\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0004", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0004\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0005", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0005\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0006", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0006\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0007", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0007\"\"\"");
|
||||
// 0008 = backspace (\b), 0009 = tab (\t), 000a = linefeed (\n)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000b", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u000B\"\"\"");
|
||||
// 000c = form feed (\f), 000d = carriage return (\r)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000e", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u000E\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000f", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u000F\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0010", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0010\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0011", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0011\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0012", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0012\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0013", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0013\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0014", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0014\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0015", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0015\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0016", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0016\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0017", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0017\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0018", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0018\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0019", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u0019\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001a", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u001A\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001b", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u001B\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001c", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u001C\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001d", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u001D\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001e", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u001E\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001f", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u001F\"\"\"");
|
||||
// 0020..0021 are treated as characters (partly quotation needed)
|
||||
// 0022 = quote (\")
|
||||
// 0023..005b are treated as characters (partly quotation needed)
|
||||
// 005c = backslash (\\)
|
||||
// 005d..007e are treated as characters (partly quotation needed)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u007f", toml_parser::EQuoteRequest::multi_line_quoted_text), "\"\"\"\\u007F\"\"\"");
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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'''");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC", toml_parser::EQuoteRequest::multi_line_literal_text), "'''ABC'''");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc_def", toml_parser::EQuoteRequest::multi_line_literal_text), "'''abc_def'''");
|
||||
EXPECT_EQ(toml_parser::QuoteText("ABC-DEF", toml_parser::EQuoteRequest::multi_line_literal_text), "'''ABC-DEF'''");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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'''");
|
||||
EXPECT_EQ(toml_parser::QuoteText(".abc", toml_parser::EQuoteRequest::multi_line_literal_text), "'''.abc'''");
|
||||
#ifndef __GNUC__
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"<EFBFBD>", toml_parser::EQuoteRequest::multi_line_literal_text),
|
||||
u8"'''\u00B5'''"); // Only supported on Windows with MS compiler
|
||||
#endif
|
||||
EXPECT_EQ(toml_parser::QuoteText(u8"\u00a1", toml_parser::EQuoteRequest::multi_line_literal_text), u8"'''\u00A1'''");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc/", toml_parser::EQuoteRequest::multi_line_literal_text), "'''abc/'''");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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'''");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\"abc\"", toml_parser::EQuoteRequest::multi_line_literal_text), "'''\"abc\"'''");
|
||||
EXPECT_EQ(toml_parser::QuoteText("'abc'", toml_parser::EQuoteRequest::multi_line_literal_text), "''''abc''''");
|
||||
EXPECT_EQ(
|
||||
toml_parser::QuoteText("abc\bdef", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"abc\\bdef\"\"\""); // Becomes quoted
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\ndef", toml_parser::EQuoteRequest::multi_line_literal_text), "'''abc\ndef'''");
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\fdef", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"abc\\fdef\"\"\""); // Becomes quoted
|
||||
EXPECT_EQ(toml_parser::QuoteText("abc\rdef", toml_parser::EQuoteRequest::multi_line_literal_text), "'''abc\rdef'''");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, 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\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0001", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0001\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0002", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0002\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0003", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0003\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0004", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0004\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0005", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0005\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0006", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0006\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0007", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0007\"\"\"");
|
||||
// 0008 = backspace (\b), 0009 = tab (\t), 000a = linefeed (\n)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000b", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u000B\"\"\"");
|
||||
// 000c = form feed (\f), 000d = carriage return (\r)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000e", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u000E\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u000f", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u000F\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0010", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0010\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0011", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0011\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0012", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0012\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0013", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0013\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0014", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0014\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0015", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0015\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0016", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0016\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0017", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0017\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0018", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0018\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u0019", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u0019\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001a", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u001A\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001b", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u001B\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001c", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u001C\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001d", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u001D\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001e", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u001E\"\"\"");
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u001f", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u001F\"\"\"");
|
||||
// 0020..0021 are treated as characters (partly quotation needed)
|
||||
// 0022 = quote (\")
|
||||
// 0023..005b are treated as characters (partly quotation needed)
|
||||
// 005c = backslash (\\)
|
||||
// 005d..007e are treated as characters (partly quotation needed)
|
||||
EXPECT_EQ(toml_parser::QuoteText("\u007f", toml_parser::EQuoteRequest::multi_line_literal_text), "\"\"\"\\u007F\"\"\"");
|
||||
// 0080... and higher are treated as unicode character (quotation needed)
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, ExtractBareKeyName)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName(""), "");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc.def"), "def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc"), "abc");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc.def.ghi"), "ghi");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("_abc.def"), "def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("_abc._def"), "_def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc-.def"), "def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc-.def-"), "def-");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("1234"), "1234");
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, ExtractQuotedKeyName)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("\"\""), "");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("\"abc\""), "abc");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc.\"def\""), "def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("\"abc.def\""), "abc.def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("\"abc\\tdef\""), "abc\tdef");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("\"'This' is a \\\"very\\\" quoted key!\""), "'This' is a \"very\" quoted key!");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("\"[1]\""), "[1]");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("\"abc"), ""); // Failure
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc\"def\""), ""); // Failure
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, ExtractLiteralKeyName)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("''"), "");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("'abc'"), "abc");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc.'def'"), "def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("'abc.def'"), "abc.def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("'abc def'"), "abc def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("'abc\\tdef'"), "abc\\tdef"); // No escape uences supported
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("'This is a \"very\" literal key!'"), "This is a \"very\" literal key!");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("'[1]'"), "[1]");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("'abc"), "");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc'def"), ""); // Failure
|
||||
}
|
||||
|
||||
TEST(TOMLMiscellaneousTests, ExtractIndexKeyName)
|
||||
{
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("[0]"), "0");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("[0][1]"), "1");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc[0][1]"), "1");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc[0].def"), "def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc[0].\"def\""), "def");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc[0].def[1]"), "1");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc[0].\"def\"[1]"), "1");
|
||||
EXPECT_EQ(toml_parser::ExtractKeyName("abc[0]def"), ""); // Failure
|
||||
}
|
||||
@@ -2,34 +2,42 @@
|
||||
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
|
||||
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
|
||||
|
||||
/* Requirements TOML CParserTOML
|
||||
/* Requirements TOML toml_parser::CParser
|
||||
* - The output after parsing is a tree structure only if parsing is successful
|
||||
* - No recovery will be attempted when syntax errors occur
|
||||
* - all errors and features (except Date-Time) as defined at https://toml.io/en/v1.0.0 have to result in an invalid or valid
|
||||
* outcome respectively
|
||||
* outcome respectively
|
||||
*/
|
||||
|
||||
TEST(RecognizeTypes, Root)
|
||||
{
|
||||
toml_parser::CParser parser("");
|
||||
auto& rroot = parser.Root();
|
||||
EXPECT_EQ(rroot.GetParent(), nullptr);
|
||||
EXPECT_EQ(rroot.GetIndex(), sdv::toml::npos);
|
||||
}
|
||||
|
||||
TEST(RecognizeTypes, Table)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
[newTable]
|
||||
[secondTable.nestedTable]
|
||||
)"s);
|
||||
|
||||
auto table1 = parser.GetRoot().GetDirect("newTable");
|
||||
auto table1 = parser.Root().Direct("newTable");
|
||||
EXPECT_EQ(table1->GetType(), sdv::toml::ENodeType::node_table);
|
||||
EXPECT_EQ(table1->GetName(), "newTable");
|
||||
EXPECT_EQ(table1->GetValue(), sdv::any_t());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(table1.get())->GetInterface<sdv::toml::INodeCollection>(), nullptr);
|
||||
|
||||
auto table2 = parser.GetRoot().GetDirect("secondTable");
|
||||
auto table2 = parser.Root().Direct("secondTable");
|
||||
EXPECT_EQ(table2->GetType(), sdv::toml::ENodeType::node_table);
|
||||
EXPECT_EQ(table2->GetName(), "secondTable");
|
||||
EXPECT_EQ(table2->GetValue(), sdv::any_t());
|
||||
EXPECT_NE(((sdv::IInterfaceAccess*) table2.get())->GetInterface<sdv::toml::INodeCollection>(), nullptr);
|
||||
|
||||
auto table3 = parser.GetRoot().GetDirect("secondTable.nestedTable");
|
||||
auto table3 = parser.Root().Direct("secondTable.nestedTable");
|
||||
EXPECT_EQ(table3->GetType(), sdv::toml::ENodeType::node_table);
|
||||
EXPECT_EQ(table3->GetName(), "nestedTable");
|
||||
EXPECT_EQ(table3->GetValue(), sdv::any_t());
|
||||
@@ -39,7 +47,7 @@ TEST(RecognizeTypes, Table)
|
||||
TEST(RecognizeTypes, Key_Value)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
name = "Hammer"
|
||||
id = 42
|
||||
pi = 3.1415926
|
||||
@@ -49,41 +57,47 @@ TEST(RecognizeTypes, Key_Value)
|
||||
)"s);
|
||||
|
||||
|
||||
auto value_name = parser.GetRoot().GetDirect("name");
|
||||
auto value_name = parser.Root().Direct("name");
|
||||
EXPECT_EQ(value_name->GetType(), sdv::toml::ENodeType::node_string);
|
||||
EXPECT_EQ(value_name->GetValue(), sdv::any_t("Hammer"));
|
||||
EXPECT_EQ(value_name->GetIndex(), 0u);
|
||||
|
||||
auto value_id = parser.GetRoot().GetDirect("id");
|
||||
auto value_id = parser.Root().Direct("id");
|
||||
EXPECT_EQ(value_id->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(value_id->GetValue(), 42);
|
||||
EXPECT_EQ(value_id->GetIndex(), 1u);
|
||||
|
||||
auto value_pi = parser.GetRoot().GetDirect("pi");
|
||||
auto value_pi = parser.Root().Direct("pi");
|
||||
EXPECT_EQ(value_pi->GetType(), sdv::toml::ENodeType::node_floating_point);
|
||||
EXPECT_EQ(value_pi->GetValue(), 3.1415926);
|
||||
EXPECT_EQ(value_pi->GetIndex(), 2u);
|
||||
|
||||
auto value_boolean = parser.GetRoot().GetDirect("boolean");
|
||||
auto value_boolean = parser.Root().Direct("boolean");
|
||||
EXPECT_EQ(value_boolean->GetType(), sdv::toml::ENodeType::node_boolean);
|
||||
EXPECT_EQ(value_boolean->GetValue(), true);
|
||||
EXPECT_EQ(value_boolean->GetIndex(), 3u);
|
||||
|
||||
auto value_array = parser.GetRoot().GetDirect("array");
|
||||
auto value_array = parser.Root().Direct("array");
|
||||
EXPECT_EQ(value_array->GetType(), sdv::toml::ENodeType::node_array);
|
||||
EXPECT_EQ(value_array->GetValue(), sdv::any_t());
|
||||
EXPECT_EQ(value_array->GetIndex(), 4u);
|
||||
|
||||
auto value_table = parser.GetRoot().GetDirect("table");
|
||||
auto value_table = parser.Root().Direct("table");
|
||||
EXPECT_EQ(value_table->GetType(), sdv::toml::ENodeType::node_table);
|
||||
EXPECT_EQ(value_table->GetValue(), sdv::any_t());
|
||||
EXPECT_EQ(value_table->GetIndex(), 5u);
|
||||
}
|
||||
|
||||
TEST(RecognizeTypes, TableArray)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
[[newTableArray]]
|
||||
[[newTableArray]]
|
||||
[[table.nestedTableArray]]
|
||||
)"s);
|
||||
|
||||
auto tableArray1 = parser.GetRoot().GetDirect("newTableArray");
|
||||
auto tableArray1 = parser.Root().Direct("newTableArray");
|
||||
EXPECT_EQ(tableArray1->GetType(), sdv::toml::ENodeType::node_array);
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(tableArray1.get())->GetInterface<sdv::toml::INodeCollection>(), nullptr);
|
||||
EXPECT_EQ(tableArray1->GetName(), "newTableArray");
|
||||
@@ -97,21 +111,23 @@ TEST(RecognizeTypes, TableArray)
|
||||
EXPECT_NE(pTableNode1, nullptr);
|
||||
EXPECT_EQ(pArrayCollection->GetNode(2), nullptr);
|
||||
|
||||
auto table1 = parser.GetRoot().GetDirect("newTableArray[0]");
|
||||
auto table1 = parser.Root().Direct("newTableArray[0]");
|
||||
ASSERT_TRUE(table1);
|
||||
EXPECT_EQ(table1->GetType(), sdv::toml::ENodeType::node_table);
|
||||
EXPECT_EQ(static_cast<sdv::IInterfaceAccess*>(table1.get()), pTableNode0);
|
||||
EXPECT_TRUE(table1->GetName().empty());
|
||||
EXPECT_EQ(table1->GetName(), "newTableArray");
|
||||
|
||||
auto table2 = parser.GetRoot().GetDirect("newTableArray[1]");
|
||||
auto table2 = parser.Root().Direct("newTableArray[1]");
|
||||
ASSERT_TRUE(table2);
|
||||
EXPECT_EQ(static_cast<sdv::IInterfaceAccess*>(table2.get()), pTableNode1);
|
||||
EXPECT_EQ(table2->GetType(), sdv::toml::ENodeType::node_table);
|
||||
EXPECT_TRUE(table2->GetName().empty());
|
||||
EXPECT_EQ(table2->GetName(), "newTableArray");
|
||||
}
|
||||
|
||||
TEST(NestedContent, Array)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
arr_mixed = [ 1.0, 2, "test string", [ 1, 2 ], { pi = 3.14, e = 2.71828 }, true]
|
||||
arr_ints = [ 1, 2, 3, 4]
|
||||
arr_ints_trailing_comma = [ 1, 2, 3, 4, ]
|
||||
@@ -124,7 +140,7 @@ TEST(NestedContent, Array)
|
||||
|
||||
{
|
||||
|
||||
auto array_ints = parser.GetRoot().GetDirect("arr_ints");
|
||||
auto array_ints = parser.Root().Direct("arr_ints");
|
||||
EXPECT_EQ(array_ints->GetType(), sdv::toml::ENodeType::node_array);
|
||||
sdv::toml::INodeCollection* pIntArrayCollection =
|
||||
static_cast<sdv::IInterfaceAccess*>(array_ints.get())->GetInterface<sdv::toml::INodeCollection>();
|
||||
@@ -135,104 +151,131 @@ TEST(NestedContent, Array)
|
||||
EXPECT_NE(pIntArrayCollection->GetNode(2), nullptr);
|
||||
EXPECT_NE(pIntArrayCollection->GetNode(3), nullptr);
|
||||
EXPECT_EQ(pIntArrayCollection->GetNode(4), nullptr);
|
||||
auto array_ints_0 = parser.GetRoot().GetDirect("arr_ints[0]");
|
||||
auto array_ints_0 = parser.Root().Direct("arr_ints[0]");
|
||||
ASSERT_NE(array_ints_0, nullptr);
|
||||
EXPECT_EQ(array_ints_0->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_ints_0->GetValue(), 1);
|
||||
auto array_ints_1 = parser.GetRoot().GetDirect("arr_ints[1]");
|
||||
EXPECT_EQ(array_ints_0->GetIndex(), 0u);
|
||||
auto array_ints_1 = parser.Root().Direct("arr_ints[1]");
|
||||
ASSERT_NE(array_ints_1, nullptr);
|
||||
EXPECT_EQ(array_ints_1->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_ints_1->GetValue(), 2);
|
||||
auto array_ints_2 = parser.GetRoot().GetDirect("arr_ints[2]");
|
||||
EXPECT_EQ(array_ints_1->GetIndex(), 1u);
|
||||
auto array_ints_2 = parser.Root().Direct("arr_ints[2]");
|
||||
ASSERT_NE(array_ints_2, nullptr);
|
||||
EXPECT_EQ(array_ints_2->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_ints_2->GetValue(), 3);
|
||||
auto array_ints_3 = parser.GetRoot().GetDirect("arr_ints[3]");
|
||||
EXPECT_EQ(array_ints_2->GetIndex(), 2u);
|
||||
auto array_ints_3 = parser.Root().Direct("arr_ints[3]");
|
||||
ASSERT_NE(array_ints_3, nullptr);
|
||||
EXPECT_EQ(array_ints_3->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_ints_3->GetValue(), 4);
|
||||
auto array_ints_4 = parser.GetRoot().GetDirect("arr_ints[4]");
|
||||
EXPECT_EQ(array_ints_3->GetIndex(), 3u);
|
||||
auto array_ints_4 = parser.Root().Direct("arr_ints[4]");
|
||||
EXPECT_EQ(array_ints_4, nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
auto array_ints_trailing_comma = parser.GetRoot().GetDirect("arr_ints_trailing_comma");
|
||||
auto array_ints_trailing_comma_0 = parser.GetRoot().GetDirect("arr_ints_trailing_comma[0]");
|
||||
auto array_ints_trailing_comma_1 = parser.GetRoot().GetDirect("arr_ints_trailing_comma[1]");
|
||||
auto array_ints_trailing_comma_2 = parser.GetRoot().GetDirect("arr_ints_trailing_comma[2]");
|
||||
auto array_ints_trailing_comma_3 = parser.GetRoot().GetDirect("arr_ints_trailing_comma[3]");
|
||||
auto array_ints_trailing_comma_4 = parser.GetRoot().GetDirect("arr_ints_trailing_comma[4]");
|
||||
auto array_ints_trailing_comma = parser.Root().Direct("arr_ints_trailing_comma");
|
||||
auto array_ints_trailing_comma_0 = parser.Root().Direct("arr_ints_trailing_comma[0]");
|
||||
auto array_ints_trailing_comma_1 = parser.Root().Direct("arr_ints_trailing_comma[1]");
|
||||
auto array_ints_trailing_comma_2 = parser.Root().Direct("arr_ints_trailing_comma[2]");
|
||||
auto array_ints_trailing_comma_3 = parser.Root().Direct("arr_ints_trailing_comma[3]");
|
||||
auto array_ints_trailing_comma_4 = parser.Root().Direct("arr_ints_trailing_comma[4]");
|
||||
|
||||
EXPECT_EQ(array_ints_trailing_comma->GetType(), sdv::toml::ENodeType::node_array);
|
||||
ASSERT_NE(array_ints_trailing_comma_0, nullptr);
|
||||
EXPECT_EQ(array_ints_trailing_comma_0->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_ints_trailing_comma_0->GetValue(), 1);
|
||||
EXPECT_EQ(array_ints_trailing_comma_0->GetIndex(), 0u);
|
||||
ASSERT_NE(array_ints_trailing_comma_1, nullptr);
|
||||
EXPECT_EQ(array_ints_trailing_comma_1->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_ints_trailing_comma_1->GetValue(), 2);
|
||||
EXPECT_EQ(array_ints_trailing_comma_1->GetIndex(), 1u);
|
||||
ASSERT_NE(array_ints_trailing_comma_2, nullptr);
|
||||
EXPECT_EQ(array_ints_trailing_comma_2->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_ints_trailing_comma_2->GetValue(), 3);
|
||||
EXPECT_EQ(array_ints_trailing_comma_2->GetIndex(), 2u);
|
||||
ASSERT_NE(array_ints_trailing_comma_3, nullptr);
|
||||
EXPECT_EQ(array_ints_trailing_comma_3->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_ints_trailing_comma_3->GetValue(), 4);
|
||||
EXPECT_EQ(array_ints_trailing_comma_3->GetIndex(), 3u);
|
||||
EXPECT_EQ(array_ints_trailing_comma_4, nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
auto array_mixed = parser.GetRoot().GetDirect("arr_mixed");
|
||||
auto array_mixed_0 = parser.GetRoot().GetDirect("arr_mixed[0]");
|
||||
auto array_mixed_1 = parser.GetRoot().GetDirect("arr_mixed[1]");
|
||||
auto array_mixed_2 = parser.GetRoot().GetDirect("arr_mixed[2]");
|
||||
auto array_mixed_3 = parser.GetRoot().GetDirect("arr_mixed[3]");
|
||||
auto array_mixed_3_2 = parser.GetRoot().GetDirect("arr_mixed[3][1]");
|
||||
auto array_mixed_4 = parser.GetRoot().GetDirect("arr_mixed[4]");
|
||||
auto array_mixed_4_pi = parser.GetRoot().GetDirect("arr_mixed[4].pi");
|
||||
auto array_mixed_5 = parser.GetRoot().GetDirect("arr_mixed[5]");
|
||||
auto array_mixed_6 = parser.GetRoot().GetDirect("arr_mixed[6]");
|
||||
auto array_mixed = parser.Root().Direct("arr_mixed");
|
||||
auto array_mixed_0 = parser.Root().Direct("arr_mixed[0]");
|
||||
auto array_mixed_1 = parser.Root().Direct("arr_mixed[1]");
|
||||
auto array_mixed_2 = parser.Root().Direct("arr_mixed[2]");
|
||||
auto array_mixed_3 = parser.Root().Direct("arr_mixed[3]");
|
||||
auto array_mixed_3_1 = parser.Root().Direct("arr_mixed[3][0]");
|
||||
auto array_mixed_3_2 = parser.Root().Direct("arr_mixed[3][1]");
|
||||
auto array_mixed_4 = parser.Root().Direct("arr_mixed[4]");
|
||||
auto array_mixed_4_pi = parser.Root().Direct("arr_mixed[4].pi");
|
||||
auto array_mixed_4_e = parser.Root().Direct("arr_mixed[4].e");
|
||||
auto array_mixed_5 = parser.Root().Direct("arr_mixed[5]");
|
||||
auto array_mixed_6 = parser.Root().Direct("arr_mixed[6]");
|
||||
|
||||
EXPECT_EQ(array_mixed->GetType(), sdv::toml::ENodeType::node_array);
|
||||
ASSERT_NE(array_mixed_0, nullptr);
|
||||
EXPECT_EQ(array_mixed_0->GetType(), sdv::toml::ENodeType::node_floating_point);
|
||||
EXPECT_EQ(array_mixed_0->GetValue(), 1.0);
|
||||
EXPECT_EQ(array_mixed_0->GetIndex(), 0u);
|
||||
ASSERT_NE(array_mixed_1, nullptr);
|
||||
EXPECT_EQ(array_mixed_1->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_mixed_1->GetValue(), 2);
|
||||
EXPECT_EQ(array_mixed_1->GetIndex(), 1u);
|
||||
ASSERT_NE(array_mixed_2, nullptr);
|
||||
EXPECT_EQ(array_mixed_2->GetType(), sdv::toml::ENodeType::node_string);
|
||||
EXPECT_EQ(static_cast<std::string>(array_mixed_2->GetValue()), "test string");
|
||||
EXPECT_EQ(array_mixed_2->GetIndex(), 2u);
|
||||
ASSERT_NE(array_mixed_3, nullptr);
|
||||
EXPECT_EQ(array_mixed_3->GetType(), sdv::toml::ENodeType::node_array);
|
||||
EXPECT_EQ(array_mixed_3->GetIndex(), 3u);
|
||||
EXPECT_EQ(array_mixed_3_1->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_mixed_3_1->GetValue(), 1);
|
||||
EXPECT_EQ(array_mixed_3_1->GetIndex(), 0u);
|
||||
EXPECT_EQ(array_mixed_3_2->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(array_mixed_3_2->GetValue(), 2);
|
||||
EXPECT_EQ(array_mixed_3_2->GetIndex(), 1u);
|
||||
ASSERT_NE(array_mixed_4, nullptr);
|
||||
EXPECT_EQ(array_mixed_4->GetType(), sdv::toml::ENodeType::node_table);
|
||||
EXPECT_EQ(array_mixed_4->GetIndex(), 4u);
|
||||
EXPECT_EQ(array_mixed_4_pi->GetType(), sdv::toml::ENodeType::node_floating_point);
|
||||
EXPECT_EQ(array_mixed_4_pi->GetValue(), 3.14);
|
||||
EXPECT_EQ(array_mixed_4_pi->GetIndex(), 0u);
|
||||
EXPECT_EQ(array_mixed_4_e->GetType(), sdv::toml::ENodeType::node_floating_point);
|
||||
EXPECT_EQ(array_mixed_4_e->GetValue(), 2.71828);
|
||||
EXPECT_EQ(array_mixed_4_e->GetIndex(), 1u);
|
||||
ASSERT_NE(array_mixed_5, nullptr);
|
||||
EXPECT_EQ(array_mixed_5->GetType(), sdv::toml::ENodeType::node_boolean);
|
||||
EXPECT_EQ(array_mixed_5->GetValue(), true);
|
||||
EXPECT_EQ(array_mixed_5->GetValue(), sdv::any_t());
|
||||
EXPECT_EQ(array_mixed_5->GetIndex(), 5u);
|
||||
EXPECT_EQ(array_mixed_6, nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
auto array_multiline = parser.GetRoot().GetDirect("arr_multiline");
|
||||
auto array_multiline_0 = parser.GetRoot().GetDirect("arr_multiline[0]");
|
||||
auto array_multiline_1 = parser.GetRoot().GetDirect("arr_multiline[1]");
|
||||
auto array_multiline_2 = parser.GetRoot().GetDirect("arr_multiline[2]");
|
||||
auto array_multiline_3 = parser.GetRoot().GetDirect("arr_multiline[3]");
|
||||
auto array_multiline = parser.Root().Direct("arr_multiline");
|
||||
auto array_multiline_0 = parser.Root().Direct("arr_multiline[0]");
|
||||
auto array_multiline_1 = parser.Root().Direct("arr_multiline[1]");
|
||||
auto array_multiline_2 = parser.Root().Direct("arr_multiline[2]");
|
||||
auto array_multiline_3 = parser.Root().Direct("arr_multiline[3]");
|
||||
|
||||
EXPECT_EQ(array_multiline->GetType(), sdv::toml::ENodeType::node_array);
|
||||
ASSERT_NE(array_multiline_0, nullptr);
|
||||
EXPECT_EQ(array_multiline_0->GetType(), sdv::toml::ENodeType::node_string);
|
||||
EXPECT_EQ(static_cast<std::string>(array_multiline_0->GetValue()), "first line");
|
||||
EXPECT_EQ(array_multiline_0->GetIndex(), 0u);
|
||||
ASSERT_NE(array_multiline_1, nullptr);
|
||||
EXPECT_EQ(array_multiline_1->GetType(), sdv::toml::ENodeType::node_string);
|
||||
EXPECT_EQ(static_cast<std::string>(array_multiline_1->GetValue()), "second line");
|
||||
EXPECT_EQ(array_multiline_1->GetIndex(), 1u);
|
||||
ASSERT_NE(array_multiline_2, nullptr);
|
||||
EXPECT_EQ(array_multiline_2->GetType(), sdv::toml::ENodeType::node_string);
|
||||
EXPECT_EQ(static_cast<std::string>(array_multiline_2->GetValue()), "third_line");
|
||||
EXPECT_EQ(array_multiline_2->GetIndex(), 2u);
|
||||
EXPECT_EQ(array_multiline_3, nullptr);
|
||||
}
|
||||
}
|
||||
@@ -240,7 +283,7 @@ TEST(NestedContent, Array)
|
||||
TEST(NestedContent, Table)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
[table]
|
||||
a = 2
|
||||
b = 1.2
|
||||
@@ -252,12 +295,12 @@ TEST(NestedContent, Table)
|
||||
d = []
|
||||
)"s);
|
||||
|
||||
auto table_a = parser.GetRoot().GetDirect("table.a");
|
||||
auto table_b = parser.GetRoot().GetDirect("table.b");
|
||||
auto anotherTable_a = parser.GetRoot().GetDirect("anotherTable.a");
|
||||
auto anotherTable_c = parser.GetRoot().GetDirect("anotherTable.c");
|
||||
auto fourthTable_a = parser.GetRoot().GetDirect("thirdTable.fourthTable.a");
|
||||
auto fourthTable_d = parser.GetRoot().GetDirect("thirdTable.fourthTable.d");
|
||||
auto table_a = parser.Root().Direct("table.a");
|
||||
auto table_b = parser.Root().Direct("table.b");
|
||||
auto anotherTable_a = parser.Root().Direct("anotherTable.a");
|
||||
auto anotherTable_c = parser.Root().Direct("anotherTable.c");
|
||||
auto fourthTable_a = parser.Root().Direct("thirdTable.fourthTable.a");
|
||||
auto fourthTable_d = parser.Root().Direct("thirdTable.fourthTable.d");
|
||||
|
||||
ASSERT_NE(table_a, nullptr);
|
||||
EXPECT_EQ(table_a->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
@@ -281,7 +324,7 @@ TEST(NestedContent, Table)
|
||||
TEST(NestedContent, TableArray)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
[[table.test]]
|
||||
a = 2
|
||||
b = 1.2
|
||||
@@ -293,53 +336,59 @@ TEST(NestedContent, TableArray)
|
||||
d = []
|
||||
)"s);
|
||||
|
||||
auto table_test_1_a = parser.GetRoot().GetDirect("table.test[0].a");
|
||||
auto table_test_1_b = parser.GetRoot().GetDirect("table.test[0].b");
|
||||
auto table_test_2_a = parser.GetRoot().GetDirect("table.test[1].a");
|
||||
auto table_test_2_c = parser.GetRoot().GetDirect("table.test[1].c");
|
||||
auto table_test_3_a = parser.GetRoot().GetDirect("table.test[2].a");
|
||||
auto table_test_3_d = parser.GetRoot().GetDirect("table.test[2].d");
|
||||
auto table_test_1_a = parser.Root().Direct("table.test[0].a");
|
||||
auto table_test_1_b = parser.Root().Direct("table.test[0].b");
|
||||
auto table_test_2_a = parser.Root().Direct("table.test[1].a");
|
||||
auto table_test_2_c = parser.Root().Direct("table.test[1].c");
|
||||
auto table_test_3_a = parser.Root().Direct("table.test[2].a");
|
||||
auto table_test_3_d = parser.Root().Direct("table.test[2].d");
|
||||
|
||||
ASSERT_NE(table_test_1_a, nullptr);
|
||||
EXPECT_EQ(table_test_1_a->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(table_test_1_a->GetValue(), 2);
|
||||
EXPECT_EQ(table_test_1_a->GetIndex(), 0u);
|
||||
ASSERT_NE(table_test_1_b, nullptr);
|
||||
EXPECT_EQ(table_test_1_b->GetType(), sdv::toml::ENodeType::node_floating_point);
|
||||
EXPECT_EQ(table_test_1_b->GetValue(), 1.2);
|
||||
EXPECT_EQ(table_test_1_b->GetIndex(), 1u);
|
||||
ASSERT_NE(table_test_2_a, nullptr);
|
||||
EXPECT_EQ(table_test_2_a->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
EXPECT_EQ(table_test_2_a->GetValue(), 4);
|
||||
EXPECT_EQ(table_test_2_a->GetIndex(), 0u);
|
||||
ASSERT_NE(table_test_2_c, nullptr);
|
||||
EXPECT_EQ(table_test_2_c->GetType(), sdv::toml::ENodeType::node_boolean);
|
||||
EXPECT_EQ(table_test_2_c->GetValue(), false);
|
||||
EXPECT_EQ(table_test_2_c->GetIndex(), 1u);
|
||||
ASSERT_NE(table_test_3_a, nullptr);
|
||||
EXPECT_EQ(table_test_3_a->GetType(), sdv::toml::ENodeType::node_string);
|
||||
EXPECT_EQ(static_cast<std::string>(table_test_3_a->GetValue()), "five");
|
||||
EXPECT_EQ(table_test_3_a->GetIndex(), 0u);
|
||||
ASSERT_NE(table_test_3_d, nullptr);
|
||||
EXPECT_EQ(table_test_3_d->GetType(), sdv::toml::ENodeType::node_array);
|
||||
EXPECT_EQ(table_test_3_d->GetIndex(), 1u);
|
||||
}
|
||||
|
||||
TEST(NestedContent, InlineTable)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
table1 = { a = 0, b = 1.2, c = "string" }
|
||||
table2 = { a = [], b = true, e = 2.71828 }
|
||||
table3 = { a = { a = "a", b = "A" }, b = {a = "b", b = "B"}, e = {a = "e", b = "E"} }
|
||||
)"s);
|
||||
|
||||
auto table1_a = parser.GetRoot().GetDirect("table1.a");
|
||||
auto table1_b = parser.GetRoot().GetDirect("table1.b");
|
||||
auto table1_c = parser.GetRoot().GetDirect("table1.c");
|
||||
auto table2_a = parser.GetRoot().GetDirect("table2.a");
|
||||
auto table2_b = parser.GetRoot().GetDirect("table2.b");
|
||||
auto table2_e = parser.GetRoot().GetDirect("table2.e");
|
||||
auto table3_a_a = parser.GetRoot().GetDirect("table3.a.a");
|
||||
auto table3_a_b = parser.GetRoot().GetDirect("table3.a.b");
|
||||
auto table3_b_a = parser.GetRoot().GetDirect("table3.b.a");
|
||||
auto table3_b_b = parser.GetRoot().GetDirect("table3.b.b");
|
||||
auto table3_e_a = parser.GetRoot().GetDirect("table3.e.a");
|
||||
auto table3_e_b = parser.GetRoot().GetDirect("table3.e.b");
|
||||
auto table1_a = parser.Root().Direct("table1.a");
|
||||
auto table1_b = parser.Root().Direct("table1.b");
|
||||
auto table1_c = parser.Root().Direct("table1.c");
|
||||
auto table2_a = parser.Root().Direct("table2.a");
|
||||
auto table2_b = parser.Root().Direct("table2.b");
|
||||
auto table2_e = parser.Root().Direct("table2.e");
|
||||
auto table3_a_a = parser.Root().Direct("table3.a.a");
|
||||
auto table3_a_b = parser.Root().Direct("table3.a.b");
|
||||
auto table3_b_a = parser.Root().Direct("table3.b.a");
|
||||
auto table3_b_b = parser.Root().Direct("table3.b.b");
|
||||
auto table3_e_a = parser.Root().Direct("table3.e.a");
|
||||
auto table3_e_b = parser.Root().Direct("table3.e.b");
|
||||
|
||||
ASSERT_NE(table1_a, nullptr);
|
||||
EXPECT_EQ(table1_a->GetType(), sdv::toml::ENodeType::node_integer);
|
||||
@@ -381,7 +430,7 @@ TEST(NestedContent, InlineTable)
|
||||
TEST(SpecialCases, Keys)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
EXPECT_NO_THROW(CParserTOML(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"(
|
||||
"127.0.0.1" = "value"
|
||||
"character encoding" = "value"
|
||||
"ʎǝʞ" = "value"
|
||||
@@ -389,21 +438,21 @@ TEST(SpecialCases, Keys)
|
||||
'quoted "value"' = "value"
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"(
|
||||
key = "value"
|
||||
bare_key = "value"
|
||||
bare-key = "value"
|
||||
1234 = "value"
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"(
|
||||
"" = "blank" # VALID but discouraged
|
||||
)"s));
|
||||
EXPECT_NO_THROW(CParserTOML(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"(
|
||||
'' = 'blank' # VALID but discouraged
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"(
|
||||
name = "Orange"
|
||||
physical.color = "orange"
|
||||
physical.shape = "round"
|
||||
@@ -411,20 +460,20 @@ TEST(SpecialCases, Keys)
|
||||
)"s));
|
||||
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"(
|
||||
fruit.name = "banana" # this is best practice
|
||||
fruit. color = "yellow" # same as fruit.color
|
||||
fruit . flavor = "banana" # same as fruit.flavor
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"(
|
||||
# This makes the key "fruit" into a table.
|
||||
fruit.apple.smooth = true
|
||||
# So then you can add to the table "fruit" like so:
|
||||
fruit.orange = 2
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"(
|
||||
# VALID BUT DISCOURAGED
|
||||
apple.type = "fruit"
|
||||
orange.type = "fruit"
|
||||
@@ -434,15 +483,15 @@ TEST(SpecialCases, Keys)
|
||||
orange.color = "orange"
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser(R"(
|
||||
3.1415 = 3.1415
|
||||
)"s));
|
||||
{
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
3.1415 = 3.1415
|
||||
)"s);
|
||||
auto table = parser.GetRoot().GetDirect("3");
|
||||
auto pi = parser.GetRoot().GetDirect("3.1415");
|
||||
auto table = parser.Root().Direct("3");
|
||||
auto pi = parser.Root().Direct("3.1415");
|
||||
ASSERT_NE(table, nullptr);
|
||||
EXPECT_EQ(table->GetType(), sdv::toml::ENodeType::node_table);
|
||||
ASSERT_NE(pi, nullptr);
|
||||
@@ -454,7 +503,7 @@ TEST(SpecialCases, Keys)
|
||||
TEST(SpecialCases, Arrays)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
integers = [ 1, 2, 3 ]
|
||||
colors = [ "red", "yellow", "green" ]
|
||||
nested_arrays_of_ints = [ [ 1, 2 ], [3, 4, 5] ]
|
||||
@@ -462,7 +511,7 @@ TEST(SpecialCases, Arrays)
|
||||
string_array = [ "all", 'strings', """are the same""", '''type''' ]
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
numbers = [ 0.1, 0.2, 0.5, 1, 2, 5 ]
|
||||
contributors = [
|
||||
"Foo Bar <foo@example.com>",
|
||||
@@ -470,7 +519,7 @@ TEST(SpecialCases, Arrays)
|
||||
]
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
integers3 = [
|
||||
1,
|
||||
2, # this is ok
|
||||
@@ -481,7 +530,7 @@ TEST(SpecialCases, Arrays)
|
||||
TEST(SpecialCases, Tables)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
[table-1]
|
||||
key1 = "some string"
|
||||
key2 = 123
|
||||
@@ -491,19 +540,19 @@ TEST(SpecialCases, Tables)
|
||||
key2 = 456
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
[dog."tater.man"]
|
||||
type.name = "pug"
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
[a.b.c] # this is best practice
|
||||
[ d.e.f ] # same as [d.e.f]
|
||||
[ g . h . i ] # same as [g.h.i]
|
||||
[ j . "ʞ" . 'l' ] # same as [j."ʞ".'l']
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
# [x] you
|
||||
# [x.y] don't
|
||||
# [x.y.z] need these
|
||||
@@ -511,14 +560,14 @@ TEST(SpecialCases, Tables)
|
||||
[x] # defining a super-table afterward is ok
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
# VALID BUT DISCOURAGED
|
||||
[fruit.apple]
|
||||
[animal]
|
||||
[fruit.orange]
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
[fruit]
|
||||
apple.color = "red"
|
||||
apple.taste.sweet = true
|
||||
@@ -529,7 +578,7 @@ TEST(SpecialCases, Tables)
|
||||
TEST(SpecialCases, TableArrays)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
[[products]]
|
||||
name = "Hammer"
|
||||
sku = 738594937
|
||||
@@ -540,7 +589,7 @@ TEST(SpecialCases, TableArrays)
|
||||
color = "gray"
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
[[fruits]]
|
||||
name = "apple"
|
||||
[fruits.physical] # subtable
|
||||
@@ -556,7 +605,7 @@ TEST(SpecialCases, TableArrays)
|
||||
name = "plantain"
|
||||
)"s));
|
||||
|
||||
EXPECT_NO_THROW(CParserTOML parser(R"(
|
||||
EXPECT_NO_THROW(toml_parser::CParser parser(R"(
|
||||
points = [ { x = 1, y = 2, z = 3 },
|
||||
{ x = 7, y = 8, z = 9 },
|
||||
{ x = 2, y = 4, z = 8 } ]
|
||||
@@ -566,32 +615,32 @@ TEST(SpecialCases, TableArrays)
|
||||
TEST(ErrorCases, KeyValue)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
EXPECT_THROW(CParserTOML parser(R"(key = # node_invalid)"s), sdv::toml::XTOMLParseException);
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(key = # node_invalid)"s), sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(CParserTOML parser(R"(first = "Tom" last = "Preston-Werner" # node_invalid)"s), sdv::toml::XTOMLParseException);
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(first = "Tom" last = "Preston-Werner" # node_invalid)"s), sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(CParserTOML parser(R"(= "no key name" # node_invalid)"s), sdv::toml::XTOMLParseException);
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(= "no key name" # node_invalid)"s), sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
name = "Tom"
|
||||
name = "Pradyun"
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(CParserTOML(R"(
|
||||
EXPECT_THROW(toml_parser::CParser(R"(
|
||||
fruit . flavor = "banana" # same as fruit.flavor
|
||||
fruit.flavor = "banana"
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(CParserTOML(R"(
|
||||
EXPECT_THROW(toml_parser::CParser(R"(
|
||||
spelling = "favorite"
|
||||
"spelling" = "favourite"
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
|
||||
|
||||
EXPECT_THROW(CParserTOML(R"(
|
||||
EXPECT_THROW(toml_parser::CParser(R"(
|
||||
# This defines the value of fruit.apple to be an integer.
|
||||
fruit.apple = 1
|
||||
# But then this treats fruit.apple like it's a table.
|
||||
@@ -604,13 +653,19 @@ TEST(ErrorCases, KeyValue)
|
||||
TEST(ErrorCases, Tables)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
[ j . "ʞ" . 'l' ]
|
||||
[j."ʞ".'l']
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
[ j . "ʞ" . 'l' ]
|
||||
["j".'ʞ'."l"]
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
[fruit]
|
||||
apple = "red"
|
||||
[fruit]
|
||||
@@ -618,7 +673,7 @@ TEST(ErrorCases, Tables)
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
[fruit]
|
||||
apple = "red"
|
||||
[fruit.apple]
|
||||
@@ -626,14 +681,14 @@ TEST(ErrorCases, Tables)
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
[fruit]
|
||||
apple.color = "red"
|
||||
apple.taste.sweet = true
|
||||
[fruit.apple] # INVALID
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
[fruit]
|
||||
apple.color = "red"
|
||||
apple.taste.sweet = true
|
||||
@@ -646,12 +701,12 @@ TEST(ErrorCases, InlineTables)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
type = { name = "Nail" }
|
||||
type.edible = false # INVALID
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
[product]
|
||||
type.name = "Nail"
|
||||
type = { edible = false } # INVALID
|
||||
@@ -662,7 +717,7 @@ TEST(ErrorCases, InlineTables)
|
||||
TEST(ErrorCases, TableArrays)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
[fruit.physical] # subtable, but to which parent element should it belong?
|
||||
color = "red"
|
||||
shape = "round"
|
||||
@@ -672,13 +727,13 @@ TEST(ErrorCases, TableArrays)
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
fruits = []
|
||||
[[fruits]] # Not allowed
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
[[fruits]]
|
||||
name = "apple"
|
||||
[[fruits.varieties]]
|
||||
@@ -688,7 +743,7 @@ TEST(ErrorCases, TableArrays)
|
||||
name = "granny smith"
|
||||
)"s),
|
||||
sdv::toml::XTOMLParseException);
|
||||
EXPECT_THROW(CParserTOML parser(R"(
|
||||
EXPECT_THROW(toml_parser::CParser parser(R"(
|
||||
[[fruits]]
|
||||
name = "apple"
|
||||
[fruits.physical]
|
||||
@@ -704,13 +759,13 @@ TEST(ErrorCases, TableArrays)
|
||||
TEST(Ordering, Array)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
|
||||
)"s);
|
||||
|
||||
auto two = parser.GetRoot().GetDirect("array[2]");
|
||||
auto eleven = parser.GetRoot().GetDirect("array[11]");
|
||||
const auto arr = parser.GetRoot().GetDirect("array");
|
||||
auto two = parser.Root().Direct("array[2]");
|
||||
auto eleven = parser.Root().Direct("array[11]");
|
||||
const auto arr = parser.Root().Direct("array");
|
||||
|
||||
// with direct access
|
||||
ASSERT_NE(two, nullptr);
|
||||
@@ -720,7 +775,7 @@ TEST(Ordering, Array)
|
||||
|
||||
// with indirect access through iterating
|
||||
ASSERT_NE(arr, nullptr);
|
||||
auto ptrArray = arr->GetArray();
|
||||
auto ptrArray = arr->Cast<toml_parser::CArray>();
|
||||
EXPECT_EQ(ptrArray->GetCount(), 12u);
|
||||
for (uint32_t uiIndex = 0; uiIndex < ptrArray->GetCount(); uiIndex++)
|
||||
EXPECT_EQ(ptrArray->Get(uiIndex)->GetValue(), (int64_t)uiIndex);
|
||||
@@ -729,7 +784,7 @@ TEST(Ordering, Array)
|
||||
TEST(Ordering, TableAray)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
[[tableArray]]
|
||||
a = 0
|
||||
[[tableArray]]
|
||||
@@ -756,19 +811,19 @@ TEST(Ordering, TableAray)
|
||||
a = 11
|
||||
)"s);
|
||||
|
||||
auto tableArray = parser.GetRoot().GetDirect("tableArray");
|
||||
auto tableArray = parser.Root().Direct("tableArray");
|
||||
|
||||
ASSERT_NE(tableArray, nullptr);
|
||||
auto ptrArray = tableArray->GetArray();
|
||||
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)->GetTable()->Find("a")->GetValue(), (int64_t) uiIndex);
|
||||
EXPECT_EQ(ptrArray->Get(uiIndex)->Cast<toml_parser::CTable>()->Direct("a")->GetValue(), (int64_t) uiIndex);
|
||||
}
|
||||
|
||||
TEST(Ordering, NodeGetDirect)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
CParserTOML parser(R"(
|
||||
toml_parser::CParser parser(R"(
|
||||
[[table.test]]
|
||||
a = 2
|
||||
b = 1.2
|
||||
@@ -782,18 +837,89 @@ TEST(Ordering, NodeGetDirect)
|
||||
{ x = 2, y = 4, z = 8 }]
|
||||
)"s);
|
||||
|
||||
auto table_test_1_a = parser.GetRoot().GetDirect("table.test[0].a");
|
||||
auto table_test_1_b = parser.GetRoot().GetDirect("table.test[0].b");
|
||||
auto table_test_2_a = parser.GetRoot().GetDirect("table.test[1].a");
|
||||
auto table_test_2_c = parser.GetRoot().GetDirect("table.test[1].c");
|
||||
auto table_test_3_a = parser.GetRoot().GetDirect("table.test[2].a");
|
||||
auto table_test_3_d = parser.GetRoot().GetDirect("table.test[2].d");
|
||||
auto table_test_1_a = parser.Root().Direct("table.test[0].a");
|
||||
auto table_test_1_b = parser.Root().Direct("table.test[0].b");
|
||||
auto table_test_2_a = parser.Root().Direct("table.test[1].a");
|
||||
auto table_test_2_c = parser.Root().Direct("table.test[1].c");
|
||||
auto table_test_3_a = parser.Root().Direct("table.test[2].a");
|
||||
auto table_test_3_d = parser.Root().Direct("table.test[2].d");
|
||||
|
||||
EXPECT_TRUE(table_test_1_a);
|
||||
EXPECT_TRUE(table_test_1_b);
|
||||
EXPECT_EQ(table_test_3_d->GetType(), sdv::toml::ENodeType::node_array);
|
||||
|
||||
auto table_test_3 = parser.GetRoot().GetDirect("table.test[2]");
|
||||
auto table_test_3_2nd = table_test_3->GetTable()->GetNodeDirect("d[2].x");
|
||||
auto table_test_3 = parser.Root().Direct("table.test[2]");
|
||||
auto table_test_3_2nd = table_test_3->Cast<toml_parser::CTable>()->GetNodeDirect("d[2].x");
|
||||
EXPECT_NE(table_test_3_2nd, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(NodeAccess, Parent)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
toml_parser::CParser parser(R"(
|
||||
[[table.test]]
|
||||
a = 2
|
||||
b = 1.2
|
||||
[[table.test]]
|
||||
a = 4
|
||||
c = false
|
||||
[[table.test]]
|
||||
a = "five"
|
||||
d = [ { x = 1, y = 2, z = 3 },
|
||||
{ x = 7, y = 8, z = 9 },
|
||||
{ x = 2, y = 4, z = 8 }]
|
||||
)"s);
|
||||
|
||||
auto fnGetName = [](sdv::IInterfaceAccess* pNode) -> std::string
|
||||
{
|
||||
sdv::toml::INodeInfo* pNodeInfo = sdv::TInterfaceAccessPtr(pNode).GetInterface<sdv::toml::INodeInfo>();
|
||||
if (!pNodeInfo) return {};
|
||||
return pNodeInfo->GetPath(true);
|
||||
};
|
||||
|
||||
auto root = &parser.Root();
|
||||
auto table = parser.Root().Direct("table");
|
||||
ASSERT_TRUE(table);
|
||||
EXPECT_EQ(table->GetParent(), root);
|
||||
EXPECT_EQ(fnGetName(table->GetParent()), "");
|
||||
auto table_test = parser.Root().Direct("table.test");
|
||||
ASSERT_TRUE(table_test);
|
||||
EXPECT_EQ(table_test->GetParent(), table.get());
|
||||
EXPECT_EQ(fnGetName(table_test->GetParent()), "table");
|
||||
auto table_test_1 = parser.Root().Direct("table.test[0]");
|
||||
ASSERT_TRUE(table_test_1);
|
||||
EXPECT_EQ(table_test_1->GetParent(), table_test.get());
|
||||
EXPECT_EQ(fnGetName(table_test_1->GetParent()), "table.test");
|
||||
auto table_test_1_a = parser.Root().Direct("table.test[0].a");
|
||||
ASSERT_TRUE(table_test_1_a);
|
||||
EXPECT_EQ(table_test_1_a->GetParent(), table_test_1.get());
|
||||
EXPECT_EQ(fnGetName(table_test_1_a->GetParent()), "table.test[0]");
|
||||
auto table_test_1_b = parser.Root().Direct("table.test[0].b");
|
||||
ASSERT_TRUE(table_test_1_b);
|
||||
EXPECT_EQ(table_test_1_b->GetParent(), table_test_1.get());
|
||||
EXPECT_EQ(fnGetName(table_test_1_b->GetParent()), "table.test[0]");
|
||||
auto table_test_2 = parser.Root().Direct("table.test[1]");
|
||||
ASSERT_TRUE(table_test_2);
|
||||
EXPECT_EQ(table_test_2->GetParent(), table_test.get());
|
||||
EXPECT_EQ(fnGetName(table_test_2->GetParent()), "table.test");
|
||||
auto table_test_2_a = parser.Root().Direct("table.test[1].a");
|
||||
ASSERT_TRUE(table_test_2_a);
|
||||
EXPECT_EQ(table_test_2_a->GetParent(), table_test_2.get());
|
||||
EXPECT_EQ(fnGetName(table_test_2_a->GetParent()), "table.test[1]");
|
||||
auto table_test_2_c = parser.Root().Direct("table.test[1].c");
|
||||
ASSERT_TRUE(table_test_2_c);
|
||||
EXPECT_EQ(table_test_2_c->GetParent(), table_test_2.get());
|
||||
EXPECT_EQ(fnGetName(table_test_2_c->GetParent()), "table.test[1]");
|
||||
auto table_test_3 = parser.Root().Direct("table.test[2]");
|
||||
ASSERT_TRUE(table_test_3);
|
||||
EXPECT_EQ(table_test_3->GetParent(), table_test.get());
|
||||
EXPECT_EQ(fnGetName(table_test_3->GetParent()), "table.test");
|
||||
auto table_test_3_a = parser.Root().Direct("table.test[2].a");
|
||||
ASSERT_TRUE(table_test_3_a);
|
||||
EXPECT_EQ(table_test_3_a->GetParent(), table_test_3.get());
|
||||
EXPECT_EQ(fnGetName(table_test_3_a->GetParent()), "table.test[2]");
|
||||
auto table_test_3_d = parser.Root().Direct("table.test[2].d");
|
||||
ASSERT_TRUE(table_test_3_d);
|
||||
EXPECT_EQ(table_test_3_d->GetParent(), table_test_3.get());
|
||||
EXPECT_EQ(fnGetName(table_test_3_d->GetParent()), "table.test[2]");
|
||||
}
|
||||
|
||||
1256
tests/unit_tests/toml_parser/statement_boundary_detection.cpp
Normal file
1256
tests/unit_tests/toml_parser/statement_boundary_detection.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user