Files
clio/tests/unit/util/log/PrettyPathTests.cpp
2026-03-24 15:25:32 +00:00

47 lines
1.1 KiB
C++

#include "util/MockAssert.hpp"
#include "util/SourceLocation.hpp"
#include "util/log/PrettyPath.hpp"
#include <gtest/gtest.h>
#include <string_view>
using namespace util;
TEST(PrettyPath, CurrentFile)
{
auto loc = CURRENT_SRC_LOCATION;
auto pretty = prettyPath(loc.file_name());
EXPECT_EQ(pretty, "util/log/PrettyPathTests.cpp");
}
struct PrettyPathDepth : public common::util::WithMockAssert {
static constexpr std::string_view kTEST_PATH = "my/awesome/path/to/file.cpp";
};
TEST_F(PrettyPathDepth, Zero)
{
EXPECT_CLIO_ASSERT_FAIL_WITH_MESSAGE(
{ [[maybe_unused]] auto unused = prettyPath(kTEST_PATH, 0); },
"maxDepth must be greater than 0"
);
}
TEST_F(PrettyPathDepth, Small)
{
auto pretty = prettyPath(kTEST_PATH, 1);
EXPECT_EQ(pretty, "file.cpp");
}
TEST_F(PrettyPathDepth, Big)
{
auto pretty = prettyPath(kTEST_PATH, 4);
EXPECT_EQ(pretty, "awesome/path/to/file.cpp");
}
TEST_F(PrettyPathDepth, MoreThanParts)
{
auto pretty = prettyPath(kTEST_PATH, 10);
EXPECT_EQ(pretty, "my/awesome/path/to/file.cpp");
}