mirror of
https://github.com/marzer/tomlplusplus.git
synced 2024-09-15 15:13:21 +00:00
930bf0ad58
new file: .editorconfig new file: .gitattributes new file: .gitignore new file: .gitmodules new file: LICENSE new file: README.md new file: examples/example.cpp new file: examples/example.toml new file: examples/meson.build new file: include/toml++/toml.h new file: include/toml++/toml_array.h new file: include/toml++/toml_common.h new file: include/toml++/toml_formatter.h new file: include/toml++/toml_node.h new file: include/toml++/toml_node_view.h new file: include/toml++/toml_parser.h new file: include/toml++/toml_table.h new file: include/toml++/toml_utf8.h new file: include/toml++/toml_utf8_generated.h new file: include/toml++/toml_value.h new file: meson.build new file: python/ci_single_header_check.py new file: python/generate_single_header.py new file: python/generate_unicode_functions.py new file: tests/catch2 new file: tests/catch2.h new file: tests/lifetimes.cpp new file: tests/main.cpp new file: tests/meson.build new file: tests/parsing_arrays.cpp new file: tests/parsing_booleans.cpp new file: tests/parsing_comments.cpp new file: tests/parsing_dates_and_times.cpp new file: tests/parsing_floats.cpp new file: tests/parsing_integers.cpp new file: tests/parsing_key_value_pairs.cpp new file: tests/parsing_spec_example.cpp new file: tests/parsing_strings.cpp new file: tests/parsing_tables.cpp new file: tests/tests.cpp new file: tests/tests.h new file: toml.hpp new file: vs/.runsettings new file: vs/example.vcxproj new file: vs/test_char.vcxproj new file: vs/test_char8.vcxproj new file: vs/test_char8_noexcept.vcxproj new file: vs/test_char_noexcept.vcxproj new file: vs/test_strict_char.vcxproj new file: vs/test_strict_char8.vcxproj new file: vs/test_strict_char8_noexcept.vcxproj new file: vs/test_strict_char_noexcept.vcxproj new file: vs/toml++.natvis new file: vs/toml++.props new file: vs/toml++.sln new file: vs/toml++.vcxproj new file: vs/toml++.vcxproj.filters
133 lines
2.8 KiB
C++
133 lines
2.8 KiB
C++
#include "tests.h"
|
|
|
|
TEST_CASE("parsing key-value pairs")
|
|
{
|
|
parsing_should_succeed(S(R"(
|
|
key = "value"
|
|
bare_key = "value"
|
|
bare-key = "value"
|
|
1234 = "value"
|
|
)"sv),
|
|
[](table&& tbl) noexcept
|
|
{
|
|
CHECK(tbl.size() == 4);
|
|
CHECK(tbl[S("key")] == S("value"sv));
|
|
CHECK(tbl[S("bare_key")] == S("value"sv));
|
|
CHECK(tbl[S("bare-key")] == S("value"sv));
|
|
CHECK(tbl[S("1234")] == S("value"sv));
|
|
}
|
|
);
|
|
|
|
parsing_should_fail(S(R"(key = # INVALID)"sv));
|
|
|
|
parsing_should_succeed(S(R"(
|
|
"127.0.0.1" = "value"
|
|
"character encoding" = "value"
|
|
"ʎǝʞ" = "value"
|
|
'key2' = "value"
|
|
'quoted "value"' = "value"
|
|
)"sv),
|
|
[](table&& tbl) noexcept
|
|
{
|
|
CHECK(tbl[S("127.0.0.1")] == S("value"sv));
|
|
CHECK(tbl[S("character encoding")] == S("value"sv));
|
|
CHECK(tbl[S("ʎǝʞ")] == S("value"sv));
|
|
CHECK(tbl[S("key2")] == S("value"sv));
|
|
CHECK(tbl[S("quoted \"value\"")] == S("value"sv));
|
|
}
|
|
);
|
|
|
|
parsing_should_fail(S(R"(= "no key name")"sv));
|
|
|
|
parsing_should_fail(S(R"(
|
|
# DO NOT DO THIS
|
|
name = "Tom"
|
|
name = "Pradyun"
|
|
)"sv)
|
|
);
|
|
|
|
}
|
|
|
|
TEST_CASE("parsing key-value pairs - dotted")
|
|
{
|
|
parsing_should_succeed(S(R"(
|
|
name = "Orange"
|
|
physical.color = "orange"
|
|
physical.shape = "round"
|
|
site."google.com" = true
|
|
)"sv),
|
|
[](table&& tbl) noexcept
|
|
{
|
|
CHECK(tbl.size() == 3);
|
|
CHECK(tbl[S("name")] == S("Orange"sv));
|
|
CHECK(tbl[S("physical")][S("color")] == S("orange"sv));
|
|
CHECK(tbl[S("physical")][S("shape")] == S("round"sv));
|
|
CHECK(tbl[S("site")][S("google.com")] == true);
|
|
}
|
|
);
|
|
|
|
|
|
parsing_should_succeed(S(R"(
|
|
fruit.apple.smooth = true
|
|
fruit.orange = 2
|
|
)"sv),
|
|
[](table&& tbl) noexcept
|
|
{
|
|
CHECK(tbl[S("fruit")][S("apple")][S("smooth")] == true);
|
|
CHECK(tbl[S("fruit")][S("orange")] == 2);
|
|
}
|
|
);
|
|
|
|
parsing_should_fail(S(R"(
|
|
# THIS IS INVALID
|
|
fruit.apple = 1
|
|
fruit.apple.smooth = true
|
|
)"sv)
|
|
);
|
|
|
|
parsing_should_succeed(S(R"(
|
|
# VALID BUT DISCOURAGED
|
|
|
|
apple.type = "fruit"
|
|
orange.type = "fruit"
|
|
|
|
apple.skin = "thin"
|
|
orange.skin = "thick"
|
|
|
|
apple.color = "red"
|
|
orange.color = "orange"
|
|
)"sv),
|
|
[](table&& tbl) noexcept
|
|
{
|
|
CHECK(tbl[S("apple")][S("type")] == S("fruit"sv));
|
|
CHECK(tbl[S("apple")][S("skin")] == S("thin"sv));
|
|
CHECK(tbl[S("apple")][S("color")] == S("red"sv));
|
|
CHECK(tbl[S("orange")][S("type")] == S("fruit"sv));
|
|
CHECK(tbl[S("orange")][S("skin")] == S("thick"sv));
|
|
CHECK(tbl[S("orange")][S("color")] == S("orange"sv));
|
|
}
|
|
);
|
|
|
|
parsing_should_succeed(S(R"(
|
|
# RECOMMENDED
|
|
|
|
apple.type = "fruit"
|
|
apple.skin = "thin"
|
|
apple.color = "red"
|
|
|
|
orange.type = "fruit"
|
|
orange.skin = "thick"
|
|
orange.color = "orange"
|
|
)"sv),
|
|
[](table&& tbl) noexcept
|
|
{
|
|
CHECK(tbl[S("apple")][S("type")] == S("fruit"sv));
|
|
CHECK(tbl[S("apple")][S("skin")] == S("thin"sv));
|
|
CHECK(tbl[S("apple")][S("color")] == S("red"sv));
|
|
CHECK(tbl[S("orange")][S("type")] == S("fruit"sv));
|
|
CHECK(tbl[S("orange")][S("skin")] == S("thick"sv));
|
|
CHECK(tbl[S("orange")][S("color")] == S("orange"sv));
|
|
}
|
|
);
|
|
}
|