Skip to content

Commit

Permalink
test: handlebars basic spec
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Jul 14, 2023
1 parent 5fa524d commit 74fd1f3
Show file tree
Hide file tree
Showing 10 changed files with 2,197 additions and 436 deletions.
347 changes: 246 additions & 101 deletions include/mrdox/Support/Handlebars.hpp

Large diffs are not rendered by default.

820 changes: 506 additions & 314 deletions src/lib/Support/Handlebars.cpp

Large diffs are not rendered by default.

568 changes: 564 additions & 4 deletions src/test/lib/Support/Handlebars.cpp

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/test_suite/detail/decomposer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ namespace test_suite::detail
format_value(T const& value)
{
std::string out;
if constexpr (std::is_convertible_v<std::decay_t<T>, std::string_view>)
{
out += '\"';
}
#ifdef MRDOX_TEST_HAS_FMT
if constexpr (fmt::has_formatter<T, fmt::format_context>::value) {
out += fmt::format("{}", value);
Expand All @@ -59,6 +63,10 @@ namespace test_suite::detail
} else {
out += demangle<T>();
}
if constexpr (std::is_convertible_v<std::decay_t<T>, std::string_view>)
{
out += '\"';
}
return out;
}

Expand Down
7 changes: 3 additions & 4 deletions src/test_suite/diff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ BOOST_TEST_DIFF(
else
{
// Compare rendered template with reference
auto success_contents = expected_contents;
DiffStringsResult diff = diffStrings(success_contents, rendered_contents);
DiffStringsResult diff = diffStrings(expected_contents, rendered_contents);
if (diff.added > 0 || diff.removed > 0)
{
std::ofstream out((std::string(error_output_path)));
Expand All @@ -292,8 +291,8 @@ BOOST_TEST_DIFF(
BOOST_TEST(diff.added == 0);
BOOST_TEST(diff.removed == 0);
}
BOOST_TEST(rendered_contents.size() == success_contents.size());
BOOST_TEST(rendered_contents == success_contents);
BOOST_TEST(rendered_contents.size() == expected_contents.size());
BOOST_TEST((rendered_contents == expected_contents));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/test_suite/test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,10 @@ test(
(void)func;
log_ <<
"#" << id << " " <<
file << "(" << line << ") "
"failed: " << expr <<
file << "(" << line << ")\n"
"failed:\n " << expr <<
//" in " << func <<
"\n";
"\n\n";
log_.flush();
return false;
}
Expand Down
33 changes: 25 additions & 8 deletions src/test_suite/test_suite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ constexpr detail::log_type log{};
{ \
DETAIL_START_WARNINGS_SUPPRESSION \
std::string d = DETAIL_STRINGIFY(__VA_ARGS__); \
d += " ("; \
d += "\n ("; \
DETAIL_SUPPRESS_PARENTHESES_WARNINGS \
d += (test_suite::detail::decomposer() <= __VA_ARGS__).format(); \
DETAIL_STOP_WARNINGS_SUPPRESSION \
Expand Down Expand Up @@ -304,27 +304,42 @@ constexpr detail::log_type log{};
#define BOOST_TEST_NOT(expr) BOOST_TEST(!(expr))

#ifndef BOOST_NO_EXCEPTIONS
# define BOOST_TEST_THROW_WITH( expr, ex, msg ) \
try { \
(void)(expr); \
::test_suite::detail::throw_failed_impl( \
#expr, #ex, "@anon", \
__FILE__, __LINE__); \
} \
catch(ex const& e) { \
BOOST_TEST(std::string_view(e.what()) == std::string_view(msg)); \
} \
catch(...) { \
::test_suite::detail::throw_failed_impl( \
#expr, #ex, "@anon", \
__FILE__, __LINE__); \
} \
(void) 0
//

# define BOOST_TEST_THROWS( expr, ex ) \
try { \
(void)(expr); \
::test_suite::detail::throw_failed_impl( \
#expr, #ex, "@anon", \
__FILE__, __LINE__); \
} \
catch(ex const&) { \
catch(ex const&) { \
BOOST_TEST_PASS(); \
} \
catch(...) { \
::test_suite::detail::throw_failed_impl( \
#expr, #ex, "@anon", \
__FILE__, __LINE__); \
}
} \
(void) 0
//
#else
#define BOOST_TEST_THROWS( expr, ex )
#endif

#ifndef BOOST_NO_EXCEPTIONS
# define BOOST_TEST_NO_THROW( expr ) \
try { \
(void)(expr); \
Expand All @@ -340,7 +355,9 @@ constexpr detail::log_type log{};
}
//
#else
# define BOOST_TEST_NO_THROW( expr ) ( [&]{ expr; return true; }() )
#define BOOST_TEST_THROWS( expr, ex )
#define BOOST_TEST_THROW_WITH( expr, ex, msg )
#define BOOST_TEST_NO_THROW( expr ) ( [&]{ expr; return true; }() )
#endif

#define TEST_SUITE(type, name) \
Expand Down
Loading

0 comments on commit 74fd1f3

Please sign in to comment.