Implement docpp::version() function, which returns the library version.
This commit is contained in:
parent
9d30189d31
commit
d13c2d02fe
|
@ -7,6 +7,12 @@ project(docpp VERSION 0.0.1
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
option(GENERATE_PKGBUILD "Generate PKGBUILD" OFF)
|
||||
option(GENERATE_EBUILD "Generate ebuild" OFF)
|
||||
option(BUILD_TARBALL "Build tarball" OFF)
|
||||
|
||||
add_compile_definitions(DOCPP_VERSION="${PROJECT_VERSION}")
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <exception>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
|
||||
/**
|
||||
* @brief A namespace to represent HTML elements and documents
|
||||
|
@ -1684,4 +1685,10 @@ namespace docpp {
|
|||
bool operator!=(const Stylesheet& stylesheet) const;
|
||||
};
|
||||
} // namespace CSS
|
||||
|
||||
/**
|
||||
* @brief Get the version of the library
|
||||
* @return std::tuple<int, int, int> The version of the library
|
||||
*/
|
||||
std::tuple<int, int, int> version();
|
||||
} // namespace docpp
|
||||
|
|
|
@ -1302,3 +1302,25 @@ std::string docpp::CSS::Stylesheet::get(const Formatting formatting, const int t
|
|||
|
||||
return std::move(ret);
|
||||
}
|
||||
|
||||
std::tuple<int, int, int> docpp::version() {
|
||||
#ifdef DOCPP_VERSION
|
||||
std::string version{DOCPP_VERSION};
|
||||
|
||||
if (version.find('.') != std::string::npos) {
|
||||
std::string major = version.substr(0, version.find('.'));
|
||||
version = version.substr(version.find('.') + 1);
|
||||
|
||||
if (version.find('.') != std::string::npos) {
|
||||
std::string minor = version.substr(0, version.find('.'));
|
||||
version = version.substr(version.find('.') + 1);
|
||||
|
||||
if (version.find('.') != std::string::npos) {
|
||||
std::string patch = version.substr(0, version.find('.'));
|
||||
return {std::stoi(major), std::stoi(minor), std::stoi(patch)};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -2015,6 +2015,14 @@ inline namespace General {
|
|||
REQUIRE(docpp::CSS::Element::npos == -1);
|
||||
REQUIRE(docpp::CSS::Stylesheet::npos == -1);
|
||||
}
|
||||
|
||||
void test_version() {
|
||||
std::tuple<int, int, int> version = docpp::version();
|
||||
|
||||
REQUIRE(std::get<0>(version) >= 0);
|
||||
REQUIRE(std::get<1>(version) >= 0);
|
||||
REQUIRE(std::get<2>(version) >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2023,6 +2031,7 @@ inline namespace General {
|
|||
SCENARIO("Test general", "[GENERAL]") {
|
||||
General::test_exceptions();
|
||||
General::test_npos_values();
|
||||
General::test_version();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue