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
121 lines
3.8 KiB
C++
121 lines
3.8 KiB
C++
#include "tests.h"
|
|
|
|
TEST_CASE("parsing strings")
|
|
{
|
|
parsing_should_succeed(S(R"(
|
|
str = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."
|
|
|
|
str1 = """
|
|
Roses are red
|
|
Violets are blue"""
|
|
)"sv),
|
|
[](table&& tbl) noexcept
|
|
{
|
|
CHECK(tbl[S("str")] == S("I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."sv));
|
|
CHECK(tbl[S("str1")] == S("Roses are red\nViolets are blue"sv));
|
|
}
|
|
);
|
|
|
|
parsing_should_succeed(S(R"(
|
|
# The following strings are byte-for-byte equivalent:
|
|
str1 = "The quick brown fox jumps over the lazy dog."
|
|
|
|
str2 = """
|
|
The quick brown \
|
|
|
|
|
|
fox jumps over \
|
|
the lazy dog."""
|
|
|
|
str3 = """\
|
|
The quick brown \
|
|
fox jumps over \
|
|
the lazy dog.\
|
|
"""
|
|
|
|
str4 = """Here are two quotation marks: "". Simple enough."""
|
|
# str5 = """Here are three quotation marks: """.""" # INVALID
|
|
str5 = """Here are three quotation marks: ""\"."""
|
|
str6 = """Here are fifteen quotation marks: ""\"""\"""\"""\"""\"."""
|
|
|
|
# "This," she said, "is just a pointless statement."
|
|
str7 = """"This," she said, "is just a pointless statement.""""
|
|
)"sv),
|
|
[](table&& tbl) noexcept
|
|
{
|
|
static constexpr auto quick_brown_fox = S("The quick brown fox jumps over the lazy dog."sv);
|
|
CHECK(tbl[S("str1")] == quick_brown_fox);
|
|
CHECK(tbl[S("str2")] == quick_brown_fox);
|
|
CHECK(tbl[S("str3")] == quick_brown_fox);
|
|
CHECK(tbl[S("str4")] == S(R"(Here are two quotation marks: "". Simple enough.)"sv));
|
|
CHECK(tbl[S("str5")] == S(R"(Here are three quotation marks: """.)"sv));
|
|
CHECK(tbl[S("str6")] == S(R"(Here are fifteen quotation marks: """"""""""""""".)"sv));
|
|
CHECK(tbl[S("str7")] == S(R"("This," she said, "is just a pointless statement.")"sv));
|
|
}
|
|
);
|
|
|
|
parsing_should_fail(S(R"(str5 = """Here are three quotation marks: """.""")"sv));
|
|
|
|
parsing_should_succeed(S(R"(
|
|
# What you see is what you get.
|
|
winpath = 'C:\Users\nodejs\templates'
|
|
winpath2 = '\\ServerX\admin$\system32\'
|
|
quoted = 'Tom "Dubs" Preston-Werner'
|
|
regex = '<\i\c*\s*>'
|
|
regex2 = '''I [dw]on't need \d{2} apples'''
|
|
lines = '''
|
|
The first newline is
|
|
trimmed in raw strings.
|
|
All other whitespace
|
|
is preserved.
|
|
'''
|
|
)"sv),
|
|
[](table&& tbl) noexcept
|
|
{
|
|
CHECK(tbl[S("winpath")] == S(R"(C:\Users\nodejs\templates)"sv));
|
|
CHECK(tbl[S("winpath2")] == S(R"(\\ServerX\admin$\system32\)"sv));
|
|
CHECK(tbl[S("quoted")] == S(R"(Tom "Dubs" Preston-Werner)"sv));
|
|
CHECK(tbl[S("regex")] == S(R"(<\i\c*\s*>)"sv));
|
|
CHECK(tbl[S("regex2")] == S(R"(I [dw]on't need \d{2} apples)"sv));
|
|
CHECK(tbl[S("lines")] == S(R"(The first newline is
|
|
trimmed in raw strings.
|
|
All other whitespace
|
|
is preserved.
|
|
)"sv));
|
|
}
|
|
);
|
|
|
|
parsing_should_succeed(S(R"(
|
|
quot15 = '''Here are fifteen quotation marks: """""""""""""""'''
|
|
|
|
# apos15 = '''Here are fifteen apostrophes: '''''''''''''''''' # INVALID
|
|
apos15 = "Here are fifteen apostrophes: '''''''''''''''"
|
|
|
|
# 'That's still pointless', she said.
|
|
str = ''''That's still pointless', she said.'''
|
|
)"sv),
|
|
[](table&& tbl) noexcept
|
|
{
|
|
CHECK(tbl[S("quot15")] == S(R"(Here are fifteen quotation marks: """"""""""""""")"sv));
|
|
CHECK(tbl[S("apos15")] == S(R"(Here are fifteen apostrophes: ''''''''''''''')"sv));
|
|
CHECK(tbl[S("str")] == S(R"('That's still pointless', she said.)"sv));
|
|
}
|
|
);
|
|
|
|
parsing_should_fail(S(R"(apos15 = '''Here are fifteen apostrophes: '''''''''''''''''' # INVALID)"sv));
|
|
|
|
//value tests
|
|
parse_expected_value(
|
|
R"("The quick brown fox jumps over the lazy dog")"sv,
|
|
S("The quick brown fox jumps over the lazy dog"sv));
|
|
parse_expected_value(
|
|
R"('The quick brown fox jumps over the lazy dog')"sv,
|
|
S("The quick brown fox jumps over the lazy dog"sv));
|
|
parse_expected_value(
|
|
R"("""The quick brown fox jumps over the lazy dog""")"sv,
|
|
S("The quick brown fox jumps over the lazy dog"sv));
|
|
parse_expected_value(
|
|
R"('''The quick brown fox jumps over the lazy dog''')"sv,
|
|
S("The quick brown fox jumps over the lazy dog"sv));
|
|
}
|