style port v1

This commit is contained in:
pvoid committed 2025-11-28 18:16:55 +03:00
1 parent 8b731e941f
commit 1e203a2245
15 files changed
+456 -124

No files matched your search

+92
View File
@@ -0,0 +1,92 @@
#include <iostream>
#include <list>
#include "filesystem.h"
#include "unit_test_framework.hpp"
namespace fs = std::filesystem;
struct TestData
{
struct fs
{
static constexpr char separator = '/';
static constexpr char preferred_separator = '/';
static constexpr char dot = '.';
static constexpr auto emptyPath = "";
static constexpr auto rootPath = "/";
static constexpr auto sysPath = "/sys";
static constexpr auto calcPath = "/sys/Calc";
static constexpr auto calcFileName = "Calc";
static constexpr auto invalidPath = "~-=%r7";
};
};
TEST(DefaultPathConstants)
{
ASSERT_EQUAL(TestData::fs::separator, fs::path::separator);
ASSERT_EQUAL(TestData::fs::preferred_separator, fs::path::preferred_separator);
ASSERT_EQUAL(TestData::fs::dot, fs::path::dot);
}
TEST(PathIsDirectory)
{
ASSERT_TRUE(fs::is_directory(fs::current_path()));
ASSERT_TRUE(fs::is_directory(TestData::fs::sysPath));
ASSERT_TRUE(fs::is_directory(TestData::fs::rootPath));
ASSERT_FALSE(fs::is_directory(TestData::fs::calcPath));
ASSERT_FALSE(fs::is_directory(TestData::fs::invalidPath));
ASSERT_FALSE(fs::is_directory(TestData::fs::emptyPath));
}
TEST(PathIsRegularFile)
{
ASSERT_FALSE(fs::is_regular_file(fs::current_path()));
ASSERT_FALSE(fs::is_regular_file(TestData::fs::rootPath));
ASSERT_FALSE(fs::is_regular_file(TestData::fs::emptyPath));
ASSERT_FALSE(fs::is_regular_file(TestData::fs::invalidPath));
ASSERT_TRUE(fs::is_regular_file(TestData::fs::calcPath));
}
TEST(PathIsAbsolute)
{
ASSERT_TRUE(fs::is_absolute(fs::current_path()));
ASSERT_TRUE(fs::is_absolute(TestData::fs::rootPath));
ASSERT_TRUE(fs::is_absolute(TestData::fs::sysPath));
ASSERT_TRUE(fs::is_absolute(TestData::fs::calcPath));
ASSERT_FALSE(fs::is_absolute(TestData::fs::emptyPath));
ASSERT_FALSE(fs::is_absolute(TestData::fs::invalidPath));
}
TEST(PathConcat)
{
fs::path p;
ASSERT_TRUE(p.empty());
ASSERT_EQUAL((p /= TestData::fs::rootPath).string(), "/");
ASSERT_EQUAL((p / TestData::fs::calcFileName).string(), "/Calc");
ASSERT_EQUAL((p / TestData::fs::sysPath).string(), "/sys");
ASSERT_EQUAL(((p /= TestData::fs::sysPath) / TestData::fs::calcFileName).string(), "/sys/Calc");
}
TEST(PathFileName)
{
ASSERT_EQUAL(fs::path(TestData::fs::emptyPath).filename().string(), TestData::fs::emptyPath);
ASSERT_EQUAL(fs::path(TestData::fs::invalidPath).filename().string(), TestData::fs::invalidPath);
ASSERT_EQUAL(fs::path(TestData::fs::calcPath).filename().string(), TestData::fs::calcFileName);
ASSERT_EQUAL(fs::path(TestData::fs::rootPath).filename().string(), TestData::fs::emptyPath);
ASSERT_EQUAL(fs::path(TestData::fs::sysPath).filename().string(), "sys");
}
// just for cli output
TEST(ScanDirectory)
{
std::list<fs::path> l;
fs::scan_directory(fs::current_path().c_str(), l);
std::cout << "entries: " << l.size() << std::endl;
for(const auto& p : l)
{
std::cout << p << std::endl;
}
}
TEST_MAIN()