kaycxx-test
C++ unit test framework
Loading...
Searching...
No Matches
assert_contain.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Klaus Reimer <k@ailis.de>
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
11#include <format>
12#include <optional>
13#include <source_location>
14#include <string_view>
15#include <utility>
16
18#include <kaycxx/test/detail/contains.hpp>
19#include <kaycxx/test/detail/to_string.hpp>
20
21namespace kaycxx::test {
22
39template <typename Actual, typename Expected>
40requires detail::contains_supported<Actual, Expected>
42 Actual const& actual,
43 Expected const& expected,
44 std::string_view reason = {},
45 std::optional<std::source_location> location = std::source_location::current()
46) {
47 if (!detail::contains(actual, expected)) {
48 auto actual_string = detail::to_string(actual);
49 auto expected_string = detail::to_string(expected);
50 auto message = std::format("Expected <{}> to contain <{}>", actual_string, expected_string);
51 throw assertion_error(
52 message,
53 reason,
54 std::move(actual_string),
55 std::move(expected_string),
56 location
57 );
58 }
59}
60
61} // namespace kaycxx::test
Defines the assertion_error type.
Unit test framework functions and types.
Definition test.hpp:15
void assert_contain(Actual const &actual, Expected const &expected, std::string_view reason={}, std::optional< std::source_location > location=std::source_location::current())
Asserts that a string contains a substring or character, or that a range contains an element.
Definition assert_contain.hpp:41