diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/common/StringTest.cpp | 5 | ||||
-rw-r--r-- | test/toml/CMakeLists.txt | 6 | ||||
-rw-r--r-- | test/toml/ParserTest.cpp | 31 |
4 files changed, 43 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 455aad90..c5e18d61 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,6 +8,7 @@ target_link_libraries(cru_test_base INTERFACE GTest::gtest GTest::gtest_main) add_subdirectory(common) add_subdirectory(platform) add_subdirectory(xml) +add_subdirectory(toml) if(WIN32) add_subdirectory(win) diff --git a/test/common/StringTest.cpp b/test/common/StringTest.cpp index f11f9197..2dc72478 100644 --- a/test/common/StringTest.cpp +++ b/test/common/StringTest.cpp @@ -28,6 +28,11 @@ TEST(String, Format) { ASSERT_EQ(Format(u"{} + {} = {}", 123, 321, 444), String(u"123 + 321 = 444")); } +TEST(String, Trim) { + using cru::String; + ASSERT_EQ(String(u" abc ").Trim(), u"abc"); +} + TEST(String, SplitToLines) { using cru::String; diff --git a/test/toml/CMakeLists.txt b/test/toml/CMakeLists.txt new file mode 100644 index 00000000..22766ecd --- /dev/null +++ b/test/toml/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(cru_toml_test + ParserTest.cpp +) +target_link_libraries(cru_toml_test PRIVATE cru_toml cru_test_base) + +gtest_discover_tests(cru_toml_test) diff --git a/test/toml/ParserTest.cpp b/test/toml/ParserTest.cpp new file mode 100644 index 00000000..5bbb5fe7 --- /dev/null +++ b/test/toml/ParserTest.cpp @@ -0,0 +1,31 @@ +#include "cru/toml/TomlDocument.hpp" +#include "cru/toml/TomlParser.hpp" + +#include <gtest/gtest.h> + +using namespace cru::toml; + +TEST(CruTomlParserTest, Simple) { + TomlParser parser( + uR"( +a1 = v1 +"a2" = "v2" +# comment + +[s1] +# comment +a3 = v3 +"a4" = "v4" + +[s2] +a5 = v5 +"a6" = "v6" + )"); + auto document = parser.Parse(); + ASSERT_EQ(document.GetSection(u"")->GetValue(u"a1"), u"v1"); + ASSERT_EQ(document.GetSection(u"")->GetValue(u"a2"), u"v2"); + ASSERT_EQ(document.GetSection(u"s1")->GetValue(u"a3"), u"v3"); + ASSERT_EQ(document.GetSection(u"s1")->GetValue(u"a4"), u"v4"); + ASSERT_EQ(document.GetSection(u"s2")->GetValue(u"a5"), u"v5"); + ASSERT_EQ(document.GetSection(u"s2")->GetValue(u"a6"), u"v6"); +} |