test: add testbench for macro/versiom_cmp

This commit is contained in:
2025-08-04 21:15:49 +08:00
parent ce2b411b0b
commit 54134b342e
5 changed files with 33 additions and 36 deletions

View File

@ -16,7 +16,7 @@ This project require at least CMake 3.23 to build. We suggest that you only use
See documentation for how to build this project.
> [!INFO]
> [!NOTE]
> When building with testbench, you may face link error with GoogleTest. This issue is caused by that the binary provided by your package manager is built in C++ 17 and its ABI is incompatible with C++ 23. The solution is that download GoogleTest source code and build it in C++ 23 on your own. See this [GitHub Issue](https://github.com/google/googletest/issues/4591) for more infomation.
> Oppositely, you don't need care about this issue if you just want to build YYCC self.

View File

@ -1,9 +0,0 @@
#include "StdPatch.hpp"
#include "EncodingHelper.hpp"
#include <string>
#include <stdexcept>
namespace YYCC::StdPatch {
}

View File

@ -1,26 +0,0 @@
#pragma once
#include "YYCCInternal.hpp"
#include <filesystem>
#include <string>
#include <string_view>
namespace YYCC::StdPatch {
/**
* @brief Constructs \c std::filesystem::path from UTF8 path.
* @param[in] u8_path UTF8 path string for building.
* @return \c std::filesystem::path instance.
* @exception std::invalid_argument Fail to parse given UTF8 string (maybe invalid?).
*/
std::filesystem::path ToStdPath(const yycc_u8string_view& u8_path);
/**
* @brief Returns the UTF8 representation of given \c std::filesystem::path.
* @param[in] path The \c std::filesystem::path instance converting to UTF8 path.
* @return The UTF8 representation of given \c std::filesystem::path.
* @exception std::invalid_argument Fail to convert to UTF8 string.
*/
yycc_u8string ToUTF8Path(const std::filesystem::path& path);
}

View File

@ -4,6 +4,7 @@ add_executable(YYCCTestbench "")
target_sources(YYCCTestbench
PRIVATE
main.cpp
yycc/macro/version_cmp.cpp
yycc/constraint.cpp
yycc/constraint/builder.cpp
yycc/string/op.cpp

View File

@ -0,0 +1,31 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/macro/version_cmp.hpp>
namespace yycctest::macro::version_cmp {
TEST(MacroVersionCmp, Same) {
// Test for same version.
EXPECT_TRUE(YYCC_VERCMP_E(1, 2, 3, 1, 2, 3));
EXPECT_FALSE(YYCC_VERCMP_NE(1, 2, 3, 1, 2, 3));
EXPECT_FALSE(YYCC_VERCMP_G(1, 2, 3, 1, 2, 3));
EXPECT_TRUE(YYCC_VERCMP_GE(1, 2, 3, 1, 2, 3));
EXPECT_TRUE(YYCC_VERCMP_NL(1, 2, 3, 1, 2, 3));
EXPECT_FALSE(YYCC_VERCMP_L(1, 2, 3, 1, 2, 3));
EXPECT_TRUE(YYCC_VERCMP_LE(1, 2, 3, 1, 2, 3));
EXPECT_TRUE(YYCC_VERCMP_NG(1, 2, 3, 1, 2, 3));
}
TEST(MacroVersionCmp, Math) {
// In version number, 1.2.10 is greater than 1.2.9
EXPECT_FALSE(YYCC_VERCMP_E(1, 2, 10, 1, 2, 9));
EXPECT_TRUE(YYCC_VERCMP_NE(1, 2, 10, 1, 2, 9));
EXPECT_TRUE(YYCC_VERCMP_G(1, 2, 10, 1, 2, 9));
EXPECT_TRUE(YYCC_VERCMP_GE(1, 2, 10, 1, 2, 9));
EXPECT_TRUE(YYCC_VERCMP_NL(1, 2, 10, 1, 2, 9));
EXPECT_FALSE(YYCC_VERCMP_L(1, 2, 10, 1, 2, 9));
EXPECT_FALSE(YYCC_VERCMP_LE(1, 2, 10, 1, 2, 9));
EXPECT_FALSE(YYCC_VERCMP_NG(1, 2, 10, 1, 2, 9));
}
}