Skip to content

Commit

Permalink
Try to fix modules ci
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Jul 28, 2024
1 parent 3c887ee commit fc72bb2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 4 additions & 3 deletions include/semver/semver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,10 @@ namespace semver
#ifdef __cpp_lib_format
#if __cpp_lib_format >= 201907L

template <>
struct std::formatter<semver::version> : std::formatter<std::string_view> {
auto format(const semver::version& version, std::format_context& ctx) const {
template <class CharT>
struct std::formatter<semver::version, CharT> : std::formatter<std::string_view> {
template <class FormatContext>
auto format(const semver::version& version, FormatContext& ctx) const {
return std::formatter<std::string_view>::format(version.str(), ctx);
}
};
Expand Down
8 changes: 7 additions & 1 deletion module/semver.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ export namespace semver {
export namespace semver::literals {
using semver::literals::operator""_v;
using semver::literals::operator""_lv;
}
}

#if defined(__cpp_lib_format)
export namespace std {
using std::formatter;
}
#endif
20 changes: 17 additions & 3 deletions test/module/module_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import semver;

#include <catch2/catch_test_macros.hpp>

import semver;

using namespace semver::literals;

TEST_CASE("Module test version components", "[version][module]") {
Expand Down Expand Up @@ -46,4 +46,18 @@ TEST_CASE("Module test version std::ostream <<", "[version][module]") {
std::stringstream ss;
ss << v;
REQUIRE(ss.str() == "5.2.3");
}
}

#ifdef __cpp_lib_format
#if __cpp_lib_format >= 201907L

TEST_CASE("Module test version std::format formatter", "[version][module]") {
REQUIRE(std::format("{}", semver::version::parse("5.2.3")) == "5.2.3");
REQUIRE(std::format("{}", semver::version::parse("5.2.3-alpha")) == "5.2.3-alpha");
REQUIRE(std::format("{}", semver::version::parse("5.2.3-1.2.3")) == "5.2.3-1.2.3");
REQUIRE(std::format("{}", semver::version::parse("5.2.3-alpha+build34")) == "5.2.3-alpha+build34");
REQUIRE(std::format("{}", semver::version::parse("5.2.3-1.2.3+build34")) == "5.2.3-1.2.3+build34");
}

#endif
#endif

0 comments on commit fc72bb2

Please sign in to comment.