aboutsummaryrefslogtreecommitdiff
path: root/test/toml
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-08 19:24:44 +0800
committercrupest <crupest@outlook.com>2022-01-08 19:24:44 +0800
commit0c7153db084060034092c1dc24222cae384722ec (patch)
tree9de1bc4636732e3cc1e1fb7309fdf2ff60683f69 /test/toml
parentc38f1f7c273e85c0a6d197cb27424c9ca69e234d (diff)
downloadcru-0c7153db084060034092c1dc24222cae384722ec.tar.gz
cru-0c7153db084060034092c1dc24222cae384722ec.tar.bz2
cru-0c7153db084060034092c1dc24222cae384722ec.zip
...
Diffstat (limited to 'test/toml')
-rw-r--r--test/toml/CMakeLists.txt6
-rw-r--r--test/toml/ParserTest.cpp31
2 files changed, 37 insertions, 0 deletions
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");
+}